Improve url parsing (add support for youtu.be links)

This commit is contained in:
Edgar P. Burkhart 2024-04-10 15:12:25 +02:00
parent 89fb30443e
commit 3070dc301a
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

View file

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