java.lang.Object
org.klomp.snark.MagnetHandler

public final class MagnetHandlerextends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    How long to wait for the connection - 10 seconds.
    private static final String
    Where to hand a magnet link's parameters on.
    private static final int
    How long to wait for the reply - 60 seconds.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Utility class, not intended for instantiation.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static URI
    buildApiUri(String base, String path)
    Build the absolute API URI for a POST from a console base URL.
    static void
    main(String[] args)
    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.
    private static boolean
    send(String base, String uri)
    POST one URI to the browser API and print the server's status line.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_BASE_URL

      private static final String DEFAULT_BASE_URL
      Where to hand a magnet link's parameters on.
      See Also:
    • CONNECT_TIMEOUT_MS

      private static final int CONNECT_TIMEOUT_MS
      How long to wait for the connection - 10 seconds.
      See Also:
    • READ_TIMEOUT_MS

      private static final int READ_TIMEOUT_MS
      How long to wait for the reply - 60 seconds.
      See Also:
  • Constructor Details

    • MagnetHandler

      private MagnetHandler()
      Utility class, not intended for instantiation.
  • Method Details

    • main

      public static void main(String[] args)
      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

      private static boolean send(String base, String uri)
      POST one URI to the browser API and print the server's status line.
      Parameters:
      base - console base URL, no trailing slash
      uri - the magnet link, torrent URL, info hash, or torrent file path
      Returns:
      true if the server accepted it
    • buildApiUri

      static URI buildApiUri(String base, String path)
      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 slash
      path - 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