dl/commands/nyaa-404.py
Michel Roux 7e307d6e04
Some checks failed
dl / lint (push) Failing after 55s
dl / docker (push) Has been skipped
fix: 🌱 add url in case of timeout
2024-06-15 18:05:06 +02:00

48 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python3
from argparse import ArgumentParser
from logging import INFO, StreamHandler
from os import path
from sys import stdout
from time import sleep
from requests import head
from transmissionrpc import LOGGER, Client, DefaultHTTPHandler # type: ignore
parser = ArgumentParser()
parser.add_argument("-u", "--username", required=True)
parser.add_argument("-p", "--password", required=True)
args = parser.parse_args()
LOGGER.setLevel(INFO)
LOGGER.addHandler(StreamHandler(stdout))
class CustomHTTPHandler(DefaultHTTPHandler):
def request(self, url, query, headers, timeout):
headers["User-Agent"] = (
"Mozilla/5.0 (X11; Linux x86_64; rv:111.0) Gecko/20100101 Firefox/111.0"
)
return super().request(url, query, headers, timeout)
client = Client(
"https://torrent.crystalyx.net/transmission/rpc",
port=443,
user=args.username,
password=args.password,
http_handler=CustomHTTPHandler(),
)
for torrent in client.get_torrents():
if "nyaa" in torrent.comment:
try:
response = head(torrent.comment)
if response.status_code != 200:
print(
f"{response.status_code} - {path.join(torrent.downloadDir, torrent.name)}"
)
except Exception:
print(f"{response.status_code} - {torrent.comment} - {path.join(torrent.downloadDir, torrent.name)}")
sleep(1)