tabs -> spaces
This commit is contained in:
parent
63eb73afbf
commit
ab7ff50cc5
@ -3,51 +3,52 @@ import youtube_dl
|
|||||||
from youtube_dl.utils import DownloadError
|
from youtube_dl.utils import DownloadError
|
||||||
from . import nyasync
|
from . import nyasync
|
||||||
|
|
||||||
|
|
||||||
@nyasync.ify
|
@nyasync.ify
|
||||||
def title(url):
|
def title(url):
|
||||||
ydl = youtube_dl.YoutubeDL()
|
ydl = youtube_dl.YoutubeDL()
|
||||||
return ydl.extract_info(url, download=False).get('title')
|
return ydl.extract_info(url, download=False).get('title')
|
||||||
|
|
||||||
def filter_query_params(url, allowed=[]):
|
def filter_query_params(url, allowed=[]):
|
||||||
split_url = urlsplit(url)
|
split_url = urlsplit(url)
|
||||||
|
|
||||||
qs = parse_qs(split_url.query)
|
qs = parse_qs(split_url.query)
|
||||||
print(qs)
|
print(qs)
|
||||||
for key in list(qs.keys()):
|
for key in list(qs.keys()):
|
||||||
if key not in allowed:
|
if key not in allowed:
|
||||||
del qs[key]
|
del qs[key]
|
||||||
|
|
||||||
return urlunsplit((
|
return urlunsplit((
|
||||||
split_url.scheme,
|
split_url.scheme,
|
||||||
split_url.netloc,
|
split_url.netloc,
|
||||||
split_url.path,
|
split_url.path,
|
||||||
urlencode(qs, doseq=True),
|
urlencode(qs, doseq=True),
|
||||||
split_url.fragment,
|
split_url.fragment,
|
||||||
))
|
))
|
||||||
|
|
||||||
@nyasync.ify
|
@nyasync.ify
|
||||||
def get_youtube_dl_metadata(url, ydl = youtube_dl.YoutubeDL()):
|
def get_youtube_dl_metadata(url, ydl = youtube_dl.YoutubeDL()):
|
||||||
if urlsplit(url).scheme == "":
|
if urlsplit(url).scheme == "":
|
||||||
return None
|
return None
|
||||||
if urlsplit(url).netloc.lower() in ("www.youtube.com", "youtube.com", "youtu.be"):
|
if urlsplit(url).netloc.lower() in ("www.youtube.com", "youtube.com", "youtu.be"):
|
||||||
#Stop it from doing the whole playlist
|
#Stop it from doing the whole playlist
|
||||||
url = filter_query_params(url, allowed=["v"])
|
url = filter_query_params(url, allowed=["v"])
|
||||||
elif urlsplit(url).scheme == "ytdl":
|
elif urlsplit(url).scheme == "ytdl":
|
||||||
url = f"https://youtube.com/watch?v={urlsplit(url).netloc}"
|
url = f"https://youtube.com/watch?v={urlsplit(url).netloc}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = ydl.extract_info(url, download=False)
|
resp = ydl.extract_info(url, download=False)
|
||||||
except DownloadError:
|
except DownloadError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
#filter and return:
|
#filter and return:
|
||||||
return {k:v for k, v in resp.items() if k in
|
return {k:v for k, v in resp.items() if k in
|
||||||
("uploader", "title", "thumbnail", "description", "duration")}
|
("uploader", "title", "thumbnail", "description", "duration")}
|
||||||
|
|
||||||
async def get_metadata(url):
|
async def get_metadata(url):
|
||||||
data = await get_youtube_dl_metadata(url)
|
data = await get_youtube_dl_metadata(url)
|
||||||
if data is None:
|
if data is None:
|
||||||
# (TODO): local ID3 tags
|
# (TODO): local ID3 tags
|
||||||
return {"failed":True}
|
return {"failed":True}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
Loading…
Reference in New Issue
Block a user