@@ -92,6 +92,21 @@ def parse_args(action, default_chromecast=None) -> argparse.Namespace:
9292--fetch-siblings each -O # get the first result per directory
9393--fetch-siblings if-audiobook -O # get the first result per directory if 'audiobook' is in the path
9494--fetch-siblings always -O # get 2,000 results per directory
95+ """ ,
96+ )
97+ ordering .add_argument (
98+ "--re-rank" ,
99+ "--rerank" ,
100+ "-rr" ,
101+ action = argparse_utils .ArgparseDict ,
102+ default = {},
103+ metavar = "COLUMN=WEIGHT" ,
104+ help = """Add key/value pairs re-rank sorting by multiple attributes (similar to MCDA)
105+ -rr 'regex_sort=1 cluster_sort=1 -size=3'
106+ will sort the playlist by taking into account size, regex, and clusters prioritizing size over the other two.
107+
108+ -u size desc -L 500 --cols path,title,size,time_modified -rs -rr 'regex_sort=1 time_modified=1'
109+ will get the 500 largest and then sort by regex_sort and time_modified
95110""" ,
96111 )
97112
@@ -407,7 +422,37 @@ def process_playqueue(args) -> None:
407422 if args .play_in_order :
408423 media = db_media .natsort_media (args , media )
409424
410- if args .regex_sort :
425+ if args .re_rank :
426+ import pandas
427+
428+ from library .utils import pd_utils
429+
430+ df = pandas .DataFrame (media )
431+
432+ if args .regex_sort :
433+ from library .text import regex_sort
434+
435+ sorted_media = regex_sort .sort_dicts (args , media )
436+ df = pd_utils .from_dict_add_path_rank (df , sorted_media , "regex_sort" )
437+ log .debug ("regex-sort: %s" , t .elapsed ())
438+ elif args .cluster_sort :
439+ from library .text import cluster_sort
440+
441+ sorted_media = cluster_sort .sort_dicts (args , media )
442+ df = pd_utils .from_dict_add_path_rank (df , sorted_media , "cluster_sort" )
443+ log .debug ("cluster-sort: %s" , t .elapsed ())
444+
445+ column_weights = {
446+ k .lstrip ("-" ): {
447+ "direction" : "desc" if k .startswith ("-" ) else "asc" ,
448+ "weight" : v or 1 ,
449+ }
450+ for k , v in args .re_rank .items ()
451+ }
452+ df = pd_utils .rank_dataframe (df , column_weights )
453+ media = df .to_dict (orient = "records" )
454+ log .debug ("re-rank: %s" , t .elapsed ())
455+ elif args .regex_sort :
411456 from library .text import regex_sort
412457
413458 media = regex_sort .sort_dicts (args , media )
0 commit comments