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)
@Feriman22
Copy link

Feriman22 commented Nov 22, 2019

Hi,

I tried to run it, but I'm getting this below error:

Traceback (most recent call last):
  File "unregistered_cleanup.py", line 12, in <module>
    torrents = rtorrent.download_list('', 'main')
  File "/usr/lib/python2.7/xmlrpclib.py", line 1243, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1602, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1283, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1313, in single_request
    response = h.getresponse(buffering=True)
  File "/usr/lib/python2.7/httplib.py", line 1137, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 448, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 412, in _read_status
    raise BadStatusLine("No status line received - the server has closed the connection")
httplib.BadStatusLine: No status line received - the server has closed the connection

@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