mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-10-04 02:46:52 +08:00
Added mover script for Unraid
This commit is contained in:
parent
8d6fb140b9
commit
687e611083
1 changed files with 57 additions and 0 deletions
57
scripts/mover.py
Normal file
57
scripts/mover.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/env python3
|
||||
# This standalone script is used to pause torrents older than last x days, run mover (in Unraid) and start torrents again once completed
|
||||
import os, sys, time
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
# --DEFINE VARIABLES--#
|
||||
# Set Number of Days to stop torrents for the move
|
||||
days = 2
|
||||
qbt_host = 'qbittorrent:8080'
|
||||
qbt_user = None
|
||||
qbt_pass = None
|
||||
# --DEFINE VARIABLES--#
|
||||
|
||||
# --START SCRIPT--#
|
||||
try:
|
||||
from qbittorrentapi import Client, LoginFailed, APIConnectionError
|
||||
except ModuleNotFoundError:
|
||||
print("Requirements Error: qbittorrentapi not installed. Please install with pip")
|
||||
sys.exit(0)
|
||||
|
||||
current = datetime.now()
|
||||
timeoffset = (current - timedelta(days=days)).timestamp()
|
||||
|
||||
|
||||
def stop_start_torrents(torrent_list, pause=True):
|
||||
for torrent in torrent_list:
|
||||
if (torrent.added_on >= timeoffset):
|
||||
if pause:
|
||||
torrent.pause()
|
||||
else:
|
||||
torrent.resume()
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
client = Client(host=qbt_host, username=qbt_user, password=qbt_pass)
|
||||
except LoginFailed:
|
||||
raise("Qbittorrent Error: Failed to login. Invalid username/password.")
|
||||
except APIConnectionError:
|
||||
raise("Qbittorrent Error: Unable to connect to the client.")
|
||||
except Exception:
|
||||
raise("Qbittorrent Error: Unable to connect to the client.")
|
||||
torrent_list = client.torrents.info(sort='added_on', reverse=True)
|
||||
|
||||
# Pause Torrents
|
||||
print(f"Pausing torrents from the last {days} Days")
|
||||
stop_start_torrents(torrent_list, True)
|
||||
time.sleep(10)
|
||||
# Start mover
|
||||
print("Starting Mover")
|
||||
os.system('/usr/local/sbin/mover.old start')
|
||||
# Start Torrents
|
||||
print(f"Resuming paused torrents from the last {days} Days")
|
||||
stop_start_torrents(torrent_list, False)
|
Loading…
Add table
Reference in a new issue