mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 13:19:58 -05:00
25 lines
691 B
Python
25 lines
691 B
Python
|
|
formatters = {
|
||
|
|
'youtube.com': lambda i: f'https://youtube.com/watch?v={i["url"]}',
|
||
|
|
'www.youtube.com': lambda i: f'https://youtube.com/watch?v={i["url"]}',
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def video_url_resolver(domain: str, entry: dict) -> str:
|
||
|
|
"""
|
||
|
|
Guess the full URL of a Youtube-DL entry.
|
||
|
|
"""
|
||
|
|
if 'webpage_url' in entry:
|
||
|
|
return entry['webpage_url']
|
||
|
|
|
||
|
|
if entry.get('url', '').startswith('https://'):
|
||
|
|
return entry['url']
|
||
|
|
if entry.get('url', '').startswith('http://'):
|
||
|
|
return entry['url']
|
||
|
|
|
||
|
|
try:
|
||
|
|
formatter = formatters[domain]
|
||
|
|
return formatter(entry)
|
||
|
|
except KeyError:
|
||
|
|
# Unable to resolve, try the URL as is.
|
||
|
|
return entry['url']
|