Compare commits

..

No commits in common. "a3c029e2fa54b0a0b4ea7b7c7d066c22d56f0adc" and "796de3bdffc47db1314edf81577a360a4b6a20e0" have entirely different histories.

2 changed files with 9 additions and 69 deletions

View File

@ -31,7 +31,7 @@ import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from docopt import docopt from docopt import docopt
args = docopt(__doc__) # type: ignore args = docopt(__doc__)
conn_info = dict( conn_info = dict(
host=args["HOSTNAME"], host=args["HOSTNAME"],
username=args["USERNAME"], username=args["USERNAME"],
@ -235,7 +235,7 @@ def add_freebsd(rel_ver: str):
with qbittorrentapi.Client(**conn_info) as qbt_client: with qbittorrentapi.Client(**conn_info) as qbt_client:
for line in data: for line in data:
if line.startswith("magnet:"): if line.startswith("magnet:"):
if qbt_client.torrents_add(line, category="distro") != "Ok.": if qbt_client.torrents_add(line) != "Ok.":
raise Exception("Failed to add torrent: " + line.split("=")[2]) raise Exception("Failed to add torrent: " + line.split("=")[2])
print(f"Added {line.split('=')[2]}") print(f"Added {line.split('=')[2]}")

View File

@ -1,22 +1,15 @@
# /// script #!/usr/bin/env python3
# dependencies = [
# "qbittorrent-api",
# "requests",
# "bs4",
# "docopt"
# ]
# ///
"""seed_armbian_torrents.py """seed_armbian_torrents.py
Description: Description:
Armbian torrents seed script Armbian torrents seed script
This script will scrape https://mirrors.jevincanders.net/armbian/dl/ for This script will download Armbian torrent files and add them to a qBittorrent
torrent files and add them to a qBittorrent instance. If there are already instance. It's intended to be run under /etc/cron.weekly or used in a systemd
Armbian torrents in the qBittorrent instance, they will be removed, and new timer.
ones will be added in their place. This script is 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: Usage:
seed_armbian_torrents.py (HOSTNAME) (USERNAME) (PASSWORD) seed_armbian_torrents.py (HOSTNAME) (USERNAME) (PASSWORD)
@ -34,57 +27,4 @@ import os
import qbittorrentapi import qbittorrentapi
import requests import requests
from bs4 import BeautifulSoup
from docopt import docopt from docopt import docopt
def add_torrents(args: dict):
archive_dir_urls = [
"https://mirrors.jevincanders.net/armbian/dl/orangepi5-plus/archive/",
"https://mirrors.jevincanders.net/armbian/dl/rockpro64/archive/",
"https://mirrors.jevincanders.net/armbian/dl/rpi4b/archive/",
]
torrent_urls = []
for url in archive_dir_urls:
response = requests.get(url, timeout=60)
soup = BeautifulSoup(response.content, "html.parser")
links = soup.find_all("a")
for link in links:
if link.text.endswith(".torrent"):
torrent_urls.append(url + link.text)
try:
qbt_client = qbittorrentapi.Client(
host=args["HOSTNAME"], username=args["USERNAME"], password=args["PASSWORD"]
)
qbt_client.auth_log_in()
for url in torrent_urls:
qbt_client.torrents_add(url, category="distro")
print(f"Added {os.path.basename(url)}")
qbt_client.auth_log_out()
except qbittorrentapi.LoginFailed as e:
print(e)
def remove_torrents(args: dict):
try:
qbt_client = qbittorrentapi.Client(
host=args["HOSTNAME"], username=args["USERNAME"], password=args["PASSWORD"]
)
qbt_client.auth_log_in()
for torrent in qbt_client.torrents_info():
if torrent.name.startswith("Armbian"):
torrent.delete(delete_files=True)
print(f"Removed {torrent.name}")
qbt_client.auth_log_out()
except qbittorrentapi.LoginFailed as e:
print(e)
if __name__ == "__main__":
args = docopt(__doc__) # type: ignore
remove_torrents(args)
add_torrents(args)