From e800652393e2c6fcceffca5e504d8df99871ebf4 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Mon, 22 Jul 2024 08:13:12 -0500 Subject: [PATCH] Use instance credentials for qbth --- README.org | 5 ++++- bin/qbth | 28 ++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/README.org b/README.org index e514edf..71669eb 100644 --- a/README.org +++ b/README.org @@ -4,7 +4,7 @@ These are scripts I use to automate various tasks in my homelab. ** bin - ~add_scihub_torrents~ : This script uses [[https://github.com/charmbracelet/gum][gum]] to select paginated text files that contain URLs of Sci Hub torrent files. For each selected file, the URLs are read and added to a qBittorrent instance. -- ~qbth~ : This is a helper program for adding Linux and BSD distros to a qBittorrent instance. +- ~qbth~ : This is a helper program for adding Linux and BSD distros to a qBittorrent instance. It's a bit crude, and the Python linter yells at me for it, but it gets the job done, and that's all I need it to do. Thank you. - ~qbt_sum_size~ : This script prints the total size of completed torrents and the total size of all torrents added to a qBittorrent instance. The former is a subset of the latter. - ~seed_armbian_torrents~ : This script downloads an archive from Armbian, extracts the torrent files within to a temporary directory, and adds each file to a qBittorrent instance. It first removes older Armbian torrents from the qBittorrent instance. - ~seed_scihub_torrents~ : This script finds which torrents have less than or equal to N seeders, where N is an integer argument supplied by the user. It then adds these torrents to a qBittorrent instance. @@ -14,3 +14,6 @@ These are scripts I use to automate various tasks in my homelab. *** system - ~server0-backup.service~ : A systemd service unit that runs the ~server0-backup~ script. - ~server0-backup.timer~ : A systemd timer unit that triggers the corresponding service unit. +*** user +- ~glances.service~ : A systemd service unit for the user scope that runs a glances server. +- ~gmcapsuled.service~ : A systemd service unit for the user scope that runs the gmcapsuled Gemini server. diff --git a/bin/qbth b/bin/qbth index f2386a3..f3beb09 100755 --- a/bin/qbth +++ b/bin/qbth @@ -1,25 +1,41 @@ #!/usr/bin/env python3 +"""qbth - qbittorrent helper + +Usage: + qbth (HOSTNAME) (USERNAME) (PASSWORD) + qbth -h + +Examples: + qbth "http://localhost:8080" "admin" "adminadmin" + qbth "https://cat.seedhost.eu/lol/qbittorrent" "lol" "meow" + +Options: + -h, --help show this help message and exit +""" + import json import os import subprocess import requests from bs4 import BeautifulSoup +from docopt import docopt from qbittorrent import Client -qb = Client("http://localhost:8080/") -qb.login() +args = docopt(__doc__) +qb = Client(args["HOSTNAME"]) +qb.login(username=args["USERNAME"], password=args["PASSWORD"]) -def add_torrents(urls): +def add_torrents(urls: list[str]): for url in urls: qb.download_from_link(url, category="distro") print(f"Added {os.path.basename(url)}") def add_torrents_from_html(webpage_url: str, torrent_substring: str): - reqs = requests.get(webpage_url) + reqs = requests.get(webpage_url, timeout=60) soup = BeautifulSoup(reqs.text, "html.parser") for link in soup.find_all("a"): if torrent_substring in link.get("href"): @@ -96,7 +112,7 @@ def remove_fedora(relver: str): def add_freebsd(relver: str): url = f"https://people.freebsd.org/~jmg/FreeBSD-{relver}-R-magnet.txt" - reqs = requests.get(url) + reqs = requests.get(url, timeout=60) data = reqs.text.split("\n") for line in data: @@ -131,7 +147,7 @@ def remove_netbsd(relver: str): def add_nixos(): url = "https://api.github.com/repos/AnimMouse/NixOS-ISO-Torrents/releases/latest" - reqs = requests.get(url) + reqs = requests.get(url, timeout=60) json_data = json.loads(reqs.text) for item in json_data["assets"]: qb.download_from_link(item["browser_download_url"], category="distro")