Files
torrents/Seedbox/10 Nahraniexistujicich.py
2026-03-01 07:49:08 +01:00

119 lines
3.1 KiB
Python

import pymysql
import qbittorrentapi
# ============================================================
# CONFIG
# ============================================================
DRY_RUN = False
QBT_URL = "https://vladob.zen.usbx.me/qbittorrent"
QBT_USER = "vladob"
QBT_PASS = "jCni3U6d#y4bfcm"
DB_CONFIG = {
"host": "192.168.1.50",
"port": 3306,
"user": "root",
"password": "Vlado9674+",
"database": "torrents",
"charset": "utf8mb4",
"autocommit": True,
}
# ============================================================
# MAIN
# ============================================================
def main():
print("=" * 60)
print("QB COMPLETED CLEANUP")
print(f"DRY_RUN = {DRY_RUN}")
print("=" * 60)
# --------------------------------------------------------
# DB CONNECT
# --------------------------------------------------------
db = pymysql.connect(**DB_CONFIG)
cursor = db.cursor()
# --------------------------------------------------------
# CONNECT QB
# --------------------------------------------------------
print("🔌 Connecting qBittorrent...")
qbt = qbittorrentapi.Client(
host=QBT_URL,
username=QBT_USER,
password=QBT_PASS,
VERIFY_WEBUI_CERTIFICATE=False
)
qbt.auth_log_in()
torrents = qbt.torrents_info()
print(f"Loaded torrents from qB: {len(torrents)}")
processed = 0
removed = 0
# --------------------------------------------------------
# LOOP
# --------------------------------------------------------
for t in torrents:
if getattr(t, "amount_left", 1) != 0:
continue
print(f"✅ COMPLETED → {t.name}")
# ----------------------------------------------------
# UPDATE DB
# ----------------------------------------------------
if not DRY_RUN:
cursor.execute("""
UPDATE torrents
SET
qb_completed_datetime = COALESCE(qb_completed_datetime, NOW()),
qb_state = %s,
qb_last_update = NOW()
WHERE torrent_hash = %s
""", (t.state, t.hash.lower()))
else:
print(f"[DRY] Would update DB → {t.name}")
processed += 1
# ----------------------------------------------------
# REMOVE FROM QB (KEEP FILES)
# ----------------------------------------------------
try:
if DRY_RUN:
print(f"[DRY] Would remove torrent from qB → {t.name}")
else:
qbt.torrents_delete(
torrent_hashes=t.hash,
delete_files=False
)
removed += 1
except Exception as e:
print(f"❌ Remove failed: {t.name}{e}")
# --------------------------------------------------------
# SUMMARY
# --------------------------------------------------------
print("\n" + "=" * 60)
print(f"Completed processed: {processed}")
print(f"Removed from qB: {removed}")
print("=" * 60)
db.close()
if __name__ == "__main__":
main()