dl/commands/2hdp.py

61 lines
1.8 KiB
Python
Raw Normal View History

from argparse import ArgumentParser
from csv import DictWriter
from logging import INFO, StreamHandler
from sys import stdout
from xml.etree import ElementTree
from requests import get
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,
)
torrents = client.get_torrents()
writer = DictWriter(stdout, fieldnames=["season", "title", "hash", "url"])
tree = ElementTree.fromstring(get("https://feed.ausha.co/Loa7srdWGm1b").text)
for item in tree.findall(".//item"):
title = item.find("title")
season = item.find("itunes:season", {"itunes": "http://www.itunes.com/dtds/podcast-1.0.dtd"})
if season is None or title is None:
continue
row = {
"title": title.text,
"season": season.text,
"hash": "",
"url": f"https://www.ygg.re/engine/search?name={title.text}&description=&file=&uploader=&category=2145&sub_category=2183&option_langue:multiple[0]=4&do=search&order=asc&sort=publish_date",
}
for torrent in torrents:
if title.text is not None and title.text.lower() in torrent.name.lower():
row["hash"] = torrent.hashString
break
writer.writerow(row)