Skip to content

Instantly share code, notes, and snippets.

@pettazz
Last active April 5, 2019 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pettazz/65ef6ce2a8c8a00ec3d95a923329c4f2 to your computer and use it in GitHub Desktop.
Save pettazz/65ef6ce2a8c8a00ec3d95a923329c4f2 to your computer and use it in GitHub Desktop.
Delete and remove files for any seeding torrents that have been idle for some number of days
import datetime
import transmissionrpc
from config import TRANSMISSION
daemon = transmissionrpc.Client(
address=TRANSMISSION.server,
port=TRANSMISSION.port,
user=TRANSMISSION.user,
password=TRANSMISSION.password)
for torrent in daemon.get_torrents():
if torrent.status == 'seeding':
idle_time = datetime.datetime.now() - torrent.date_active
if idle_time > datetime.timedelta(days=2):
print 'Removing %s after %s inactivity' % (torrent.name, idle_time)
daemon.remove_torrent(torrent.hashString, delete_data=True)
@pettazz
Copy link
Author

pettazz commented Apr 5, 2019

Example setup:

  1. Ensure that rpc-enabled is set to true in your transmission-daemon config and that RPC is up and running (if you have something like Sonarr using it, you're all set already)
  2. Put this file in its own directory somewhere safe like /home/tvrobot/transmission-cleanup/run.py
  3. Install the transmission library into the system python: sudo easy_install transmissionrpc
  4. Add your transmission details in a file named config.py in the same directory:
class SETTINGS:
    days_to_wait = 10

class TRANSMISSION:
    server = '127.0.0.1'
    port = '9091'
    user = 'hellorobot'
    password = ''
  • days_to_wait: once a torrent has been active for this long, delete it
  • server: use this for default or whatever value you've set in transmission-daemon config's rpc-bind-address
  • port: transmission-daemon config's rpc-port
  • user: transmission-daemon config's rpc-username (leave blank if rpc-authentication-required is false)
  • password: transmission-daemon config's rpc-password if set, otherwise leave blank
  1. Check where your python is installed with which python
  2. Edit your crontab to add a schedule with sudo crontab -l
  3. Ensure that the PATH includes your python location (add it if missing), looking something like PATH=/usr/sbin:/usr/bin:/sbin:/bin
  4. Add an entry to run the cleanup, for example this runs it every night at 1am:
  0 1    *   *   *   python /home/tvrobot/transmission-cleanup/run.py

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