From 196137ba4f7cf0344f731f7c7b8224e223626d93 Mon Sep 17 00:00:00 2001 From: Jacob Chapman <7908073+chapmanjacobd@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:35:10 +0000 Subject: [PATCH] torrents-status: more intuative torrent states --- library/playback/torrents_status.py | 47 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/library/playback/torrents_status.py b/library/playback/torrents_status.py index 95335b66..6ef91d0d 100644 --- a/library/playback/torrents_status.py +++ b/library/playback/torrents_status.py @@ -56,9 +56,32 @@ def shorten(s, width): if not torrents: processes.no_media_found() + interesting_states = [ + # 'uploading', + "activeUP", + "inactiveUP", + "queuedUP", + "stoppedUP", + # "downloading", + "stoppedDL", + "queuedDL", + "forcedMetaDL", + "metaDL", + "inactiveDL", + "activeDL", + "missingFiles", + "error", + ] + torrents_by_state = {} - for torrent in torrents: - torrents_by_state.setdefault(torrent.state, []).append(torrent) + for t in torrents: + state = t.state + if state not in interesting_states: + if t.state_enum.is_complete: + state = "activeUP" if t.uploaded_session > 0 else "inactiveUP" + else: + state = "activeDL" if t.downloaded_session > 0 else "inactiveDL" + torrents_by_state.setdefault(state, []).append(t) categories = [] for state, state_torrents in torrents_by_state.items(): @@ -73,27 +96,11 @@ def shorten(s, width): } ) - interesting_states = [ - "stoppedUP", - "queuedUP", - "stoppedDL", - "forcedMetaDL", - "metaDL", - "forcedDL", - "stalledDL", - # 'forcedUP', 'stalledUP', 'uploading', # not very interesting - "downloading", - "missingFiles", - "error", - ] - categories = sorted( categories, key=lambda d: ( - d["state"].endswith(("missingFiles", "error")), - d["state"].endswith(("downloading", "DL")), - iterables.safe_index(interesting_states, d["state"]), - ), + iterables.safe_index(interesting_states, d["state"]) + ) ) if len(torrents_by_state) > 1: