fix: show only live torrent transfers
This commit is contained in:
@@ -462,9 +462,13 @@ def _qbit_torrent_direction(torrent: dict[str, Any]) -> str | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _qbit_torrent_is_active(torrent: dict[str, Any]) -> bool:
|
def _qbit_torrent_transfer_direction(torrent: dict[str, Any]) -> str | None:
|
||||||
state = str(torrent.get("state") or "").lower()
|
"""Return a direction only while qBittorrent reports nonzero throughput."""
|
||||||
return bool(_qbit_torrent_direction(torrent)) or state in _QBITTORRENT_OTHER_ACTIVE_STATES
|
if _safe_int(torrent.get("dlspeed")) > 0:
|
||||||
|
return "downloading"
|
||||||
|
if _safe_int(torrent.get("upspeed")) > 0:
|
||||||
|
return "uploading"
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class QbittorrentWidgetSource:
|
class QbittorrentWidgetSource:
|
||||||
@@ -529,9 +533,9 @@ class QbittorrentWidgetSource:
|
|||||||
if widget_kind == "active":
|
if widget_kind == "active":
|
||||||
active = []
|
active = []
|
||||||
for torrent in torrents.values():
|
for torrent in torrents.values():
|
||||||
if not _qbit_torrent_is_active(torrent):
|
direction = _qbit_torrent_transfer_direction(torrent)
|
||||||
|
if not direction:
|
||||||
continue
|
continue
|
||||||
direction = _qbit_torrent_direction(torrent)
|
|
||||||
active.append(
|
active.append(
|
||||||
{
|
{
|
||||||
"name": torrent.get("name"),
|
"name": torrent.get("name"),
|
||||||
|
|||||||
@@ -1158,8 +1158,8 @@ async def test_qbittorrent_totals_counts_all_torrents():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_qbittorrent_active_filters_dl_ul_only():
|
async def test_qbittorrent_active_filters_current_transfers_only():
|
||||||
"""Active kind returns all active download/upload states, including queued work."""
|
"""Active kind returns only torrents with current download or upload throughput."""
|
||||||
from media_library_viewer_api.widgets.sources import QbittorrentWidgetSource
|
from media_library_viewer_api.widgets.sources import QbittorrentWidgetSource
|
||||||
|
|
||||||
adapter = QbittorrentWidgetSource()
|
adapter = QbittorrentWidgetSource()
|
||||||
@@ -1175,15 +1175,10 @@ async def test_qbittorrent_active_filters_dl_ul_only():
|
|||||||
result = await adapter.fetch(service, "active", {})
|
result = await adapter.fetch(service, "active", {})
|
||||||
|
|
||||||
active = result["torrents"]
|
active = result["torrents"]
|
||||||
assert len(active) == 5
|
assert len(active) == 2
|
||||||
names = [t["name"] for t in active]
|
names = [torrent["name"] for torrent in active]
|
||||||
assert "Movie.mkv" in names
|
assert names == ["Movie.mkv", "Show.mkv"]
|
||||||
assert "Show.mkv" in names
|
assert all((torrent["dl_speed"] or 0) > 0 or (torrent["up_speed"] or 0) > 0 for torrent in active)
|
||||||
assert "Forced download" in names
|
|
||||||
assert "Stalled upload" in names
|
|
||||||
assert "Queued" in names
|
|
||||||
# Paused torrents remain excluded, but queued transfer work is visible.
|
|
||||||
assert "Paused" not in names
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|||||||
Reference in New Issue
Block a user