java.lang.Object
org.klomp.snark.MagnetHandler
Standalone launcher that forwards magnet links, torrent URLs, info hashes, or torrent file paths to the I2PSnark browser API (POST /_add).
Registered by BrowserApiInstaller as the OS browser handler for magnet: links and .torrent files, replacing the previous shell-script approach (no curl, no CSRF nonce scraping, no HTML parsing).
Usage: java -cp i2psnark.jar org.klomp.snark.MagnetHandler --url
http://127.0.0.1:7657/i2psnark 'magnet:?xt=urn:btih:...'
Each URI is sent as a POST with form-encoded parameter newURL. The server replies with a single status line; exit code is 0 only if all were OK.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intHow long to wait for the connection - 10 seconds.private static final StringWhere to hand a magnet link's parameters on.private static final intHow long to wait for the reply - 60 seconds.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescription(package private) static URIbuildApiUri(String base, String path) Build the absolute API URI for a POST from a console base URL.static voidCommand line entry point: POST each magnet link, torrent URL, info hash or torrent file path given on the command line to the running i2psnark console's browser API, and exit non-zero if any was rejected or the arguments were unusable.private static booleanPOST one URI to the browser API and print the server's status line.
Field Details
DEFAULT_BASE_URL
Where to hand a magnet link's parameters on.- See Also:
CONNECT_TIMEOUT_MS
private static final int CONNECT_TIMEOUT_MSHow long to wait for the connection - 10 seconds.- See Also:
READ_TIMEOUT_MS
private static final int READ_TIMEOUT_MSHow long to wait for the reply - 60 seconds.- See Also:
Constructor Details
MagnetHandler
private MagnetHandler()Utility class, not intended for instantiation.
Method Details
main
Command line entry point: POST each magnet link, torrent URL, info hash or torrent file path given on the command line to the running i2psnark console's browser API, and exit non-zero if any was rejected or the arguments were unusable.- Parameters:
args- an optional --url followed by the console base URL, then one or more magnets, URLs, info hashes or torrent file paths
send
buildApiUri
Build the absolute API URI for a POST from a console base URL.A trailing slash on the base is stripped before appending the path so the result never contains a double slash, regardless of how the operator supplied the base URL.
- Parameters:
base- console base URL, with or without a trailing slashpath- the API path to append, e.g. "/_add"- Returns:
- the absolute API URI
- Throws:
IllegalArgumentException- if the resulting URI is not a valid absolute URI