diff --git a/feed b/feed index 262a2fc..0253dac 100755 --- a/feed +++ b/feed @@ -232,8 +232,10 @@ def get_parser(): filters.add_argument('--max-len', default=0, type=int, help='Exclude any audio that is longer ' 'than MAX_LEN seconds') - filters.add_argument('--random', default=False, - action='store_true', help='Pick randomly') + filters.add_argument('--sort-by', default='no', type=str, + choices=('random', 'date')) + filters.add_argument('--reverse', default=False, + action='store_true', help='Reverse list order') filters.add_argument('--min-len', default=0, type=int, help='Exclude any audio that is shorter ' 'than MIN_LEN seconds') @@ -306,6 +308,7 @@ def main(): or os.path.isfile(url): # download the feed tree = get_tree(url) + # filtering if not args.group: # get audio urls, removing those that are too long audios += [audio for audio in get_urls(tree) if @@ -343,9 +346,17 @@ def main(): else: logging.info('unsupported url `%s`', url) - audios = audios[args.start:] - if args.random: + # sort + if args.sort_by == 'random': random.shuffle(audios) + elif args.sort_by == 'date': + audios.sort(key=lambda x: x.age) + + if args.reverse: + audios.reverse() + + # slice + audios = audios[args.start:] audios = audios[:args.howmany] # the for loop excludes the last one