From 5930f1cdba6cb2ff6cc68650f3eb159231d1417d Mon Sep 17 00:00:00 2001 From: boyska Date: Sun, 18 Feb 2018 20:34:31 +0100 Subject: [PATCH] sort by duration --- feed | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/feed b/feed index 635dcca..29702ff 100755 --- a/feed +++ b/feed @@ -241,16 +241,16 @@ def get_parser(): filters = p.add_argument_group('filters', 'Select only items that match ' 'these conditions') + filters.add_argument('--min-len', default=0, type=DurationType, + help='Exclude any audio that is shorter ' + 'than MIN_LEN seconds') filters.add_argument('--max-len', default=0, type=DurationType, help='Exclude any audio that is longer ' 'than MAX_LEN seconds') filters.add_argument('--sort-by', default='no', type=str, - choices=('random', 'date')) + choices=('random', 'date', 'duration')) filters.add_argument('--reverse', default=False, action='store_true', help='Reverse list order') - filters.add_argument('--min-len', default=0, type=DurationType, - help='Exclude any audio that is shorter ' - 'than MIN_LEN seconds') filters.add_argument('--min-age', default=datetime.timedelta(), type=TimeDeltaType, @@ -363,6 +363,8 @@ def main(): random.shuffle(audios) elif args.sort_by == 'date': audios.sort(key=lambda x: x.age) + elif args.sort_by == 'duration': + audios.sort(key=lambda x: x.duration) if args.reverse: audios.reverse()