Skip to content

Commit 47c916b

Browse files
authored
Merge pull request #9 from dokeraj/add-Tracker-Alias-in-Tags
Tracker Aliases - in tags
2 parents 819287c + a5a2fdd commit 47c916b

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

qbitTorrentRemover.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import time
44
from dataclasses import dataclass
5+
from typing import Optional
56

67
import qbittorrentapi
78
from discord_webhook import DiscordWebhook, DiscordEmbed
@@ -34,6 +35,7 @@ class TorrentWrapper:
3435
class TrackerRatio:
3536
tracker: str
3637
ratio: float
38+
alias: Optional[str]
3739

3840

3941
print("Starting Script..")
@@ -47,27 +49,38 @@ class TrackerRatio:
4749

4850
# create the dataclass TrackerRatio that will be used later to make the comparisons
4951
def createTrackersRatioFromEnv():
50-
trackersRatioList = []
51-
# don't populate the list if the user didn't use this env var
52-
if QBIT_TRACKERS_WITH_RATIO_TRESHOLD == "":
53-
return trackersRatioList
54-
55-
for tracker in QBIT_TRACKERS_WITH_RATIO_TRESHOLD.split(";"):
56-
trackerUrlAndRatio = tracker.split("@")
57-
if len(trackerUrlAndRatio) != 2:
52+
def returnTrackerAndRatio(rest):
53+
trackerAndRatio = rest.split("@")
54+
tracker = trackerAndRatio[0]
55+
if len(trackerAndRatio) != 2:
5856
print(
59-
"ERR: ENV var TRACKERS_SEED_RATIO is not set properly - you need to make it in the following format:\n TRACKERNAME1@RATIO;TRACKERNAME2@RATIO\nWhere the TRACKERNAME is the name of the tracker (ex. torrentleech) and the RATIO is a decimal number (ex. 1.3)\nNow exiting app!")
57+
"ERR: ENV var TRACKERS_SEED_RATIO is not set properly - you need to make it in the following format:\n TRACKER_NAME1#TRACKER_ALIAS1@RATIO1;TRACKERNAME2@RATIO2\nWhere the TRACKERNAME is the domain of the tracker from the tracker url string (ex. torrentleech.org) and the RATIO is a decimal number (ex. 1.3). The TRACKER_ALIAS is optional and it's the display name in the torrent's tags.\nNow exiting app!")
6058
sys.exit(0)
6159

6260
ratio = 0.0
6361
try:
64-
ratio = float(trackerUrlAndRatio[1])
62+
ratio = float(trackerAndRatio[1])
6563
except ValueError:
6664
print(
6765
"ERR: ENV var TRACKERS_SEED_RATIO is not set properly - you need to set the ratio to be a decimal number like 2.3 for example. Now exiting app!")
6866
sys.exit(0)
6967

70-
trackersRatioList.append(TrackerRatio(str(trackerUrlAndRatio[0]), ratio))
68+
return tracker, ratio
69+
70+
trackersRatioList = []
71+
# don't populate the list if the user didn't use this env var
72+
if QBIT_TRACKERS_WITH_RATIO_TRESHOLD == "":
73+
return trackersRatioList
74+
75+
for tracker in QBIT_TRACKERS_WITH_RATIO_TRESHOLD.split(";"):
76+
if "#" in tracker:
77+
trackerName = tracker.split("#")[0]
78+
rest = tracker.split("#")[1]
79+
trackerAlias, ratio = returnTrackerAndRatio(rest)
80+
trackersRatioList.append(TrackerRatio(str(trackerName), ratio, trackerAlias))
81+
else:
82+
trackerName, ratio = returnTrackerAndRatio(tracker)
83+
trackersRatioList.append(TrackerRatio(str(trackerName), ratio, None))
7184

7285
return trackersRatioList
7386

@@ -132,7 +145,7 @@ def postStatsToDiscord(torrentsToRemove):
132145

133146
for cTor in torrentsToRemove:
134147
# get the current torrent ratio
135-
curRatio = f":small_orange_diamond: *Ratio: {round(cTor.torrent.ratio, 2)}*"
148+
curRatio = f":small_orange_diamond:*Ratio: {round(cTor.torrent.ratio, 2)}*"
136149

137150
# add the tags in the message if they exists for the current torrent
138151
existingTags = qbt_client.torrents_info(torrent_hashes=cTor.torrent.hash)[0]["tags"]

0 commit comments

Comments
 (0)