mirror of
https://codeberg.org/hyperreal/admin-scripts
synced 2024-11-25 09:03:41 +01:00
Refactor
This commit is contained in:
parent
2d5f7e352b
commit
8d9cf5380a
@ -1,12 +1,27 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
"""seed_armbian_torrents
|
||||||
# Armbian torrents seed script
|
|
||||||
#
|
Description:
|
||||||
# This script will download Armbian torrent files and add them to a qBittorrent
|
Armbian torrents seed script
|
||||||
# instance. It's intended to be run under /etc/cron.weekly or used in a systemd
|
|
||||||
# timer.
|
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
|
||||||
# Python implementation of https://docs.armbian.com/Community_Torrent/
|
timer.
|
||||||
|
|
||||||
|
This is a Python implementation of https://docs.armbian.com/Community_Torrent/
|
||||||
|
for qBittorrent.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
seed_armbian_torrents (HOSTNAME) (USERNAME) (PASSWORD)
|
||||||
|
seed_armbian_torrents -h
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
seed_armbian_torrents "http://localhost:8080" "admin" "adminadmin"
|
||||||
|
seed_armbian_torrents "https://cat.seedhost.eu/lol/qbittorrent" "lol" "pw"
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help show this help message and exit.
|
||||||
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
@ -14,18 +29,24 @@ from tempfile import TemporaryDirectory
|
|||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
from docopt import docopt
|
||||||
from qbittorrent import Client
|
from qbittorrent import Client
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
args = docopt(__doc__)
|
||||||
|
|
||||||
qb = Client("http://localhost:8080/")
|
# Initialize client and login
|
||||||
qb.login()
|
qb = Client(args["HOSTNAME"])
|
||||||
|
qb.login(username=args["USERNAME"], password=args["PASSWORD"])
|
||||||
|
|
||||||
with TemporaryDirectory() as tmp_dir:
|
with TemporaryDirectory() as tmp_dir:
|
||||||
req = requests.get(
|
req = requests.get(
|
||||||
"https://dl.armbian.com/torrent/all-torrents.zip", stream=True
|
"https://dl.armbian.com/torrent/all-torrents.zip",
|
||||||
|
stream=True,
|
||||||
|
timeout=60,
|
||||||
)
|
)
|
||||||
zip_file = ZipFile(BytesIO(req.content))
|
|
||||||
|
with ZipFile(BytesIO(req.content)) as zip_file:
|
||||||
zip_file.extractall(tmp_dir)
|
zip_file.extractall(tmp_dir)
|
||||||
|
|
||||||
torrents = qb.torrents()
|
torrents = qb.torrents()
|
||||||
@ -38,4 +59,6 @@ if __name__ == "__main__":
|
|||||||
for torrent_file in torrent_files:
|
for torrent_file in torrent_files:
|
||||||
with open(os.path.join(tmp_dir, torrent_file), "rb") as tf:
|
with open(os.path.join(tmp_dir, torrent_file), "rb") as tf:
|
||||||
qb.download_from_file(tf, category="distro")
|
qb.download_from_file(tf, category="distro")
|
||||||
print(f"Added {os.path.basename(os.path.join(tmp_dir, torrent_file))}")
|
print(
|
||||||
|
f"Added {os.path.basename(os.path.join(tmp_dir, torrent_file))}"
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user