Skip to content

Commit

Permalink
torrent-info: fix categories sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanjacobd committed Dec 11, 2024
1 parent 400d8fc commit 8497c29
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions xklb/playback/torrents_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ def torrents_info():
"file_count": sum(len(t.files) for t in torrents) if args.verbose >= 1 else None, # a bit slow
}
)

categories = sorted(
categories,
key=lambda d: (
d["state"].endswith(("downloading", "DL")),
iterables.safe_index(interesting_states, d["state"]),
),
)
printing.table(iterables.list_dict_filter_bool(categories))
print()

Expand Down
9 changes: 9 additions & 0 deletions xklb/utils/iterables.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ def safe_len(list_) -> Any | None:
return len(str(list_))


def safe_index(list_, value) -> int:
if not list_:
return 0
try:
return list_.index(value)
except ValueError:
return -1


def get_all_lists(nested_dict):
list_ = []

Expand Down

0 comments on commit 8497c29

Please sign in to comment.