✨ qBittorrent: cle API native (>= 5.2, Bearer) + compatibilite login 204 + suppression torrent en bypass/port separe
This commit is contained in:
1 parent
c7344f8988
commit
8e76fb7112
8 files changed
+143
-15
No files matched your search
+23
-5
@@ -100,6 +100,7 @@ def _qbittorrent_read(qb: QbittorrentConfig) -> QbittorrentSettingsRead:
|
||||
port=qb.port,
|
||||
username=qb.username,
|
||||
password_configured=qb.password is not None,
|
||||
api_key_configured=qb.api_key is not None,
|
||||
status=service_status(qb),
|
||||
tested_version=qb.test.version,
|
||||
tested_at=qb.test.at,
|
||||
@@ -200,6 +201,7 @@ def put_settings(payload: SettingsWrite) -> SettingsRead:
|
||||
qb_changed = bool(qb.url) and str(qb.url).rstrip("/") != (cfg.qbittorrent.url or "")
|
||||
qb_changed = qb_changed or bool(qb.username and qb.username != cfg.qbittorrent.username)
|
||||
qb_changed = qb_changed or bool(qb.password)
|
||||
qb_changed = qb_changed or bool(qb.api_key)
|
||||
if qb_changed:
|
||||
reset_test(cfg.qbittorrent)
|
||||
if qb.url is not None:
|
||||
@@ -208,6 +210,8 @@ def put_settings(payload: SettingsWrite) -> SettingsRead:
|
||||
cfg.qbittorrent.username = qb.username
|
||||
if qb.password:
|
||||
cfg.qbittorrent.password = qb.password
|
||||
if qb.api_key:
|
||||
cfg.qbittorrent.api_key = qb.api_key
|
||||
|
||||
write_config(cfg)
|
||||
return _settings_read()
|
||||
@@ -301,7 +305,7 @@ def qbittorrent_from_config() -> QbittorrentClient:
|
||||
url = build_base_url(qb.url, qb.port)
|
||||
if not url:
|
||||
raise HTTPException(status_code=409, detail="La connexion qBittorrent n'est pas configurée")
|
||||
return QbittorrentClient(url, qb.username, qb.password)
|
||||
return QbittorrentClient(url, qb.username, qb.password, qb.api_key)
|
||||
|
||||
|
||||
@app.get("/api/settings/qbittorrent", response_model=QbittorrentSettingsRead)
|
||||
@@ -318,6 +322,7 @@ def put_qbittorrent_settings(payload: QbittorrentSettingsWrite) -> QbittorrentSe
|
||||
)
|
||||
qb_changed = qb_changed or bool(payload.username and payload.username != qb.username)
|
||||
qb_changed = qb_changed or bool(payload.password)
|
||||
qb_changed = qb_changed or bool(payload.api_key)
|
||||
if qb_changed:
|
||||
reset_test(qb)
|
||||
if payload.url is not None:
|
||||
@@ -334,6 +339,8 @@ def put_qbittorrent_settings(payload: QbittorrentSettingsWrite) -> QbittorrentSe
|
||||
# Champs vides: mode bypass d'authentification qBittorrent, sans identifiants.
|
||||
qb.username = None
|
||||
qb.password = None
|
||||
if payload.api_key:
|
||||
qb.api_key = payload.api_key
|
||||
write_config(cfg)
|
||||
return _qbittorrent_read(qb)
|
||||
|
||||
@@ -381,7 +388,12 @@ def _log_config_summary() -> None:
|
||||
if getattr(cfg, name).url
|
||||
]
|
||||
if cfg.qbittorrent.url:
|
||||
mode = "identifiants" if cfg.qbittorrent.username else "bypass d'authentification"
|
||||
if cfg.qbittorrent.api_key:
|
||||
mode = "cle API"
|
||||
elif cfg.qbittorrent.username:
|
||||
mode = "identifiants"
|
||||
else:
|
||||
mode = "bypass d'authentification"
|
||||
configured.append(f"qbittorrent ({mode})")
|
||||
if configured:
|
||||
print(f"conf.json charge: {', '.join(configured)}", flush=True)
|
||||
@@ -480,12 +492,18 @@ def _linked_mkv(movie: IsoMovie) -> Path | None:
|
||||
|
||||
|
||||
async def _delete_iso_torrent(iso_path: str) -> None:
|
||||
"""Supprime le torrent qBittorrent de l'ISO (best effort, sans bloquer)."""
|
||||
"""Supprime le torrent qBittorrent de l'ISO (best effort, sans bloquer).
|
||||
|
||||
Fonctionne dans tous les modes d'authentification: cle API, identifiants
|
||||
ou bypass (l'URL doit simplement etre configuree). Le port separe est
|
||||
pris en compte via build_base_url.
|
||||
"""
|
||||
qb = read_config().qbittorrent
|
||||
if not qb.url or not qb.username or not qb.password:
|
||||
url = build_base_url(qb.url, qb.port)
|
||||
if not url:
|
||||
return
|
||||
try:
|
||||
client = QbittorrentClient(qb.url, qb.username, qb.password)
|
||||
client = QbittorrentClient(url, qb.username, qb.password, qb.api_key)
|
||||
torrents = await client.torrents()
|
||||
match = match_torrent(torrents, iso_path)
|
||||
if match is not None and match.get("hash"):
|
||||
|
||||
Reference in new issue
Block a user