mirror of
https://codeberg.org/hyperreal/admin-scripts
synced 2024-11-25 09:03:41 +01:00
Update seed_armbian_torrents.py
This commit is contained in:
parent
796de3bdff
commit
b2450248a1
@ -1,15 +1,22 @@
|
|||||||
#!/usr/bin/env python3
|
# /// script
|
||||||
|
# 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 download Armbian torrent files and add them to a qBittorrent
|
This script will scrape https://mirrors.jevincanders.net/armbian/dl/ for
|
||||||
instance. It's intended to be run under /etc/cron.weekly or used in a systemd
|
torrent files and add them to a qBittorrent instance. If there are already
|
||||||
timer.
|
Armbian torrents in the qBittorrent instance, they will be removed, and new
|
||||||
|
ones will be added in their place. This script is intended to be run under
|
||||||
This is a Python implementation of https://docs.armbian.com/Community_Torrent/
|
/etc/cron.weekly or used in a systemd timer.
|
||||||
for qBittorrent.
|
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
seed_armbian_torrents.py (HOSTNAME) (USERNAME) (PASSWORD)
|
seed_armbian_torrents.py (HOSTNAME) (USERNAME) (PASSWORD)
|
||||||
@ -27,4 +34,65 @@ 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):
|
||||||
|
url = "https://mirrors.jevincanders.net/armbian/dl/"
|
||||||
|
response = requests.get(url, timeout=60)
|
||||||
|
soup = BeautifulSoup(response.content, "html.parser")
|
||||||
|
links = soup.find_all("a")
|
||||||
|
|
||||||
|
archive_dir_urls = []
|
||||||
|
for link in links:
|
||||||
|
if (
|
||||||
|
link.text.endswith("/")
|
||||||
|
and not link.text.startswith("_")
|
||||||
|
and not link.text == "torrent/"
|
||||||
|
):
|
||||||
|
archive_dir_urls.append(url + link.text + "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)
|
||||||
|
Loading…
Reference in New Issue
Block a user