Skip to content

Commit

Permalink
torrents-status: more intuative torrent states
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanjacobd committed Jan 24, 2025
1 parent 8dc2b8c commit 196137b
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions library/playback/torrents_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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:
Expand Down

0 comments on commit 196137b

Please sign in to comment.