Improve url parsing (add support for youtu.be links)
This commit is contained in:
parent
89fb30443e
commit
3070dc301a
1 changed files with 10 additions and 4 deletions
|
@ -11,6 +11,15 @@ def bl_path(bl, user):
|
||||||
return bl.joinpath(user).with_suffix(".txt")
|
return bl.joinpath(user).with_suffix(".txt")
|
||||||
|
|
||||||
|
|
||||||
|
def parse_musik(raw):
|
||||||
|
if "youtube.com" in raw:
|
||||||
|
return parse_qs(urlparse(raw).query).get("v", [None])[0]
|
||||||
|
elif "youtu.be" in raw:
|
||||||
|
return urlparse(raw).path[1:]
|
||||||
|
|
||||||
|
return raw
|
||||||
|
|
||||||
|
|
||||||
def generate_list(args):
|
def generate_list(args):
|
||||||
musik_list = []
|
musik_list = []
|
||||||
user_list = []
|
user_list = []
|
||||||
|
@ -27,10 +36,7 @@ def generate_list(args):
|
||||||
|
|
||||||
logger.debug("Lecture de la liste")
|
logger.debug("Lecture de la liste")
|
||||||
with q.open() as f:
|
with q.open() as f:
|
||||||
_raw_musiks = [
|
_raw_musiks = [parse_musik(_musik) for _musik in f.read().splitlines()]
|
||||||
parse_qs(urlparse(_musik).query).get("v", [None])[0] or _musik
|
|
||||||
for _musik in f.read().splitlines()
|
|
||||||
]
|
|
||||||
_musiks = list(set(filter(lambda _m: _m not in blacklist, _raw_musiks)))
|
_musiks = list(set(filter(lambda _m: _m not in blacklist, _raw_musiks)))
|
||||||
|
|
||||||
if len(_musiks) < args.number:
|
if len(_musiks) < args.number:
|
||||||
|
|
Loading…
Reference in a new issue