sane-bt-search: add "--sort-by size" option
This commit is contained in:
@@ -50,6 +50,7 @@ logger = logging.getLogger(__name__)
|
|||||||
class SortMethod(Enum):
|
class SortMethod(Enum):
|
||||||
Balanced = "balanced"
|
Balanced = "balanced"
|
||||||
Seeders = "seeders"
|
Seeders = "seeders"
|
||||||
|
Size = "size"
|
||||||
Tracker = "tracker"
|
Tracker = "tracker"
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
@@ -346,11 +347,13 @@ class Client:
|
|||||||
def sort_results(torrents: list[Torrent], by: SortMethod) -> list[Torrent]:
|
def sort_results(torrents: list[Torrent], by: SortMethod) -> list[Torrent]:
|
||||||
def key(t: Torrent) -> tuple[int, int, Torrent]:
|
def key(t: Torrent) -> tuple[int, int, Torrent]:
|
||||||
rank_seeders = -t.seeders
|
rank_seeders = -t.seeders
|
||||||
|
rank_size = -t.size
|
||||||
# TODO: `Balanced` should consider `size` and `pub_date`
|
# TODO: `Balanced` should consider `size` and `pub_date`
|
||||||
return {
|
return {
|
||||||
SortMethod.Balanced: (t.tracker.quality, rank_seeders, t.tracker.order, t),
|
SortMethod.Balanced: (t.tracker.quality, rank_seeders, t.tracker.order, rank_size, t),
|
||||||
SortMethod.Seeders: (rank_seeders, t.tracker.quality, t.tracker.order, t),
|
SortMethod.Seeders: (rank_seeders, t.tracker.quality, t.tracker.order, rank_size, t),
|
||||||
SortMethod.Tracker: (t.tracker.quality, t.tracker.order, rank_seeders, t),
|
SortMethod.Size: (rank_size, t.tracker.quality, rank_seeders, t.tracker.order, t),
|
||||||
|
SortMethod.Tracker: (t.tracker.quality, t.tracker.order, rank_seeders, rank_size, t),
|
||||||
}[by]
|
}[by]
|
||||||
return sorted(torrents, key=key)
|
return sorted(torrents, key=key)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user