--sort-by and --reverse
no means "leave it as it is"
This commit is contained in:
parent
0740fb5f84
commit
324fdf9d96
1 changed files with 15 additions and 4 deletions
19
feed
19
feed
|
@ -232,8 +232,10 @@ def get_parser():
|
||||||
filters.add_argument('--max-len', default=0, type=int,
|
filters.add_argument('--max-len', default=0, type=int,
|
||||||
help='Exclude any audio that is longer '
|
help='Exclude any audio that is longer '
|
||||||
'than MAX_LEN seconds')
|
'than MAX_LEN seconds')
|
||||||
filters.add_argument('--random', default=False,
|
filters.add_argument('--sort-by', default='no', type=str,
|
||||||
action='store_true', help='Pick randomly')
|
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,
|
filters.add_argument('--min-len', default=0, type=int,
|
||||||
help='Exclude any audio that is shorter '
|
help='Exclude any audio that is shorter '
|
||||||
'than MIN_LEN seconds')
|
'than MIN_LEN seconds')
|
||||||
|
@ -306,6 +308,7 @@ def main():
|
||||||
or os.path.isfile(url):
|
or os.path.isfile(url):
|
||||||
# download the feed
|
# download the feed
|
||||||
tree = get_tree(url)
|
tree = get_tree(url)
|
||||||
|
# filtering
|
||||||
if not args.group:
|
if not args.group:
|
||||||
# get audio urls, removing those that are too long
|
# get audio urls, removing those that are too long
|
||||||
audios += [audio for audio in get_urls(tree) if
|
audios += [audio for audio in get_urls(tree) if
|
||||||
|
@ -343,9 +346,17 @@ def main():
|
||||||
else:
|
else:
|
||||||
logging.info('unsupported url `%s`', url)
|
logging.info('unsupported url `%s`', url)
|
||||||
|
|
||||||
audios = audios[args.start:]
|
# sort
|
||||||
if args.random:
|
if args.sort_by == 'random':
|
||||||
random.shuffle(audios)
|
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]
|
audios = audios[:args.howmany]
|
||||||
|
|
||||||
# the for loop excludes the last one
|
# the for loop excludes the last one
|
||||||
|
|
Loading…
Reference in a new issue