This commit is contained in:
2025-12-15 06:28:20 +01:00
parent 9c95999a26
commit 314eb20e6b
3 changed files with 368 additions and 1 deletions

72
60 Testcountoftorrents.py Normal file
View File

@@ -0,0 +1,72 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from datetime import datetime
import qbittorrentapi
# ==============================
# CONFIG přizpůsob si podle sebe
# ==============================
QBT_CONFIG = {
"host": "192.168.1.76",
"port": 8080,
"username": "admin",
"password": "adminadmin",
}
def fmt_ts(ts: int) -> str:
"""
Převod unix timestampu na čitelný string.
qBittorrent vrací -1 pokud hodnota není známá.
"""
if ts is None or ts <= 0:
return ""
try:
return datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S")
except Exception:
return f"invalid({ts})"
def main():
# Připojení
qb = qbittorrentapi.Client(
host=QBT_CONFIG["host"],
port=QBT_CONFIG["port"],
username=QBT_CONFIG["username"],
password=QBT_CONFIG["password"],
)
try:
qb.auth_log_in()
print("✅ Connected to qBittorrent\n")
except Exception as e:
print("❌ Could not connect to qBittorrent:", e)
return
# Všechno, žádný filter na downloading
torrents = qb.torrents_info(filter='all')
print(f"Found {len(torrents)} torrents (filter='all')\n")
for t in torrents:
# properties obsahují last_seen
try:
props = qb.torrents_properties(t.hash)
except Exception as e:
print(f"⚠️ Cannot get properties for {t.hash[:8]} {t.name}: {e}")
continue
seen_complete = getattr(t, "seen_complete", None) # z /torrents/info
last_seen = getattr(props, "last_seen", None) # z /torrents/properties
print("=" * 80)
print(f"Name : {t.name}")
print(f"Hash : {t.hash}")
print(f"State : {t.state}")
print(f"Progress : {float(t.progress) * 100:.2f}%")
print(f"Seen complete: {fmt_ts(seen_complete)} (t.seen_complete)")
print(f"Last seen : {fmt_ts(last_seen)} (props.last_seen)")
print("\n✅ Done.")
if __name__ == "__main__":
main()