torrent-audit: only filter out complete torrents
This commit is contained in:
@@ -57,6 +57,19 @@ def get_qbit_torrents(qbit_client, category: str) -> dict[str, dict]:
|
||||
return {t["hash"].upper(): t for t in torrents}
|
||||
|
||||
|
||||
def is_complete(torrent: dict) -> bool:
|
||||
"""True iff the torrent's payload is fully on disk.
|
||||
|
||||
A torrent that was once imported can later end up at progress < 1 if the
|
||||
files were deleted or qBittorrent was reset and the torrent was re-added.
|
||||
Those entries must NOT be reported as abandoned-safe: their reported size
|
||||
is the metadata size, not what is actually on disk, so the reclaim figure
|
||||
would be a fiction and a 'safe to delete' verdict could kill a re-grab in
|
||||
progress.
|
||||
"""
|
||||
return float(torrent.get("progress", 0)) >= 1.0
|
||||
|
||||
|
||||
def gib(size_bytes: int) -> str:
|
||||
return f"{size_bytes / 1073741824:.1f}"
|
||||
|
||||
@@ -133,6 +146,12 @@ def find_movie_abandoned(radarr, qbit_movies):
|
||||
torrent = qbit_movies.get(ahash)
|
||||
if torrent is None:
|
||||
continue
|
||||
# Skip torrents whose payload is not fully on disk: their reported size
|
||||
# is metadata, not actual on-disk bytes, so flagging them as
|
||||
# abandoned-safe would lie about the reclaim and could disrupt a
|
||||
# re-download in progress.
|
||||
if not is_complete(torrent):
|
||||
continue
|
||||
|
||||
mid = hash_to_movie.get(ahash)
|
||||
movie = radarr_movies.get(mid) if mid else None
|
||||
@@ -211,6 +230,8 @@ def find_tv_abandoned(sonarr, qbit_tvshows):
|
||||
torrent = qbit_tvshows.get(ahash)
|
||||
if torrent is None:
|
||||
continue
|
||||
if not is_complete(torrent):
|
||||
continue
|
||||
|
||||
status = "SAFE"
|
||||
notes = []
|
||||
|
||||
Reference in New Issue
Block a user