FIX filtering for files, too
This commit is contained in:
parent
229b946a32
commit
086c1f9aa6
1 changed files with 39 additions and 36 deletions
75
feed
75
feed
|
@ -330,47 +330,50 @@ def main():
|
|||
|
||||
audios = []
|
||||
for url in sources:
|
||||
if url.startswith('http:') or url.startswith('https:') \
|
||||
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
|
||||
(args.max_len == 0 or
|
||||
audio.duration <= args.max_len) and
|
||||
(args.min_len == 0 or
|
||||
audio.duration >= args.min_len) and
|
||||
(args.min_age.total_seconds() == 0 or
|
||||
audio.age >= args.min_age) and
|
||||
(args.max_age.total_seconds() == 0 or
|
||||
audio.age <= args.max_age)
|
||||
]
|
||||
else:
|
||||
groups = get_grouped_urls(tree)
|
||||
audios += [groups[g] for g in groups.keys()
|
||||
if
|
||||
(args.max_len == 0 or
|
||||
groups[g].duration <= args.max_len) and
|
||||
(args.min_len == 0 or
|
||||
groups[g].duration >= args.max_len) and
|
||||
(args.min_age.total_seconds() == 0 or
|
||||
groups[g].age >= args.min_age) and
|
||||
(args.max_age.total_seconds() == 0 or
|
||||
groups[g].age <= args.max_age)
|
||||
]
|
||||
elif os.path.isdir(url):
|
||||
audiodir = get_audio_from_dir(url)
|
||||
if not args.group:
|
||||
if not args.group:
|
||||
if os.path.isdir(url):
|
||||
audiodir = get_audio_from_dir(url)
|
||||
audios += audiodir
|
||||
elif url.startswith('http:') or url.startswith('https:') \
|
||||
or os.path.isfile(url):
|
||||
audios += get_urls(get_tree(url))
|
||||
else:
|
||||
logging.info('unsupported url `%s`', url)
|
||||
audios = [audio for audio in audios if
|
||||
(args.max_len == 0 or
|
||||
audio.duration <= args.max_len) and
|
||||
(args.min_len == 0 or
|
||||
audio.duration >= args.min_len) and
|
||||
(args.min_age.total_seconds() == 0 or
|
||||
audio.age >= args.min_age) and
|
||||
(args.max_age.total_seconds() == 0 or
|
||||
audio.age <= args.max_age)
|
||||
]
|
||||
else: # group
|
||||
if os.path.isdir(url):
|
||||
audiodir = get_audio_from_dir(url)
|
||||
agroups = []
|
||||
for a in audiodir:
|
||||
ag = AudioGroup(os.path.basename(a.url))
|
||||
ag.append(a)
|
||||
audios.append(ag)
|
||||
else:
|
||||
logging.info('unsupported url `%s`', url)
|
||||
agroups.append(ag)
|
||||
elif url.startswith('http:') or url.startswith('https:') \
|
||||
or os.path.isfile(url):
|
||||
groups = get_grouped_urls(get_tree(url))
|
||||
agroups = groups.values()
|
||||
else:
|
||||
logging.info('unsupported url `%s`', url)
|
||||
audios += [g for g in agroups
|
||||
if
|
||||
(args.max_len == 0 or
|
||||
g.duration <= args.max_len) and
|
||||
(args.min_len == 0 or
|
||||
g.duration >= args.max_len) and
|
||||
(args.min_age.total_seconds() == 0 or
|
||||
g.age >= args.min_age) and
|
||||
(args.max_age.total_seconds() == 0 or
|
||||
g.age <= args.max_age)
|
||||
]
|
||||
|
||||
# sort
|
||||
if args.sort_by == 'random':
|
||||
|
|
Loading…
Reference in a new issue