Skip to content

Direct Torrent Injection

moleculekayak edited this page Oct 25, 2024 · 7 revisions

Direct Torrent Injection (experimental)

Important

This is considered experimental and only recommended for Docker users. By using this and providing feedback, you're helping me improve this tool for everyone BUT you're taking all the usual risks inherent to experimental features.

Warning

This is advanced functionality. Experience with tools like cross-seed is recommended. If you're new to this tool or cross-seeding in general, make sure you're comfortable with the basic functionality of this program first.

Important

This guide assumes you've set up your torrent clients according to the TRaSH guides. Injection is possible with other setups if you're knowledgeable in Docker but no guides or support will be offered

Direct torrent injection is available for Deluge and qBittorrent. No other clients are planned but feel free to create a PR if you want to add another client!

Before you start

  • Make sure you've read, understood, and applied the concepts around the /data directory found in the installation guide
  • Make sure you've read and understood the concepts in the config file guide

Setup

  • In your config file, set appropriate values for inject_torrents and injection_link_directory
  • In your config file, set authentication details for your torrent client (deluge_rpc_url OR qbittorrent_url OR transmission_rpc_url)

That's it! Your connection to your torrent client will be validated before every fertilizer command (except --help, of course)

Concepts

The distinction between your "output directory" (the -o flag in the CLI) and the injection_link_directory configuration setting can be confusing. Here's the upshot:

  • The "output directory" is where the generated .torrent files are stored. Example: /data/fertilizer/torrent-files
  • The injection_link_directory is where the actually files that have been downloaded should be "copied" to. Example: /data/fertilizer/linked-data
    • NOTE: we need to make a copy of the files because otherwise deleting the original torrent would also delete the underlying files, breaking the cross-seeded torrent (and vice-versa)
    • IMPORTANT: the files are actually hardlinked which means the "copy" doesn't actually take up any additional space so long as the original and cross-seeded files are on the same mount and partition. Splitting these files across drives, partitions, or Docker volume mounts will NOT result in a hardlink (which is part of why I make such a fuss about the matching /data directories thing)
  • One of these directories should not be stored within the other. They can go wherever you want under /data and they can be siblings, just don't put one at /data/fertilizer/torrent-files and the other at /data/fertilizer/torrent-files/data, for instance

Real-world example

Since you've read the blurb on the /data directory, I won't reiterate that here other than to say that this only works if there's a /data directory mapped to your torrent client and it's the exact same directory you've mounted to /data for fertilizer.

For my setup I have an instance of Deluge provided by the binhex-delugevpn container. It maps the /shares/bittorrent directory on my host to the /data directory within the container. If I were to run ls /shares/bittorrent on the host you'd see it holds directories related to torrenting like complete and incomplete. If this sounds like your setup then you shouldn't need to do anything from the perspective of your torrent client's Docker container!

In fertilizer, here's my config.json:

{
  "red_key": "xxxxxxxxxx",
  "ops_key": "xxxxxxxxxx",
  "deluge_rpc_url": "http://:pass@host:8112/json",
  "inject_torrents": true,
  "injection_link_directory": "/data/fertilizer/linked-data"
}

and for every command I'd set my output directory (-o) to /data/fertilizer/torrent-files. On my host, this would correspond to the /shares/bittorrent/fertilizer/linked-data and /shares/bittorrent/fertilizer/torrent-files directories.

I apologize if this is thuddingly repetitive ;)

From there, I'd run a test scan of a single file to ensure everything works. You should have a new torrent in your client that's successfully seeding @ 100% completion. Injection is now implicitly enabled for all fertilizer commands.

Putting it all together

Assuming the test run worked as expected, this is when I'd switch to server mode. If you have everything set up correctly, here's how the flow works out:

  1. The fertilizer server is started with fertilizer -i /torrents -o /data/<your output dir> -c /config/config.json --server
  2. The torrent client completes a download
  3. This invokes the script I've set up which informs the fertilizer server to check this newly completed torrent
  4. Iff this newly completed torrent is cross-seedable, a new .torrent file is generated and placed in your output directory. Simultaneously, the original torrent's data files are copied (hardlinked) to your injection_link_directory
  5. Your torrent client is informed of this new torrent and the location of the copied files. It automatically checks the files and begins seeding!