Skip to content

Commit 196137b

Browse files
committed
torrents-status: more intuative torrent states
1 parent 8dc2b8c commit 196137b

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

library/playback/torrents_status.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,32 @@ def shorten(s, width):
5656
if not torrents:
5757
processes.no_media_found()
5858

59+
interesting_states = [
60+
# 'uploading',
61+
"activeUP",
62+
"inactiveUP",
63+
"queuedUP",
64+
"stoppedUP",
65+
# "downloading",
66+
"stoppedDL",
67+
"queuedDL",
68+
"forcedMetaDL",
69+
"metaDL",
70+
"inactiveDL",
71+
"activeDL",
72+
"missingFiles",
73+
"error",
74+
]
75+
5976
torrents_by_state = {}
60-
for torrent in torrents:
61-
torrents_by_state.setdefault(torrent.state, []).append(torrent)
77+
for t in torrents:
78+
state = t.state
79+
if state not in interesting_states:
80+
if t.state_enum.is_complete:
81+
state = "activeUP" if t.uploaded_session > 0 else "inactiveUP"
82+
else:
83+
state = "activeDL" if t.downloaded_session > 0 else "inactiveDL"
84+
torrents_by_state.setdefault(state, []).append(t)
6285

6386
categories = []
6487
for state, state_torrents in torrents_by_state.items():
@@ -73,27 +96,11 @@ def shorten(s, width):
7396
}
7497
)
7598

76-
interesting_states = [
77-
"stoppedUP",
78-
"queuedUP",
79-
"stoppedDL",
80-
"forcedMetaDL",
81-
"metaDL",
82-
"forcedDL",
83-
"stalledDL",
84-
# 'forcedUP', 'stalledUP', 'uploading', # not very interesting
85-
"downloading",
86-
"missingFiles",
87-
"error",
88-
]
89-
9099
categories = sorted(
91100
categories,
92101
key=lambda d: (
93-
d["state"].endswith(("missingFiles", "error")),
94-
d["state"].endswith(("downloading", "DL")),
95-
iterables.safe_index(interesting_states, d["state"]),
96-
),
102+
iterables.safe_index(interesting_states, d["state"])
103+
)
97104
)
98105

99106
if len(torrents_by_state) > 1:

0 commit comments

Comments
 (0)