Fix handle_completed — guard against invalid completion_on timestamp

qBittorrent returns completion_on = -1 for torrents that were never
completed. datetime.fromtimestamp(-1) throws OSError on Windows.
Added explicit check for negative values and try/except for safety.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-02 07:02:21 +01:00
parent 15b498ca55
commit b37db5397e

View File

@@ -110,11 +110,15 @@ def handle_completed(qbt, cursor):
""" """
removed = 0 removed = 0
for t in qbt.torrents_info(): for t in qbt.torrents_info():
if not t.completion_on: if not t.completion_on or t.completion_on < 0:
continue
try:
completed_dt = datetime.fromtimestamp(t.completion_on)
except (OSError, ValueError, OverflowError):
continue continue
thash = t.hash.lower() thash = t.hash.lower()
completed_dt = datetime.fromtimestamp(t.completion_on)
try: try:
qbt.torrents_delete(torrent_hashes=thash, delete_files=False) qbt.torrents_delete(torrent_hashes=thash, delete_files=False)