Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.0.8 #476

Merged
merged 3 commits into from
Jan 28, 2024
Merged

4.0.8 #476

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.7
4.0.8
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
flake8==6.1.0
flake8==7.0.0
pre-commit==3.6.0
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
67 changes: 38 additions & 29 deletions scripts/mover.py
Original file line number Diff line number Diff line change
@@ -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--#
Expand All @@ -26,46 +23,58 @@
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)
Loading