From 796de3bdffc47db1314edf81577a360a4b6a20e0 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio Date: Sat, 16 Nov 2024 13:35:35 -0600 Subject: [PATCH] Organize, modularize, compartmentalize --- .archived/{ => python}/add_scihub_torrents.py | 0 .archived/{ => python}/mastodon.py | 0 .../{ => python}/seed_scihub_max_seeders.py | 0 .../{ => shell}/armbian-tx-stats-html.nu | 0 .archived/{ => shell}/backup-to-minio.bash | 0 .archived/{ => shell}/qbt-sum-size.bash | 0 .archived/{ => shell}/qbth.bash | 0 .archived/{ => shell}/qbtlist.bash | 0 .../{rsync-backup => shell/rsync-backup.bash} | 0 .../{ => shell}/seed-armbian-torrents.bash | 0 .archived/{ => shell}/seed-armbian-tx.nu | 0 .../server0_backup.bash} | 0 .archived/{ => shell}/tx-stats-html.nu | 0 .gitignore | 4 +- .../add_qbt_trackers.py | 0 .../calculate_mirror_size.py | 0 .../fetch_combined_trackers_list.py | 0 .../fetch_scihub_infohashes.py | 0 list_torrents.py => python/list_torrents.py | 0 mastodon.py => python/mastodon.py | 0 qbt_sum_size.py => python/qbt_sum_size.py | 0 qbth.py => python/qbth.py | 0 python/requirements.txt | 7 +++ .../scihub_knapsack.py | 0 python/seed_armbian_torrents.py | 30 +++++++++ .../sync_from_remotes.py | 0 .../sync_to_remotes.py | 0 update_tracker.py => python/update_tracker.py | 0 seed_armbian_torrents.py | 63 ------------------- qbt_stats_html.nu => shell/qbt_stats_html.nu | 0 .../record_mastodon_media_size | 0 .../sync_to_protondrive | 0 32 files changed, 38 insertions(+), 66 deletions(-) rename .archived/{ => python}/add_scihub_torrents.py (100%) rename .archived/{ => python}/mastodon.py (100%) rename .archived/{ => python}/seed_scihub_max_seeders.py (100%) rename .archived/{ => shell}/armbian-tx-stats-html.nu (100%) rename .archived/{ => shell}/backup-to-minio.bash (100%) rename .archived/{ => shell}/qbt-sum-size.bash (100%) rename .archived/{ => shell}/qbth.bash (100%) rename .archived/{ => shell}/qbtlist.bash (100%) rename .archived/{rsync-backup => shell/rsync-backup.bash} (100%) rename .archived/{ => shell}/seed-armbian-torrents.bash (100%) rename .archived/{ => shell}/seed-armbian-tx.nu (100%) rename .archived/{server0_backup.sh => shell/server0_backup.bash} (100%) rename .archived/{ => shell}/tx-stats-html.nu (100%) rename add_qbt_trackers.py => python/add_qbt_trackers.py (100%) rename calculate_mirror_size.py => python/calculate_mirror_size.py (100%) rename fetch_combined_trackers_list.py => python/fetch_combined_trackers_list.py (100%) rename fetch_scihub_infohashes.py => python/fetch_scihub_infohashes.py (100%) rename list_torrents.py => python/list_torrents.py (100%) rename mastodon.py => python/mastodon.py (100%) rename qbt_sum_size.py => python/qbt_sum_size.py (100%) rename qbth.py => python/qbth.py (100%) create mode 100644 python/requirements.txt rename scihub_knapsack.py => python/scihub_knapsack.py (100%) create mode 100755 python/seed_armbian_torrents.py rename sync_from_remotes.py => python/sync_from_remotes.py (100%) rename sync_to_remotes.py => python/sync_to_remotes.py (100%) rename update_tracker.py => python/update_tracker.py (100%) delete mode 100755 seed_armbian_torrents.py rename qbt_stats_html.nu => shell/qbt_stats_html.nu (100%) rename record_mastodon_media_size => shell/record_mastodon_media_size (100%) rename sync_to_protondrive => shell/sync_to_protondrive (100%) diff --git a/.archived/add_scihub_torrents.py b/.archived/python/add_scihub_torrents.py similarity index 100% rename from .archived/add_scihub_torrents.py rename to .archived/python/add_scihub_torrents.py diff --git a/.archived/mastodon.py b/.archived/python/mastodon.py similarity index 100% rename from .archived/mastodon.py rename to .archived/python/mastodon.py diff --git a/.archived/seed_scihub_max_seeders.py b/.archived/python/seed_scihub_max_seeders.py similarity index 100% rename from .archived/seed_scihub_max_seeders.py rename to .archived/python/seed_scihub_max_seeders.py diff --git a/.archived/armbian-tx-stats-html.nu b/.archived/shell/armbian-tx-stats-html.nu similarity index 100% rename from .archived/armbian-tx-stats-html.nu rename to .archived/shell/armbian-tx-stats-html.nu diff --git a/.archived/backup-to-minio.bash b/.archived/shell/backup-to-minio.bash similarity index 100% rename from .archived/backup-to-minio.bash rename to .archived/shell/backup-to-minio.bash diff --git a/.archived/qbt-sum-size.bash b/.archived/shell/qbt-sum-size.bash similarity index 100% rename from .archived/qbt-sum-size.bash rename to .archived/shell/qbt-sum-size.bash diff --git a/.archived/qbth.bash b/.archived/shell/qbth.bash similarity index 100% rename from .archived/qbth.bash rename to .archived/shell/qbth.bash diff --git a/.archived/qbtlist.bash b/.archived/shell/qbtlist.bash similarity index 100% rename from .archived/qbtlist.bash rename to .archived/shell/qbtlist.bash diff --git a/.archived/rsync-backup b/.archived/shell/rsync-backup.bash similarity index 100% rename from .archived/rsync-backup rename to .archived/shell/rsync-backup.bash diff --git a/.archived/seed-armbian-torrents.bash b/.archived/shell/seed-armbian-torrents.bash similarity index 100% rename from .archived/seed-armbian-torrents.bash rename to .archived/shell/seed-armbian-torrents.bash diff --git a/.archived/seed-armbian-tx.nu b/.archived/shell/seed-armbian-tx.nu similarity index 100% rename from .archived/seed-armbian-tx.nu rename to .archived/shell/seed-armbian-tx.nu diff --git a/.archived/server0_backup.sh b/.archived/shell/server0_backup.bash similarity index 100% rename from .archived/server0_backup.sh rename to .archived/shell/server0_backup.bash diff --git a/.archived/tx-stats-html.nu b/.archived/shell/tx-stats-html.nu similarity index 100% rename from .archived/tx-stats-html.nu rename to .archived/shell/tx-stats-html.nu diff --git a/.gitignore b/.gitignore index b6628c6..f421fb3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -.direnv -.venv - +python/.venv diff --git a/add_qbt_trackers.py b/python/add_qbt_trackers.py similarity index 100% rename from add_qbt_trackers.py rename to python/add_qbt_trackers.py diff --git a/calculate_mirror_size.py b/python/calculate_mirror_size.py similarity index 100% rename from calculate_mirror_size.py rename to python/calculate_mirror_size.py diff --git a/fetch_combined_trackers_list.py b/python/fetch_combined_trackers_list.py similarity index 100% rename from fetch_combined_trackers_list.py rename to python/fetch_combined_trackers_list.py diff --git a/fetch_scihub_infohashes.py b/python/fetch_scihub_infohashes.py similarity index 100% rename from fetch_scihub_infohashes.py rename to python/fetch_scihub_infohashes.py diff --git a/list_torrents.py b/python/list_torrents.py similarity index 100% rename from list_torrents.py rename to python/list_torrents.py diff --git a/mastodon.py b/python/mastodon.py similarity index 100% rename from mastodon.py rename to python/mastodon.py diff --git a/qbt_sum_size.py b/python/qbt_sum_size.py similarity index 100% rename from qbt_sum_size.py rename to python/qbt_sum_size.py diff --git a/qbth.py b/python/qbth.py similarity index 100% rename from qbth.py rename to python/qbth.py diff --git a/python/requirements.txt b/python/requirements.txt new file mode 100644 index 0000000..079634f --- /dev/null +++ b/python/requirements.txt @@ -0,0 +1,7 @@ +beautifulsoup4==4.12.3 +docopt==0.6.2 +pandas==2.2.3 +qbittorrent==0.1.6 +Requests==2.32.3 +resend==2.4.0 +rich==13.9.4 diff --git a/scihub_knapsack.py b/python/scihub_knapsack.py similarity index 100% rename from scihub_knapsack.py rename to python/scihub_knapsack.py diff --git a/python/seed_armbian_torrents.py b/python/seed_armbian_torrents.py new file mode 100755 index 0000000..7a82aec --- /dev/null +++ b/python/seed_armbian_torrents.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +"""seed_armbian_torrents.py + +Description: +Armbian torrents seed script + +This script will download Armbian torrent files and add them to a qBittorrent +instance. It's intended to be run under /etc/cron.weekly or used in a systemd +timer. + +This is a Python implementation of https://docs.armbian.com/Community_Torrent/ +for qBittorrent. + +Usage: + seed_armbian_torrents.py (HOSTNAME) (USERNAME) (PASSWORD) + seed_armbian_torrents.py -h + +Examples: + seed_armbian_torrents.py "http://localhost:8080" "admin" "adminadmin" + seed_armbian_torrents.py "https://cat.seedhost.eu/lol/qbittorrent" "lol" "pw" + +Options: + -h, --help show this help message and exit. +""" + +import os + +import qbittorrentapi +import requests +from docopt import docopt diff --git a/sync_from_remotes.py b/python/sync_from_remotes.py similarity index 100% rename from sync_from_remotes.py rename to python/sync_from_remotes.py diff --git a/sync_to_remotes.py b/python/sync_to_remotes.py similarity index 100% rename from sync_to_remotes.py rename to python/sync_to_remotes.py diff --git a/update_tracker.py b/python/update_tracker.py similarity index 100% rename from update_tracker.py rename to python/update_tracker.py diff --git a/seed_armbian_torrents.py b/seed_armbian_torrents.py deleted file mode 100755 index 57f76d2..0000000 --- a/seed_armbian_torrents.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python3 -"""seed_armbian_torrents.py - -Description: -Armbian torrents seed script - -This script will download Armbian torrent files and add them to a qBittorrent -instance. It's intended to be run under /etc/cron.weekly or used in a systemd -timer. - -This is a Python implementation of https://docs.armbian.com/Community_Torrent/ -for qBittorrent. - -Usage: - seed_armbian_torrents.py (HOSTNAME) (USERNAME) (PASSWORD) - seed_armbian_torrents.py -h - -Examples: - seed_armbian_torrents.py "http://localhost:8080" "admin" "adminadmin" - seed_armbian_torrents.py "https://cat.seedhost.eu/lol/qbittorrent" "lol" "pw" - -Options: - -h, --help show this help message and exit. -""" - -import os -from io import BytesIO -from tempfile import TemporaryDirectory -from zipfile import ZipFile - -import requests -from docopt import docopt -from qbittorrent import Client - -if __name__ == "__main__": - args = docopt(__doc__) - - # Initialize client and login - qb = Client(args["HOSTNAME"]) - qb.login(username=args["USERNAME"], password=args["PASSWORD"]) - - with TemporaryDirectory() as tmp_dir: - req = requests.get( - "https://dl.armbian.com/torrent/all-torrents.zip", - stream=True, - timeout=60, - ) - - with ZipFile(BytesIO(req.content)) as zip_file: - zip_file.extractall(tmp_dir) - - for torrent in qb.torrents(): - if "Armbian" in torrent.get("name"): # type: ignore - qb.delete_permanently(torrent.get("hash")) # type: ignore - print(f"Removed {torrent.get('name')}") # type: ignore - - torrent_files = os.listdir(tmp_dir) - for torrent_file in torrent_files: - with open(os.path.join(tmp_dir, torrent_file), "rb") as tf: - qb.download_from_file(tf, category="distro") - print( - f"Added {os.path.basename(os.path.join(tmp_dir, torrent_file))}" - ) diff --git a/qbt_stats_html.nu b/shell/qbt_stats_html.nu similarity index 100% rename from qbt_stats_html.nu rename to shell/qbt_stats_html.nu diff --git a/record_mastodon_media_size b/shell/record_mastodon_media_size similarity index 100% rename from record_mastodon_media_size rename to shell/record_mastodon_media_size diff --git a/sync_to_protondrive b/shell/sync_to_protondrive similarity index 100% rename from sync_to_protondrive rename to shell/sync_to_protondrive