I wrote this to enhance the functionality of Sonarr/Radarr's torrent black hole feature to convert .magnet files (links) into a torrent file that rtorrent could natively import through my specified watch folder while preserving my custom labels, download directories, etc. If you found this script then you must already know my pain.
This loops through all the .magnet files in the directory saved in $FILES and passes them through to aria2c which takes the infohash or magnet url and turns it into a .torrent file that rtorrent can then import through its watch folder.
All credit for aria2c goes to the original developers: https://aria2.github.io/
- install aria2
sudo apt install aria2
- Aria2c daemon should be running i.e.
aria2c --daemon --enable-rpc=true --enable-dht --dht-listen-port=6881
- make sure incomming port 6881 (TCP and UDP) is open (forwarded) on your router/firewall
- Replace $DIR with the watch directory path you have .magnet files being saved into by sonarr/radarr/sickgear/etc.
- make sure this script is executable
chmod +x magnet2torrent.sh
- add this script to cron
*/1 * * * * ~/magnet2torrent/magnet2torrent.sh
I designed and tested this script on a WhatBox slot and it works flawlessly. Place the magnet2torrent file in your home directory and modify the paths in the file to match your directory structure.
Aria2c will need to be compiled from source. I had no issues with dependencies on WhatBox when compiling. For info on compiling software on Whatbox see: https://whatbox.ca/wiki/Installing_Software
This creates my watch folder:
schedule = watch_directory_2,5,5,"load_start=~/movie-watch/*.torrent,d.set_custom1=couchpotato"
This is used to move torrents based on labels:
method.insert = d.get_finished_dir,simple,"cat=~/files/,$d.get_custom1=" method.set_key = event.download.finished,move_complete,"d.set_directory=$d.get_finished_dir=;execute=mkdir,-p,$d.get_finished_dir=;execute=mv,-u,$d.get_base_path=,$d.get_finished_dir="
To automate this conversion process I setup a cronjob to run every 5 minutes:
*/5 * * * * ~/magnet2torrent
In my limited testing this has worked flawlessly and that if configured correctly there is little danger (I don't want to claim there is no potential dangers) of this script causing data loss or deleting a .magnet file before it has downloaded all of the metadata for that magnet and saved the corresponding .torrent file.
Please use some common sense if you are going to file a bug report.
-What OS are you running and is this a dedicated server or a seedbox? -Is the script unmodified from how I have provided it? -Does the offending magnet link work if you put it directly into your torrent client? -Post the command you are using to invoke the script. -Please add &>~/magnet2torrent.log to the end of your command so that I can get any and all information that is getting output on either stdin or stderr. Post the log file with your issue.