From dd8a036600ef33d594faa590f4b04954454cea47 Mon Sep 17 00:00:00 2001 From: trotskylenin Date: Tue, 29 Mar 2022 18:55:44 -0300 Subject: [PATCH 1/5] Fixed NoneType Error None was replaced by '' in line 54 to comply with os.environ.get method --- transmission-trackers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index 820b57e..bcdaaf8 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -51,7 +51,7 @@ if getcwd() != '/docker/transmission/transmission-trackers': from os import environ as env, path, mkdir try: - cache_file = path.join(env.get('TEMP',env.get('TMP',None)) ,'.cache/trackers.txt') + cache_file = path.join(env.get('TEMP',env.get('TMP','')) ,'.cache/trackers.txt') if not path.isdir(path.dirname(cache_file)): mkdir(path.dirname(cache_file)) import toml From a3222aa148c25bb7902eb182e167b09d5a2c74ef Mon Sep 17 00:00:00 2001 From: Mubashshir Date: Sat, 10 Jun 2023 21:17:03 +0600 Subject: [PATCH 2/5] Fix backward compatibility between trpc and t-rpc See-also: e7ddfb7006e4ce (add support for transmission-rpc (newer fork)) Signed-off-by: Mubashshir --- transmission-trackers.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index bcdaaf8..6c569b4 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -1,5 +1,10 @@ #!/usr/bin/env python3 from __future__ import print_function +import socket +import time +import os +import sys +from os import getcwd # Host, port, username and password to connect to Transmission # Set user and pw to None if auth is not required @@ -46,8 +51,8 @@ # Debug output 'debug': False } + cache_file = None # Universal scope -from os import getcwd if getcwd() != '/docker/transmission/transmission-trackers': from os import environ as env, path, mkdir try: @@ -69,17 +74,15 @@ toml.dump( {'client': client, 'config': config }, f ) except KeyError: # Where to cache downloaded lists - cache_file = path.join(env['TEMP'] ,'.cache/trackers.txt') + cache_file = path.join(env['TEMP'] ,'.cache/trackers.txt') else: cache_file = '/tmp/trackers_cache.txt' - ### Configuration ends here ### hdrs = {'User-Agent': 'Mozilla/5.0'} hosts, ips = set(()), set(()) -import sys, os, time, socket try: from transmissionrpc import Client if 'host' in client: @@ -237,13 +240,13 @@ def readLocalLists(): if config['status_filter'] and not t.status in config['status_filter']: dbg('{}: skipping due to status filter'.format(t.name)) continue - if t.isPrivate: + if getattr(t, 'isPrivate', getattr(t, 'is_private', False)): dbg('{}: skipping private torrent'.format(t.name)) continue ttrk = set(()) for trk in t.trackers: - ttrk.add(trk['announce']) + ttrk.add(getattr(trk, 'fields', trk).get('announce')) diff = trackers - ttrk From 4873f4e18e183a0c707a3db3bee84452c6b717f3 Mon Sep 17 00:00:00 2001 From: Mehul Boricha Date: Fri, 12 Apr 2024 16:23:04 +0530 Subject: [PATCH 3/5] Automatically Reannounce Torrent Where The Trackers Have Been Updated --- transmission-trackers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/transmission-trackers.py b/transmission-trackers.py index 6c569b4..01a9d30 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -253,5 +253,7 @@ def readLocalLists(): if diff: lg('{}: Adding {} trackers (before: {})'.format(t.name, len(diff), len(ttrk))) tc.change_torrent(t.id, trackerAdd=list(diff)) + time.sleep(1) + tc.reannounce_torrent(t.id) else: dbg('{}: update not needed'.format(t.name)) From fb41bf0c1b78f25e7daf508f561bb23796dfb123 Mon Sep 17 00:00:00 2001 From: Mehul Boricha Date: Fri, 12 Apr 2024 16:30:31 +0530 Subject: [PATCH 4/5] Added Cronjob support while checking if transmission is running or not --- README.md | 5 +++++ transmission-trackers-auto-cron.sh | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 transmission-trackers-auto-cron.sh diff --git a/README.md b/README.md index 183ea8f..0b91ed4 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,8 @@ Usage: * Adjust other parameters if needed (see comments) * Make the script run by cron e.g. every minute * You're done + +Cron Setup: +* Open Crontab using crontab -e +* For Updating Trackers to Every New Torrent Every 15 Minutes Add: */15 * * * * /usr/bin/sh [path]]/transmission-trackers-auto-cron.sh +* Modify the transmission-trackers-auto.sh file as per your needs. We have provided two options, transmission-daemon & docker \ No newline at end of file diff --git a/transmission-trackers-auto-cron.sh b/transmission-trackers-auto-cron.sh new file mode 100644 index 0000000..7aca918 --- /dev/null +++ b/transmission-trackers-auto-cron.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# If you are using transmission-daemon directly on system the below code will ensure that trackers script run only when it is running +if [ "$(systemctl is-active transmission-daemon)" = "active" ] +then +/usr/bin/python3 [path]]/transmission-trackers.py +fi + +# If you are using docker for transmission use the following. Replace 'docker-container-name' with the appropriate name +if [ "$( docker container inspect -f '{{.State.Running}}' 'docker-container-name' )" = "true" ] +then +/usr/bin/python3 [path]]/transmission-trackers.py +fi \ No newline at end of file From 65cc825ed32bf810be5960d66f481710d7a2ad72 Mon Sep 17 00:00:00 2001 From: "Leonidas P. Papadakos" Date: Thu, 6 Mar 2025 19:54:29 +0200 Subject: [PATCH 5/5] Add tracker filter That way we can exclude e.g. private tracker torrents --- transmission-trackers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/transmission-trackers.py b/transmission-trackers.py index 01a9d30..3a5e8c6 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -21,6 +21,11 @@ # If empty - will affect all torrents 'status_filter': (), + # Ignore torrents that contain any of these trackers. + # This is useful, e.g., for excluding torrents from private trackers. + # trackers are matched by substring, so you can cover https://my.site/announce with just my.site + 'tracker_filter': [], + # A list of URLs where to get the tracker lists from. # The lists are combined into one with duplicates removed. # The trackers from these lists are checked by looking up the URL's hostname in DNS. @@ -248,6 +253,10 @@ def readLocalLists(): for trk in t.trackers: ttrk.add(getattr(trk, 'fields', trk).get('announce')) + if any(tracker in url for url in ttrk for tracker in config['tracker_filter']): + dbg('{}: skipping due to tracker filter'.format(t.name)) + continue + diff = trackers - ttrk if diff: