2024-07-09 06:37:10 +02:00
|
|
|
#!/usr/bin/env python3
|
2024-06-23 16:27:58 +02:00
|
|
|
#
|
|
|
|
# Armbian torrents seed script
|
|
|
|
#
|
|
|
|
# This script will download Armbian torrent files and add them to a qBittorrent
|
2024-07-09 06:37:10 +02:00
|
|
|
# instance. It's intended to be run under /etc/cron.weekly or used in a systemd
|
|
|
|
# timer.
|
2024-06-23 16:27:58 +02:00
|
|
|
#
|
2024-07-09 06:37:10 +02:00
|
|
|
# Python implementation of https://docs.armbian.com/Community_Torrent/
|
|
|
|
|
|
|
|
import os
|
|
|
|
from io import BytesIO
|
|
|
|
from tempfile import TemporaryDirectory
|
|
|
|
from zipfile import ZipFile
|
|
|
|
|
|
|
|
import requests
|
|
|
|
from qbittorrent import Client
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
2024-07-15 01:51:57 +02:00
|
|
|
qb = Client("http://localhost:8080/")
|
2024-07-09 06:37:10 +02:00
|
|
|
qb.login()
|
|
|
|
|
|
|
|
with TemporaryDirectory() as tmp_dir:
|
|
|
|
req = requests.get(
|
|
|
|
"https://dl.armbian.com/torrent/all-torrents.zip", stream=True
|
|
|
|
)
|
|
|
|
zip_file = ZipFile(BytesIO(req.content))
|
|
|
|
zip_file.extractall(tmp_dir)
|
|
|
|
|
|
|
|
torrents = qb.torrents()
|
|
|
|
for torrent in torrents:
|
|
|
|
if "Armbian" in torrent["name"]:
|
|
|
|
qb.delete_permanently(torrent["hash"])
|
|
|
|
print(f"Removed {torrent['name']}")
|
|
|
|
|
|
|
|
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))}")
|