2023-04-24 07:02:56 +00:00
|
|
|
#!/usr/bin/env python3
|
2023-04-23 19:51:03 +00:00
|
|
|
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
|
2024-11-30 11:12:15 +00:00
|
|
|
from transmissionrpc import LOGGER, Client, DefaultHTTPHandler # type: ignore
|
2023-04-23 19:51:03 +00:00
|
|
|
|
|
|
|
parser = ArgumentParser()
|
2023-06-09 16:30:06 +00:00
|
|
|
parser.add_argument("-u", "--username", required=True)
|
|
|
|
parser.add_argument("-p", "--password", required=True)
|
2023-04-23 19:51:03 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
LOGGER.setLevel(INFO)
|
|
|
|
LOGGER.addHandler(StreamHandler(stdout))
|
|
|
|
|
2024-11-30 11:12:15 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2023-04-23 19:51:03 +00:00
|
|
|
client = Client(
|
|
|
|
"https://torrent.crystalyx.net/transmission/rpc",
|
|
|
|
port=443,
|
|
|
|
user=args.username,
|
|
|
|
password=args.password,
|
2024-11-30 11:12:15 +00:00
|
|
|
http_handler=CustomHTTPHandler,
|
2023-04-23 19:51:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
for torrent in client.get_torrents():
|
|
|
|
if "nyaa" in torrent.comment:
|
2024-06-15 15:54:46 +00:00
|
|
|
try:
|
|
|
|
response = head(torrent.comment)
|
|
|
|
if response.status_code != 200:
|
2024-11-29 18:52:49 +00:00
|
|
|
print(f"{response.status_code} - {path.join(torrent.downloadDir, torrent.name)}")
|
2024-06-15 15:54:46 +00:00
|
|
|
except Exception:
|
2024-06-15 16:07:49 +00:00
|
|
|
print(
|
|
|
|
f"{response.status_code} - {torrent.comment} - {path.join(torrent.downloadDir, torrent.name)}" # noqa
|
|
|
|
)
|
2024-06-15 15:54:46 +00:00
|
|
|
|
2023-04-23 19:51:03 +00:00
|
|
|
sleep(1)
|