admin-scripts/seed_scihub_max_seeders.py

54 lines
1.6 KiB
Python
Raw Normal View History

2024-07-21 16:55:52 +02:00
#!/usr/bin/env python3
2024-07-29 08:48:44 +02:00
"""seed_scihub_max_seeders.py
Description:
Find Sci Hub torrents containing MAX_SEEDERS seeders and add them to a qBittorrent
instance.
MAX_SEEDERS is a positive integer argument.
2024-07-21 16:55:52 +02:00
Usage:
2024-08-05 00:18:24 +02:00
seed_scihub_max_seeders.py [--only-count] (HOSTNAME) (USERNAME) (PASSWORD) (MAX_SEEDERS)
2024-07-29 08:48:44 +02:00
seed_scihub_max_seeders.py -h
2024-07-21 16:55:52 +02:00
Examples:
2024-07-29 08:48:44 +02:00
seed_scihub_max_seeders.py "http://localhost:8080" "admin" "adminadmin" 4
2024-08-05 00:18:24 +02:00
seed_scihub_max_seeders.py --only-count "https://cat.seedhost.eu/lol/qbittorrent" "lol" "pw" 3
2024-07-21 16:55:52 +02:00
Options:
2024-08-05 00:18:24 +02:00
--only-count do not add torrents, but only print the number of torrents with MAX_SEEDERS
2024-07-21 16:55:52 +02:00
-h, --help show this help message and exit
"""
import json
import os
import requests
from docopt import docopt
from qbittorrent import Client
if __name__ == "__main__":
2024-08-05 00:18:24 +02:00
args = docopt(__doc__) # type: ignore
2024-07-21 16:55:52 +02:00
qb = Client(args["HOSTNAME"])
qb.login(username=args["USERNAME"], password=args["PASSWORD"])
TORRENT_HEALTH_URL = (
"https://zrthstr.github.io/libgen_torrent_cardiography/torrent.json"
)
response = requests.get(TORRENT_HEALTH_URL, timeout=60)
json_data = json.loads(response.text)
2024-08-05 00:18:24 +02:00
if args["--only-count"]:
sum = 0
for item in json_data:
if item["seeders"] <= int(args["MAX_SEEDERS"]):
sum += 1
print(f"Number of torrents with <= {int(args["MAX_SEEDERS"])} seeders: {sum}")
else:
for item in json_data:
if item["seeders"] <= int(args["MAX_SEEDERS"]):
qb.download_from_link(item["link"], category="scihub")
print(f"Added {os.path.basename(item["name"])}")