From 4645963fb49eaa012d94cc877392bd7dc58f59ec Mon Sep 17 00:00:00 2001 From: "S. X. Liang" <60531983+Scottpedia@users.noreply.github.com> Date: Fri, 11 Dec 2020 02:53:19 -0500 Subject: [PATCH 01/13] Update transmission-trackers.py - update the keyword parameter. The 'host' did not work for me. I changed to name to 'address' according to (`transmissionrpc`'s document)[https://pythonhosted.org/transmissionrpc/reference/transmissionrpc.html#client-object] --- transmission-trackers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index 19690f8..1531c00 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -4,7 +4,7 @@ # Host, port, username and password to connect to Transmission # Set user and pw to None if auth is not required client = { - 'host': 'localhost', + 'address': 'localhost', 'port': 9091, 'user': 'admin', 'password': 'passwd' From 3eef6fff599a1738b9ce90d476e3d42428a47021 Mon Sep 17 00:00:00 2001 From: Mubashshir Date: Mon, 26 Apr 2021 13:58:33 +0600 Subject: [PATCH 02/13] Be compatible with both the old and new module The old transmissionrpc and new transmission-rpc has a few conflicts in argument name here and there, it tries to handle these conflicts. --- transmission-trackers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index 1531c00..453c3dc 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -4,7 +4,7 @@ # Host, port, username and password to connect to Transmission # Set user and pw to None if auth is not required client = { - 'address': 'localhost', + 'host': 'localhost', 'port': 9091, 'user': 'admin', 'password': 'passwd' @@ -80,6 +80,9 @@ import sys, os, time, socket try: from transmissionrpc import Client + if 'host' in client: + client['address'] = client['host'] + del client['host'] except ImportError: try: from transmission_rpc import Client From 0a9d0ec5d8980cd5785e55f40c2b309cf033ee28 Mon Sep 17 00:00:00 2001 From: Mubashshir Date: Sun, 29 Aug 2021 15:49:45 +0600 Subject: [PATCH 03/13] Skip private torrents --- transmission-trackers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/transmission-trackers.py b/transmission-trackers.py index 453c3dc..fff85b8 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -235,6 +235,9 @@ 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: + dbg('{}: skipping private torrent'.format(t.name)) + continue ttrk = set(()) for trk in t.trackers: From 9dbebdcfb33677d678abd0eb5341b7bc5e6126ad Mon Sep 17 00:00:00 2001 From: Mavaddat Javid Date: Sat, 6 Nov 2021 21:24:41 -0700 Subject: [PATCH 04/13] Robust env recall w multiple failsafes Line 56 tries `$env:HOME`, `$env:USERPROFILE`, `$env:HOMEPATH` before failing to `None` object. --- transmission-trackers.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index fff85b8..a2932d1 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -53,7 +53,7 @@ try: import toml configfile = path.join( \ - env.get('XDG_CONFIG_HOME', path.join(env['HOME'],'.config')), + env.get('XDG_CONFIG_HOME', path.join(env.get('HOME',env.get('USERPROFILE',env.get('HOMEPATH',None))),'.config')), 'transmission/trackers.toml' ) if path.exists(configfile): @@ -64,10 +64,9 @@ mkdir(path.dirname(configfile)) with open(configfile, 'w') as f: toml.dump( {'client': client, 'config': config }, f ) - except: - pass + except KeyError: # Where to cache downloaded lists - cache_file = path.join(env['HOME'] ,'.cache/trackers.txt') + cache_file = path.join(env['TEMP'] ,'.cache/trackers.txt') else: cache_file = '/tmp/trackers_cache.txt' From e64b560cc3e75534dcc7b8effb72880921ef8227 Mon Sep 17 00:00:00 2001 From: Mavaddat Javid Date: Sat, 6 Nov 2021 21:29:31 -0700 Subject: [PATCH 05/13] Fix scope for `cache_file` --- transmission-trackers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index a2932d1..43365a1 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -46,7 +46,7 @@ # Debug output 'debug': False } - +cache_file=None # Universal scope to be set later from os import getcwd if getcwd() != '/docker/transmission/transmission-trackers': from os import environ as env, path, mkdir From 94546ebdb83d4d81cc0d306bf9b35c593a315421 Mon Sep 17 00:00:00 2001 From: Mavaddat Javid Date: Sat, 6 Nov 2021 21:35:23 -0700 Subject: [PATCH 06/13] Update transmission-trackers.py --- transmission-trackers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index 43365a1..1af9fa8 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -46,7 +46,7 @@ # Debug output 'debug': False } -cache_file=None # Universal scope to be set later +cache_file = path.join(env.get('TEMP',env.get('TMP',None)) ,'.cache/trackers.txt') # Universal scope from os import getcwd if getcwd() != '/docker/transmission/transmission-trackers': from os import environ as env, path, mkdir From 939adaaec7bda298724f2a02b9e7f4fc42f4e0e8 Mon Sep 17 00:00:00 2001 From: Mavaddat Javid Date: Sat, 6 Nov 2021 21:36:48 -0700 Subject: [PATCH 07/13] Create transmission-trackers.py --- transmission-trackers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index 1af9fa8..bec0d2f 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -46,11 +46,12 @@ # Debug output 'debug': False } -cache_file = path.join(env.get('TEMP',env.get('TMP',None)) ,'.cache/trackers.txt') # Universal scope +cache_file = None # Universal scope from os import getcwd 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') import toml configfile = path.join( \ env.get('XDG_CONFIG_HOME', path.join(env.get('HOME',env.get('USERPROFILE',env.get('HOMEPATH',None))),'.config')), From cddfbd4501b76430a8f6f98564a6aeb13e7c1ee7 Mon Sep 17 00:00:00 2001 From: Mavaddat Javid Date: Sat, 6 Nov 2021 21:39:36 -0700 Subject: [PATCH 08/13] make directory for `.cache` --- transmission-trackers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/transmission-trackers.py b/transmission-trackers.py index bec0d2f..820b57e 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -52,6 +52,8 @@ from os import environ as env, path, mkdir try: cache_file = path.join(env.get('TEMP',env.get('TMP',None)) ,'.cache/trackers.txt') + if not path.isdir(path.dirname(cache_file)): + mkdir(path.dirname(cache_file)) import toml configfile = path.join( \ env.get('XDG_CONFIG_HOME', path.join(env.get('HOME',env.get('USERPROFILE',env.get('HOMEPATH',None))),'.config')), From dd8a036600ef33d594faa590f4b04954454cea47 Mon Sep 17 00:00:00 2001 From: trotskylenin Date: Tue, 29 Mar 2022 18:55:44 -0300 Subject: [PATCH 09/13] 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 10/13] 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 11/13] 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 12/13] 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 13/13] 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: