#!/usr/bin/env python3 from argparse import ArgumentParser from csv import DictWriter from sys import stdout from xml.etree import ElementTree from requests import get from transmissionrpc import Client, DefaultHTTPHandler # type: ignore parser = ArgumentParser() parser.add_argument("-u", "--username", required=True) parser.add_argument("-p", "--password", required=True) args = parser.parse_args() 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(), ) movies = [] 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 or title.text is None: continue row = { "title": title.text, "season": f"Saison {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.lower() in torrent.name.lower(): row["hash"] = torrent.hashString break movies.append(title.text.lower()) writer.writerow(row) tree = ElementTree.fromstring( get("https://www.calvinballconsortium.fr/podcasts/leretourdujeudi/feed.xml").text ) for item in tree.findall(".//item"): title = item.find("title") if title is None or title.text is None or title.text.lower() in movies: continue row = { "title": title.text, "season": "Jeudi", "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.lower() in torrent.name.lower(): row["hash"] = torrent.hashString break movies.append(title.text.lower()) writer.writerow(row)