-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Devin Buhl <[email protected]>
- Loading branch information
Showing
2 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import tldextract | ||
|
||
import qbittools | ||
|
||
INDEXER_SPECS = { | ||
'filelist': { | ||
'name': 'filelist', | ||
'urls': ['filelist.io', 'flro.org'], | ||
'required_seed_ratio': 1.05, | ||
'required_seed_days': 2.5, | ||
}, | ||
'torrentleech': { | ||
'name': 'torrentleech', | ||
'urls': ['tleechreload.org', 'torrentleech.org'], | ||
'required_seed_ratio': 1.05, | ||
'required_seed_days': 10.5, | ||
}, | ||
'hd-torrents': { | ||
'name': 'hd-torrents', | ||
'urls': ['hdts-announce.ru'], | ||
'required_seed_ratio': 1.05, | ||
'required_seed_days': 10.5, | ||
}, | ||
'hd-space': { | ||
'name': 'hd-space', | ||
'urls': ['hd-space.pw'], | ||
'required_seed_ratio': 1.05, | ||
'required_seed_days': 10.5, | ||
}, | ||
'scenetime': { | ||
'name': 'scenetime', | ||
'urls': ['scenetime.com'], | ||
'required_seed_ratio': 0, | ||
'required_seed_days': 3.5, | ||
}, | ||
'iptorrents': { | ||
'name': 'iptorrents', | ||
'urls': ['bgp.technology', 'empirehost.me', 'stackoverflow.tech'], | ||
'required_seed_ratio': 1.05, | ||
'required_seed_days': 14.5, | ||
}, | ||
'torrentseeds': { | ||
'name': 'torrentseeds', | ||
'urls': ['torrentseeds.org'], | ||
'required_seed_ratio': 1.05, | ||
'required_seed_days': 5.5, | ||
}, | ||
} | ||
|
||
DHT_MATCHES = [ | ||
'** [DHT] **', | ||
'** [PeX] **', | ||
'** [LSD] **' | ||
] | ||
|
||
def filter_indexer_by_args(indexer_list): | ||
results = [] | ||
for indexer_name in indexer_list: | ||
indexer_spec = INDEXER_SPECS.get(indexer_name) | ||
if indexer_spec: | ||
results.append(indexer_spec) | ||
return results | ||
|
||
def filter_indexer_by_url(indexer_list, domain): | ||
for indexer in indexer_list: | ||
if domain in indexer['urls']: | ||
return indexer | ||
return None | ||
|
||
def seconds(days: int) -> int: | ||
seconds_in_a_day = 86400 | ||
seconds = days * seconds_in_a_day | ||
return seconds | ||
|
||
def days(seconds: int) -> int: | ||
seconds_in_a_day = 86400 | ||
days = seconds / seconds_in_a_day | ||
return days | ||
|
||
def dhms(total_seconds: int) -> str: | ||
seconds = total_seconds % 60 | ||
total_minutes = total_seconds // 60 | ||
total_hours = total_minutes // 60 | ||
minutes = total_minutes % 60 | ||
days = total_hours // 24 | ||
hours = total_hours % 24 | ||
return f"{days}d{hours}h{minutes}m{seconds}s" | ||
|
||
def __init__(args, logger): | ||
client = qbittools.qbit_client(args) | ||
indexers = [item for sublist in args.indexer for item in sublist] | ||
filtered_indexer_list = filter_indexer_by_args(indexers) | ||
|
||
logger.info(f"Checking for expired torrents in qBittorrent") | ||
logger.info(f"Using indexers '{' '.join(indexers)}'") | ||
if args.dry_run: | ||
logger.info(f"Dry run mode initiated, no torrents will be deleted") | ||
|
||
torrents_info = client.torrents.info() | ||
for torrent in torrents_info: | ||
real_trackers = list(filter(lambda s: not s.url in DHT_MATCHES, torrent.trackers)) | ||
domain = tldextract.extract(sorted(real_trackers, key=lambda x: x.url)[0].url).registered_domain | ||
|
||
indexer = filter_indexer_by_url(filtered_indexer_list, domain) | ||
if indexer: | ||
if torrent['ratio'] >= indexer['required_seed_ratio']: | ||
logger.info(f"Removing torrent {torrent['name']} ({domain}) with matching indexer {indexer['name']} due to an expired ratio ({round(torrent['ratio'], 2)})") | ||
if not args.dry_run: | ||
torrent.delete(delete_files=False) | ||
elif torrent['seeding_time'] >= seconds(indexer['required_seed_days']): | ||
logger.info(f"Removing torrent {torrent['name']} ({domain}) with matching indexer {indexer['name']} due to an expired seeding time ({dhms(torrent['seeding_time'])})") | ||
if not args.dry_run: | ||
torrent.delete(delete_files=False) | ||
|
||
def add_arguments(subparser): | ||
parser = subparser.add_parser('expired') | ||
parser.add_argument('--dry-run', action='store_true', help='Do not delete the torrents only log them', required=False) | ||
parser.add_argument('--indexer', nargs='*', action='append', metavar='myindexer', default=[], help='Indexer, can be repeated multiple times', required=False) | ||
|
||
qbittools.add_default_args(parser) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters