Torrent management: Process finished torrents
Here's where we have the most fun. rtorrent has done all the work for us to grab our torrents, moving completed files into [download/torrents/finished]. Now we'll write some script magic to organize our downloads, without interrupting rtorrent seeding.
Let's review our directory layout:
download/torrents/ actively downloading torrents and files finished/ files that have finished downloading archived/ actively seeding torrents of archived files symlinks/ symlinks to files that have been archived offline/ offline torrents - move back to archived to auto-restart
We already have the first two directories working. Here's the next goal: move finished files to the proper location, according to the content. IMHO, if you are a reasonably sane person, you don't want all your media jammed into one directory. You want to keep your media organized, preferrably in a central location on the network. So let's get organized! We'll use some regex magic - don't worry, it's not too hard. In true hacker fashion, we'll use a mixed bag of scripts that I stole whenever possible, and wrote only when necessary. I'll try to give credit where due! :>
Steps:
- Scan the finished directory for the top-level file or directory of newly-completed downloads
- For each one we find, scan the torrents directory for a matching .torrent file
- Examine each file-dir/.torrent pair to determine where it should be archived
- Move the .torrent file to the archived/backup directory (this temporarily stops seeding)
- Move the files to the correct archive location on the network (this may take some time...)
- Create a symlink to the files under archived/symlinks
- Move the .torrent in backup into the archived dir, while giving it a completed hash
- rtorrent will immediately seed the .torrent file using the newly archived files
Scripts: Torrent management: main script (perl) Torrent management: archive script (bash) Torrent management: torrent parser script (php) Torrent management: rtorrent seed hash script (python)
Installation:
- Put all scripts in a script directory accessible by cron
- Run the main script in cron every half hour or so
- To put archived torrents offline, move the .torrent file from archived to offline; move it back to seed again