rtorrent is a very popular torrent app and it’s often used with its web UI, rutorrent.
However, rtorrent/rutorrent is getting a rather long in the tooth. As one PulsedMedia staff member told me, “rTorrent is sadly pretty much abandonware for the last ~8 years. Momentum only keeps it going.”
One unfortunate problem with rutorrent is that if your seedbox is busy (and sometimes even if it isn’t), you can issue commands to remove torrents in rutorrent and rtorrent (the actual engine that manages torrents) will fail to remove them. This is especially true with large torrents where cleanup involves hundreds or thousands of files. Those are virtually guaranteed to fail.
In such cases, you’ll get a build up of files over time, to the point where you can have gigabytes or terabytes of dead space.
There are some tools that can help with this. One is autotorrent2, which can list unseeded files for you to cleanup. However, it requires accessing rtorrent over a socket port, which PulsedMedia doesn’t support, as they use socket files.
I’ve hacked up a quick script to list unseeded torrents which, while not perfect, gets the job done. Instead of talking to the rtorrent API, it instead examines the rtorrent session directory.
Hey! Let’s take a quick break to talk about PulsedMedia! This post is not sponsored by them nor did they review it or even ask me to run a promo. I’m just a happy customer who’s been using their service for several years. While you can torrent on lots of VPSes/dedi servers, I prefer a dedicated seedbox provider who’s used to the I/O and network loads. PM has done a great job for me. You can get started for as cheap as 3.99€/month. And they do often run special offers on LowEndTalk.
OK, back to your seedbox.
In the session directory, you’ll find a .torrent file for each actively seeded file. rtorrent does a much better job of cleaning this up, as it’s just a single system call to remove it and doesn’t involve traversing a directory tree. After adding and removing hundreds of torrents, mine was perfectly in sync with rutorrent. We can look in this directory to get a list of what’s seeded, and then look at what’s in the data directory, and compare.
I said it’s not perfect because it’s comparing the paths for each source, and it’s possible to have two torrents with the same path.
We’re going to leverage torrent-parser to do the actual reading of the .torrent files.
To setup, create a virtual environment:
python3 -m venv torrent-parser cd ~/torrent-parser ./pip install torrent_parser
And here’s the script. Obviously, adjust the top shebang (#!) line and directory locations for your account. With minimal modifications, this should work on any rtorrent setup at any provider:
#!/home/raindog308/torrent-parser/bin/python import os, re import torrent_parser as tp torrent_dir = "/home/raindog308/session" data_dir = "/home/raindog308/data" data_entries = {} for data_entry in os.listdir(data_dir): data_entries[data_entry] = True for torrent_file in os.listdir(torrent_dir): if re.search('\.torrent$',torrent_file): full_file = "{}/{}".format(torrent_dir,torrent_file) data = tp.parse_torrent_file(full_file) name = data['info']['name'] try: del data_entries[name] except: print ("possible dupe torent path: {}".format(name)) for data_entry in sorted(data_entries.keys()): print (data_entry)
A true pythonista could probably rewrite that in a much shorter syntax, but it works!
Related Posts:
- LowEndBoxTV: AMD Shootout: Ryzen vs. Epyc – Which is Right For You? - November 24, 2024
- Early Black Friday Offer: VersaWeb has a Dedi Deal in Las Vegas, Dallas, and Miami! - November 23, 2024
- LowEndBoxTV: Are All Hetzner Locations Alike?No!And Piotr Has the Proof: “This is Clearly Not the Same Processor” - November 22, 2024
Leave a Reply