From 479c521d0f7aab31a74fedba13117f6e39a93196 Mon Sep 17 00:00:00 2001 From: Mubashshir Date: Wed, 20 May 2020 08:27:55 +0600 Subject: [PATCH 01/24] Update transmission-trackers.py IPv6 Trackers support. --- transmission-trackers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index 8ba948c..25464b0 100644 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -70,7 +70,7 @@ def parse(txt): def validateTrackerURL(url, dns=True): try: - h = urlparse(url).netloc.split(':', 1)[0] + h = ':'.join(urlparse(url).netloc.split(':')[0:-1]) except: lg("Tracker URL '{}' is malformed".format(url)) return False From 6a3ccaf04488941c2282ca6e6fe1ab9864882c69 Mon Sep 17 00:00:00 2001 From: zcq100 Date: Mon, 14 Sep 2020 20:06:19 +0800 Subject: [PATCH 02/24] add ipv6 tracker --- tracker_ipv6.txt | 1 + transmission-trackers.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 tracker_ipv6.txt diff --git a/tracker_ipv6.txt b/tracker_ipv6.txt new file mode 100644 index 0000000..9c90f39 --- /dev/null +++ b/tracker_ipv6.txt @@ -0,0 +1 @@ +http://tracker.ipv6tracker.ru/announce diff --git a/transmission-trackers.py b/transmission-trackers.py index 25464b0..05fbd31 100644 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -2,7 +2,7 @@ # Host, port, username and password to connect to Transmission # Set user and pw to None if auth is not required -host, port, user, pw = 'localhost', 9091, 'admin', 'pwd' +host, port, user, pw = 'localhost', 9091, 'admin', 'passwd' # Work with torrents having only these statuses. # Can be any combination of: 'check pending', 'checking', 'downloading', 'seeding', 'stopped' From 02d3d6467e1a951e346e9b893b143138341da2b1 Mon Sep 17 00:00:00 2001 From: zcq100 Date: Mon, 14 Sep 2020 20:07:26 +0800 Subject: [PATCH 03/24] add ipv6 tracker --- transmission-trackers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index 05fbd31..c296911 100644 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -17,7 +17,7 @@ # The trackers from these lists are checked by looking up the URL's hostname in DNS. urls = [ 'https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt', - # 'http://some.other.tracker.list/trackers.txt' + 'https://raw.githubusercontent.com/zcq100/transmission-trackers/master/tracker_ipv6.txt', # ... ] From 6e8424f9ce7eada85cefd2e9060baa06409aee6c Mon Sep 17 00:00:00 2001 From: zcq100 Date: Mon, 14 Sep 2020 20:42:11 +0800 Subject: [PATCH 04/24] add systemd-file --- transmission-trackers.service | 14 ++++++++++++++ transmission-trackers.timer | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 transmission-trackers.service create mode 100644 transmission-trackers.timer diff --git a/transmission-trackers.service b/transmission-trackers.service new file mode 100644 index 0000000..b077b2a --- /dev/null +++ b/transmission-trackers.service @@ -0,0 +1,14 @@ +[Unit] +Description=add tracker to torent +After=network.target network-online.target +Wants=network-online.target + +[Service] +User=zcq100 +Type=oneshot +WorkingDirectory=/docker/transmission/transmission-trackers +ExecStart=python3 transmission-trackers.py + + +[Install] +WantedBy=multi-user.target diff --git a/transmission-trackers.timer b/transmission-trackers.timer new file mode 100644 index 0000000..7c0a4b7 --- /dev/null +++ b/transmission-trackers.timer @@ -0,0 +1,10 @@ +[Unit] +Description=add trackers to torrent every 10 minutes + +[Timer] +OnBootSec=0s +OnUnitActiveSec=10min +Unit=transmission-trackers.service + +[Install] +WantedBy=multi-user.target From 3914c52505f4945bdf230fb7e7c9cf7f4b400d78 Mon Sep 17 00:00:00 2001 From: zcq100 Date: Mon, 14 Sep 2020 20:47:18 +0800 Subject: [PATCH 05/24] add requirements.txt --- requirements.txt | 1 + transmission-trackers.service | 1 + 2 files changed, 2 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..402b734 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +transmissionrpc>=0.11 diff --git a/transmission-trackers.service b/transmission-trackers.service index b077b2a..3daae6e 100644 --- a/transmission-trackers.service +++ b/transmission-trackers.service @@ -6,6 +6,7 @@ Wants=network-online.target [Service] User=zcq100 Type=oneshot +#Your WorkingDirectory WorkingDirectory=/docker/transmission/transmission-trackers ExecStart=python3 transmission-trackers.py From e7ddfb7006e4ce5b78a1bfb87867ac8dda84aae0 Mon Sep 17 00:00:00 2001 From: Mubashshir Date: Mon, 28 Sep 2020 14:59:56 +0600 Subject: [PATCH 06/24] add support for transmission-rpc (newer fork) --- transmission-trackers.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index c296911..14eb5f5 100644 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -45,7 +45,15 @@ hdrs = {'User-Agent': 'Mozilla/5.0'} hosts, ips = set(()), set(()) -import transmissionrpc, sys, os, time, socket +import sys, os, time, socket +try: + from transmissionrpc import Client +except ImportError: + try + from transmission_rpc import Client + except ImportError: + print("neither transmissionrpc nor transmission-rpc is installed") + exit() if sys.version_info[0] == 2: from urllib import Request, urlopen @@ -173,7 +181,10 @@ def readLocalLists(): exit(1) try: - tc = transmissionrpc.Client(host, port=port, user=user, password=pw) + if Client.__module__ == 'transmission_rpc.client': + tc = Client(host=host, port=port, username=user, password=pw) + else: + tc = Client(host, port=port, user=user, password=pw) except: if not err_on_connect: exit() From 097dd9a8967a526cc0c7bbce67e9313082a3facd Mon Sep 17 00:00:00 2001 From: Mubashshir Date: Mon, 28 Sep 2020 17:08:31 +0600 Subject: [PATCH 07/24] add support for toml config file --- requirements.txt | 4 +- transmission-trackers.py | 133 ++++++++++++++++++++++++--------------- 2 files changed, 85 insertions(+), 52 deletions(-) diff --git a/requirements.txt b/requirements.txt index 402b734..5689f64 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ -transmissionrpc>=0.11 +transmission-rpc>=3.2; python_version >= '3' +transmissionrpc>=0.11; python_version < '3' +toml diff --git a/transmission-trackers.py b/transmission-trackers.py index 14eb5f5..b0d7312 100644 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -2,44 +2,75 @@ # Host, port, username and password to connect to Transmission # Set user and pw to None if auth is not required -host, port, user, pw = 'localhost', 9091, 'admin', 'passwd' - -# Work with torrents having only these statuses. -# Can be any combination of: 'check pending', 'checking', 'downloading', 'seeding', 'stopped' -# If empty - will affect all torrents -status_filter = () - -# How frequently to update trackers cache -update_freq = 86400 - -# 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. -urls = [ - 'https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt', - 'https://raw.githubusercontent.com/zcq100/transmission-trackers/master/tracker_ipv6.txt', - # ... -] - -# Whether to print an error if connection failed (no Transmission running?) -err_on_connect = False - -# Where to cache downloaded lists -cache_file = '/tmp/trackers_cache.txt' - -# Additional local lists of trackers to load. -# Better to use absolute paths. -# These are not checked against DNS -local_lists = [ - # '/var/cache/trackers1.txt' - # '/var/cache/trackers2.txt' - # ... -] - -# Don't print anything (unless an error occures) -silent = False -# Debug output -debug = False +client = { + 'host': 'localhost', + 'port': 9091, + 'user': 'admin', + 'password': 'passwd' +} +config = { + + # Work with torrents having only these statuses. + # Can be any combination of: 'check pending', 'checking', 'downloading', 'seeding', 'stopped' + # If empty - will affect all torrents + 'status_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. + 'remote_lists': [ + 'https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt', + 'https://raw.githubusercontent.com/zcq100/transmission-trackers/master/tracker_ipv6.txt', + # ... + ], + + # How frequently to update trackers cache + 'update_freq': 86400, + + # Additional local lists of trackers to load. + # Better to use absolute paths. + # These are not checked against DNS + 'local_lists': [ + # '/var/cache/trackers1.txt' + # '/var/cache/trackers2.txt' + # ... + ], + + # Whether to print an error if connection failed (no Transmission running?) + 'err_on_connect': False, + + # Don't print anything (unless an error occures) + 'silent': False, + + # Debug output + 'debug': False +} + +from os import getcwd +if getcwd() != '/docker/transmission/transmission-trackers': + from os import environ as env, path, mkdir + try: + import toml + configfile = path.join( \ + env.get('XDG_CONFIG_HOME', path.join(env['HOME'],'.config')), + 'transmission/trackers.toml' + ) + if path.exists(configfile): + with open(configfile, 'r') as f: + client, config = toml.load(f).values() + else: + if not path.isdir(path.dirname(configfile)): + mkdir(path.dirname(configfile)) + with open(configfile, 'w') as f: + toml.dump( {'client': client, 'config': config }, f ) + except: + pass + # Where to cache downloaded lists + cache_file = path.join(env['HOME'] ,'.cache/trackers.txt') +else: + cache_file = '/tmp/trackers_cache.txt' + + ### Configuration ends here ### hdrs = {'User-Agent': 'Mozilla/5.0'} @@ -49,8 +80,11 @@ try: from transmissionrpc import Client except ImportError: - try + try: from transmission_rpc import Client + if 'user' in client: + client['username'] = client['user'] + del client['user'] except ImportError: print("neither transmissionrpc nor transmission-rpc is installed") exit() @@ -63,10 +97,10 @@ from urllib.parse import urlparse def lg(msg): - if not silent: print(msg) + if not config['silent']: print(msg) def dbg(msg): - if debug: lg(msg) + if config['debug']: lg(msg) def parse(txt): l = [] @@ -125,7 +159,7 @@ def downloadLists(): try: mt = os.stat(cache_file).st_mtime - if time.time() - mt > update_freq: + if time.time() - mt > config['update_freq']: update = True except: update = True @@ -134,7 +168,7 @@ def downloadLists(): return None trk = [] - for url in urls: + for url in config['remote_lists']: l = loadURL(url) trk += l dbg("Remote URL '{}' loaded: {} trackers".format(url, len(l))) @@ -151,7 +185,7 @@ def downloadLists(): def readLocalLists(): trk = [] - for f in local_lists: + for f in config['local_lists']: l = loadFile(f) trk += l dbg("Local list '{}' loaded: {} trackers".format(f, len(l))) @@ -167,7 +201,7 @@ def readLocalLists(): lg('Remote URLs downloaded: {} trackers'.format(len(trk_remote))) elif trk_remote is None: trk_remote = [] - local_lists.append(cache_file) + config['local_lists'].append(cache_file) trk_local = readLocalLists() if trk_local: @@ -181,12 +215,9 @@ def readLocalLists(): exit(1) try: - if Client.__module__ == 'transmission_rpc.client': - tc = Client(host=host, port=port, username=user, password=pw) - else: - tc = Client(host, port=port, user=user, password=pw) + tc = Client(**client) except: - if not err_on_connect: + if not config['err_on_connect']: exit() print("Unable to connect to Transmission: ", sys.exc_info()[0]) @@ -197,7 +228,7 @@ def readLocalLists(): dbg('{} torrents total'.format(len(torrents))) for t in torrents: - if status_filter and not t.status in status_filter: + if config['status_filter'] and not t.status in config['status_filter']: dbg('{}: skipping due to status filter'.format(t.name)) continue From ac84c960561edfe9103e11843366df294788c8cd Mon Sep 17 00:00:00 2001 From: Mubashshir Date: Mon, 28 Sep 2020 17:10:26 +0600 Subject: [PATCH 08/24] fix compatibility with python 2 --- transmission-trackers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index 14eb5f5..3098c90 100644 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +from __future__ import print_function # Host, port, username and password to connect to Transmission # Set user and pw to None if auth is not required @@ -56,7 +57,7 @@ exit() if sys.version_info[0] == 2: - from urllib import Request, urlopen + from urllib2 import Request, urlopen from urlparse import urlparse else: from urllib.request import Request, urlopen From 96fc3b0c1eeb2a507df9f676b93a41ea0b0bc9ab Mon Sep 17 00:00:00 2001 From: Mubashshir Date: Mon, 28 Sep 2020 17:46:49 +0600 Subject: [PATCH 09/24] fix typo --- transmission-trackers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transmission-trackers.py b/transmission-trackers.py index 3098c90..21daf11 100644 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -50,7 +50,7 @@ try: from transmissionrpc import Client except ImportError: - try + try: from transmission_rpc import Client except ImportError: print("neither transmissionrpc nor transmission-rpc is installed") From 41ca6e136337e9c95333795022aa651151368a71 Mon Sep 17 00:00:00 2001 From: Mubashshir Date: Wed, 28 Oct 2020 01:21:33 +0600 Subject: [PATCH 10/24] chmod +x transmission-trackers.py --- transmission-trackers.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 transmission-trackers.py diff --git a/transmission-trackers.py b/transmission-trackers.py old mode 100644 new mode 100755 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 11/24] 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 12/24] 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 13/24] 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 14/24] 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 15/24] 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 16/24] 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 17/24] 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 18/24] 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 19/24] 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 20/24] 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 21/24] 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 22/24] 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 23/24] 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: From d6153fe454d88eab6d529ad8f61e1c6995f1fcf7 Mon Sep 17 00:00:00 2001 From: trotskylenin Date: Fri, 19 Dec 2025 17:54:39 -0300 Subject: [PATCH 24/24] - Fixed KeyError: 'tracker_filter' #22 - Fixed transmission-trackers-auto-cron.sh to find path correctly. - Added .gitignore to ignore the .cache folder --- .gitignore | 1 + transmission-trackers-auto-cron.sh | 13 +++++++------ transmission-trackers.py | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 .gitignore mode change 100644 => 100755 transmission-trackers-auto-cron.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..16d3c4d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.cache diff --git a/transmission-trackers-auto-cron.sh b/transmission-trackers-auto-cron.sh old mode 100644 new mode 100755 index 7aca918..b4cc0e7 --- a/transmission-trackers-auto-cron.sh +++ b/transmission-trackers-auto-cron.sh @@ -1,13 +1,14 @@ #!/bin/bash +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd)" # 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 +/usr/bin/python3 $DIR/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 +# If you are using docker for transmission use the following. Replace 'docker-container-name' with the appropriate name and uncomment the following +#if [ "$( docker container inspect -f '{{.State.Running}}' 'docker-container-name' )" = "true" ] +#then +#/usr/bin/python3 $DIR/transmission-trackers.py +#fi diff --git a/transmission-trackers.py b/transmission-trackers.py index 3a5e8c6..203ec20 100755 --- a/transmission-trackers.py +++ b/transmission-trackers.py @@ -54,7 +54,7 @@ 'silent': False, # Debug output - 'debug': False + 'debug': True } cache_file = None # Universal scope @@ -253,7 +253,8 @@ 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']): + # Use .get() to avoid error if key doesn't exist + if any(tracker in url for url in ttrk for tracker in config.get('tracker_filter', [])): dbg('{}: skipping due to tracker filter'.format(t.name)) continue