This commit is contained in:
2026-02-08 13:08:00 +01:00
parent 67e320287a
commit 1219f840c6
2 changed files with 182 additions and 33 deletions

View File

@@ -6,7 +6,7 @@ from datetime import datetime
# CONFIG
# ============================================================
DRY_RUN = False # ← změň na True pokud chceš test
DRY_RUN = False # ← change to True for testing
QBT_URL = "https://vladob.zen.usbx.me/qbittorrent"
QBT_USER = "vladob"
@@ -22,7 +22,6 @@ DB_CONFIG = {
"autocommit": True,
}
# ============================================================
# CONNECT
# ============================================================
@@ -49,6 +48,8 @@ def connect_db():
def main():
print("🚀 UltraCC completed torrent cleanup")
print(f"DRY_RUN = {DRY_RUN}")
print("------------------------------------------------")
qbt = connect_qbt()
db = connect_db()
@@ -58,11 +59,12 @@ def main():
removed_count = 0
skipped_count = 0
updated_db_count = 0
for t in torrents:
# ----------------------------------------------------
# Test completed via completion_on
# Only completed torrents
# ----------------------------------------------------
if not t.completion_on:
continue
@@ -70,11 +72,10 @@ def main():
thash = t.hash.lower()
name = t.name
state = t.state
completion_dt = datetime.fromtimestamp(t.completion_on)
# ----------------------------------------------------
# Skip pokud už DB má completion
# Check DB
# ----------------------------------------------------
cursor.execute("""
SELECT qb_completed_datetime
@@ -84,40 +85,64 @@ def main():
row = cursor.fetchone()
if row and row[0]:
skipped_count += 1
# ====================================================
# CASE 1 — Torrent completed in qBittorrent but NOT in DB
# → Update DB + Remove torrent
# ====================================================
if not row or not row[0]:
print(f"✔ COMPLETED (DB update required): {name}")
print(f" Completion time: {completion_dt}")
if not DRY_RUN:
cursor.execute("""
UPDATE torrents
SET
qb_state = %s,
qb_progress = 1,
qb_completed_datetime = %s,
qb_last_update = NOW()
WHERE torrent_hash = %s
""", (f"completed_removed ({state})", completion_dt, thash))
updated_db_count += 1
# Remove torrent
if DRY_RUN:
print(" [DRY] Would remove torrent")
else:
qbt.torrents_delete(delete_files=False, torrent_hashes=thash)
removed_count += 1
continue
print(f"✔ COMPLETED: {name}")
print(f" Completion time: {completion_dt}")
# ====================================================
# CASE 2 — Torrent completed in qBittorrent AND already completed in DB
# → Just remove torrent
# ====================================================
if row and row[0]:
# ----------------------------------------------------
# UPDATE DB
# ----------------------------------------------------
if not DRY_RUN:
cursor.execute("""
UPDATE torrents
SET
qb_state = %s,
qb_progress = 1,
qb_completed_datetime = %s,
qb_last_update = NOW()
WHERE torrent_hash = %s
""", (f"completed_removed ({state})", completion_dt, thash))
print(f"✔ COMPLETED (Already in DB → removing): {name}")
# ----------------------------------------------------
# REMOVE TORRENT
# ----------------------------------------------------
if DRY_RUN:
print(" [DRY] Would remove torrent")
else:
qbt.torrents_delete(delete_files=False, torrent_hashes=thash)
removed_count += 1
if DRY_RUN:
print(" [DRY] Would remove torrent")
else:
qbt.torrents_delete(delete_files=False, torrent_hashes=thash)
removed_count += 1
continue
skipped_count += 1
# =========================================================
# SUMMARY
# =========================================================
print("------------------------------------------------")
print(f"Removed torrents : {removed_count}")
print(f"DB updated : {updated_db_count}")
print(f"Skipped torrents : {skipped_count}")
print(f"DRY_RUN : {DRY_RUN}")
print("------------------------------------------------")
print(f"Removed torrents : {removed_count}")
print(f"Skipped torrents : {skipped_count}")
print(f"DRY_RUN = {DRY_RUN}")
if __name__ == "__main__":