refactor: add transmissionrpc_cf and 2hdp script
Some checks failed
dl / lint (push) Successful in 2m7s
dl / docker (push) Failing after 6m33s

This commit is contained in:
Michel Roux 2024-11-30 01:50:46 +01:00
parent 3a01e58244
commit cf68462ae2
5 changed files with 81 additions and 25 deletions

View File

@ -9,10 +9,10 @@ RUN apt-get update && \
apt-get install -y \
vim p7zip* git mc lftp rename wget curl procps psmisc \
openssh-client transmission-cli speedtest-cli \
python3-pip python3-requests python3-transmissionrpc && \
python3-pip python3-requests && \
apt-get install -y --no-install-recommends mame-tools && \
rm -rf /var/lib/apt/lists/* && \
pip install yt-dlp && \
pip install --extra-index-url https://git.crystalyx.net/api/packages/Xefir/pypi/simple/ transmissionrpc-cf yt-dlp \
curl -sSL https://raw.githubusercontent.com/MatanZ/tremc/main/tremc -o /usr/local/bin/tremc && \
curl -sSL https://raw.githubusercontent.com/putnam/binmerge/master/binmerge -o /usr/local/bin/binmerge && \
update-alternatives --set editor /usr/bin/vim.basic

49
commands/2hdp.py Normal file
View File

@ -0,0 +1,49 @@
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)

View File

@ -6,7 +6,7 @@ from sys import stdout
from time import sleep
from requests import head
from transmissionrpc import LOGGER, Client, DefaultHTTPHandler # type: ignore
from transmissionrpc_cf import LOGGER, Client # type: ignore
parser = ArgumentParser()
parser.add_argument("-u", "--username", required=True)
@ -16,21 +16,11 @@ 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():

34
poetry.lock generated
View File

@ -293,22 +293,34 @@ files = [
]
[[package]]
name = "transmission-rpc"
version = "7.0.11"
description = "Python module that implements the Transmission bittorent client JSON-RPC protocol"
name = "transmissionrpc-cf"
version = "0.2.1"
description = "Fork of transmissionrpc-ng with CloudFlare support"
optional = false
python-versions = "~=3.8"
python-versions = ">=3.7"
files = [
{file = "transmission_rpc-7.0.11-py3-none-any.whl", hash = "sha256:94fd008b54640dd9fff14d7ae26848f901e9d130a70950b8930f9b395988914f"},
{file = "transmission_rpc-7.0.11.tar.gz", hash = "sha256:5872322e60b42e368bc9c4724773aea4593113cb19bd2da589f0ffcdabe57963"},
{file = "transmissionrpc_cf-0.2.1-py3-none-any.whl", hash = "sha256:f1daf9f5e649250d64009f48a537d9f2f47eeba1687e304c0f073e6f8c484a9e"},
{file = "transmissionrpc_cf-0.2.1.tar.gz", hash = "sha256:dda3ab986bd07c674e0e6cf76721c699490cfb805c399fb81fa02406942601f9"},
]
[package.dependencies]
requests = ">=2.23,<3.0"
typing-extensions = ">=4.5.0"
transmissionrpc-ng = ">=0.13.1,<0.14.0"
[package.extras]
dev = ["coverage (==7.6.0)", "furo (==2024.7.18)", "mypy (==1.11.1)", "pre-commit (==3.8.0)", "pytest (==8.3.2)", "pytest-github-actions-annotate-failures (==0.2.0)", "sphinx (>=7,<=8)", "sphinx-autobuild (==2024.4.16)", "sphinx-copybutton (==0.5.2)", "sphinx-github-style (==1.2.2)", "sphinx-new-tab-link (==0.5.2)", "types-requests (==2.32.0.20240712)", "yarl (==1.9.4)"]
[package.source]
type = "legacy"
url = "https://git.crystalyx.net/api/packages/Xefir/pypi/simple"
reference = "gitea"
[[package]]
name = "transmissionrpc-ng"
version = "0.13.1"
description = "Python module that implements the Transmission BitTorent client RPC protocol."
optional = false
python-versions = ">=3.6"
files = [
{file = "transmissionrpc-ng-0.13.1.tar.gz", hash = "sha256:97d9b25784205cdc90e60857ee713a8b9b0cf02db9066969509ab97efd22bdba"},
{file = "transmissionrpc_ng-0.13.1-py3-none-any.whl", hash = "sha256:092954f0571392cd6ff498ea9b5a55de3b20f68fd919d6fe94e4f5e112a750bc"},
]
[[package]]
name = "types-requests"
@ -376,4 +388,4 @@ test = ["pytest (>=8.1,<9.0)", "pytest-rerunfailures (>=14.0,<15.0)"]
[metadata]
lock-version = "2.0"
python-versions = "^3.10"
content-hash = "9b7f8022fffca9b43b709f43f1d20088d2557c1eccd5ac8c7708e89fe07d10cb"
content-hash = "085ce1422940a6bc32eea3d6c3ca975435aecbbfd2e25ebca4e1720f5a147b74"

View File

@ -7,8 +7,8 @@ package-mode = false
[tool.poetry.dependencies]
python = "^3.10"
transmissionrpc-cf = "^0.2.1"
requests = "^2.32.3"
transmission-rpc = "^7.0.11"
yt-dlp = "^2024.11.27"
[tool.poetry.group.dev.dependencies]
@ -16,6 +16,11 @@ ruff = "^0.8.1"
mypy = "^1.13.0"
types-requests = "^2.32.0"
[[tool.poetry.source]]
name = "gitea"
url = "https://git.crystalyx.net/api/packages/Xefir/pypi/simple"
priority = "supplemental"
[tool.ruff]
line-length = 100