* update requirements

* Add arguments for mover (#473)

* Add arguments for mover

Adding arguments to mover, so there is no point to define constants

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update mover.py

Co-authored-by: bobokun <12660469+bobokun@users.noreply.github.com>

* Update mover.py

Co-authored-by: bobokun <12660469+bobokun@users.noreply.github.com>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: bobokun <12660469+bobokun@users.noreply.github.com>

* 4.0.8

---------

Co-authored-by: Denys Kozhevnikov <github@mail.noonamer.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
bobokun 2024-01-28 17:39:29 -05:00 committed by GitHub
parent 937e9e886f
commit eebfb3e827
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 46 additions and 39 deletions

View file

@ -1,10 +1,8 @@
# Requirements Updated
- qbittorrent-api==2023.11.57
- ruamel.yaml==0.18.5
- qbittorrent-api==2024.1.58
# Bug Fixes
- Fixes #388
- Fixes #452
- Fixes #437
# Updates
- Adds arguments for mover script (Adds #473)
**Full Changelog**: https://github.com/StuffAnThings/qbit_manage/compare/v4.0.6...v4.0.7
Special thanks to @NooNameR for their contributions!
**Full Changelog**: https://github.com/StuffAnThings/qbit_manage/compare/v4.0.7...v4.0.8

View file

@ -1 +1 @@
4.0.7
4.0.8

View file

@ -1,2 +1,2 @@
flake8==6.1.0
flake8==7.0.0
pre-commit==3.6.0

View file

@ -1,6 +1,6 @@
bencodepy==0.9.5
GitPython==3.1.41
qbittorrent-api==2023.11.57
qbittorrent-api==2024.1.58
requests==2.31.0
retrying==1.3.4
ruamel.yaml==0.18.5

View file

@ -1,22 +1,19 @@
#!/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 argparse
import os
import sys
import time
from datetime import datetime
from datetime import timedelta
# --DEFINE VARIABLES--#
# Set Number of Days to stop torrents between two offsets
# days_from set to 0 will pause any torrents from todays date
# days_to will be the upper limit of how far you want to pause torrents to
days_from = 0
days_to = 2
qbt_host = "qbittorrent:8080"
qbt_user = None
qbt_pass = None
parser = argparse.ArgumentParser(prog="Qbit Mover", description="Stop torrents and kick off Unraid mover process")
parser.add_argument("--host", help="qbittorrent host including port", required=True)
parser.add_argument("-u", "--user", help="qbittorrent user", default="admin")
parser.add_argument("-p", "--password", help="qbittorrent password", default="adminadmin")
parser.add_argument("--days_from", help="Set Number of Days to stop torrents between two offsets", type=int, default=0)
parser.add_argument("--days_to", help="Set Number of Days to stop torrents between two offsets", type=int, default=2)
# --DEFINE VARIABLES--#
# --START SCRIPT--#
@ -26,46 +23,58 @@ except ModuleNotFoundError:
print('Requirements Error: qbittorrent-api not installed. Please install using the command "pip install qbittorrent-api"')
sys.exit(1)
current = datetime.now()
timeoffset_from = (current - timedelta(days=days_from)).timestamp()
timeoffset_to = (current - timedelta(days=days_to)).timestamp()
if days_from > days_to:
raise ("Config Error: days_from must be set lower than days_to")
def filter_torrents(torrent_list, timeoffset_from, timeoffset_to):
result = []
for torrent in torrent_list:
if torrent.added_on >= timeoffset_to and torrent.added_on <= timeoffset_from:
result.append(torrent)
elif torrent.added_on < timeoffset_to:
break
return result
def stop_start_torrents(torrent_list, pause=True):
for torrent in torrent_list:
if torrent.added_on >= timeoffset_to and torrent.added_on <= timeoffset_from:
if pause:
torrent.pause()
else:
torrent.resume()
if pause:
print(f"Pausing: {torrent.name} [{torrent.added_on}]")
torrent.pause()
else:
if torrent.added_on >= timeoffset_to:
continue
else:
break
print(f"Resuming: {torrent.name} [{torrent.added_on}]")
torrent.resume()
if __name__ == "__main__":
current = datetime.now()
args = parser.parse_args()
if args.days_from > args.days_to:
raise ("Config Error: days_from must be set lower than days_to")
try:
client = Client(host=qbt_host, username=qbt_user, password=qbt_pass)
client = Client(host=args.host, username=args.user, password=args.password)
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.")
timeoffset_from = current - timedelta(days=args.days_from)
timeoffset_to = current - timedelta(days=args.days_to)
torrent_list = client.torrents.info(sort="added_on", reverse=True)
torrents = filter_torrents(torrent_list, timeoffset_from.timestamp(), timeoffset_to.timestamp())
# Pause Torrents
print(f"Pausing torrents from {days_from} - {days_to} days ago")
stop_start_torrents(torrent_list, True)
print(f"Pausing [{len(torrents)}] torrents from {args.days_from} - {args.days_to} days ago")
stop_start_torrents(torrents, True)
time.sleep(10)
# Start mover
print("Starting Mover")
# Or using mover tunning
# os.system('/usr/local/sbin/mover start')
os.system("/usr/local/sbin/mover.old start")
# Start Torrents
print(f"Resuming paused torrents from {days_from} - {days_to} days ago")
stop_start_torrents(torrent_list, False)
print(f"Resuming [{len(torrents)}] paused torrents from {args.days_from} - {args.days_to} days ago")
stop_start_torrents(torrents, False)