Skip to content

Instantly share code, notes, and snippets.

@onedr0p
Last active April 19, 2023 18:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onedr0p/8170117d43873c18c34139b7c5904c14 to your computer and use it in GitHub Desktop.
Save onedr0p/8170117d43873c18c34139b7c5904c14 to your computer and use it in GitHub Desktop.
rtorrent - remove specific torrents (set on a cron)
# Python 2.7
import re
import xmlrpclib
import httplib, urllib
# rTorrent URL
server_url = 'http://localhost:6000'
rtorrent = xmlrpclib.Server(server_url)
# Get all the torrents in rtorrent
torrents = rtorrent.download_list('', 'main')
for torrent in torrents:
# Delete Unregistered torrents in the sonarr category
torrent_tracker_status = rtorrent.d.get_message(torrent)
torrent_label = rtorrent.d.get_custom1(torrent)
# Remove torrents where they are deleted from trackers
text = re.search("Unregistered", torrent_tracker_status)
# Only remove ones that are in the sonarr or couchpotato label
if text and (torrent_label == 'sonarr' or torrent_label == 'couchpotato'):
torrent_hash = rtorrent.d.get_hash(torrent)
torrent_name = rtorrent.d.get_name(torrent)
rtorrent.d.delete_tied(torrent_hash)
rtorrent.d.erase(torrent_hash)
@onedr0p
Copy link
Author

onedr0p commented Nov 22, 2019

It's been a long time since I made this, and I don't use rtorrent anymore. Maybe something change with rtorrents RPC? I am not sure but it did work 3 years ago.

My suggestion would be to search the internet and see if you can come up with anything.

@nojkepop
Copy link

nojkepop commented Apr 19, 2023

I know this is pretty old but I ran into a similar problem as @Feriman22. If you run print(rtorrent.system.listMethods()) it will list all the commands accepted by the server. The rtorrent server I have has different commands than the one is the code example.

Some of the differences I found were:

torrent_label = rtorrent.d.custom1(torrent)
torrent_hash = rtorrent.d.hash(torrent)
torrent_name = rtorrent.d.name(torrent)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment