dl/commands/2hdp.py

50 lines
1.5 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_cf import LOGGER, Client # 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))
client = Client(
"https://torrent.crystalyx.net/transmission/rpc",
port=443,
user=args.username,
password=args.password,
)
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)