--sort-by and --reverse

no means "leave it as it is"
This commit is contained in:
boyska 2018-02-13 23:00:56 +01:00
parent 0740fb5f84
commit 324fdf9d96

19
feed
View file

@ -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