mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 20:00:15 +00:00
more valueerrors in url extraction
This commit is contained in:
parent
bce1022677
commit
164ee5c523
@ -70,6 +70,8 @@ class UrlListParser:
|
|||||||
# is not a url
|
# is not a url
|
||||||
id_type = self.find_valid_id(url)
|
id_type = self.find_valid_id(url)
|
||||||
youtube_id = url
|
youtube_id = url
|
||||||
|
elif "youtube.com" not in url:
|
||||||
|
raise ValueError(f"{url} is not a youtube link")
|
||||||
elif parsed.path:
|
elif parsed.path:
|
||||||
# is a url
|
# is a url
|
||||||
youtube_id, id_type = self.detect_from_url(parsed)
|
youtube_id, id_type = self.detect_from_url(parsed)
|
||||||
@ -86,6 +88,7 @@ class UrlListParser:
|
|||||||
if parsed.netloc == "youtu.be":
|
if parsed.netloc == "youtu.be":
|
||||||
# shortened
|
# shortened
|
||||||
youtube_id = parsed.path.strip("/")
|
youtube_id = parsed.path.strip("/")
|
||||||
|
_ = self.find_valid_id(youtube_id)
|
||||||
return youtube_id, "video"
|
return youtube_id, "video"
|
||||||
|
|
||||||
if parsed.query:
|
if parsed.query:
|
||||||
@ -93,6 +96,7 @@ class UrlListParser:
|
|||||||
query_parsed = parse_qs(parsed.query)
|
query_parsed = parse_qs(parsed.query)
|
||||||
if "v" in query_parsed.keys():
|
if "v" in query_parsed.keys():
|
||||||
youtube_id = query_parsed["v"][0]
|
youtube_id = query_parsed["v"][0]
|
||||||
|
_ = self.find_valid_id(youtube_id)
|
||||||
return youtube_id, "video"
|
return youtube_id, "video"
|
||||||
|
|
||||||
if "list" in query_parsed.keys():
|
if "list" in query_parsed.keys():
|
||||||
@ -102,6 +106,7 @@ class UrlListParser:
|
|||||||
if parsed.path.startswith("/channel/"):
|
if parsed.path.startswith("/channel/"):
|
||||||
# channel id in url
|
# channel id in url
|
||||||
youtube_id = parsed.path.split("/")[2]
|
youtube_id = parsed.path.split("/")[2]
|
||||||
|
_ = self.find_valid_id(youtube_id)
|
||||||
return youtube_id, "channel"
|
return youtube_id, "channel"
|
||||||
|
|
||||||
# dedect channel with yt_dlp
|
# dedect channel with yt_dlp
|
||||||
@ -135,7 +140,12 @@ class UrlListParser:
|
|||||||
"playlistend": 0,
|
"playlistend": 0,
|
||||||
}
|
}
|
||||||
url_info = youtube_dl.YoutubeDL(obs).extract_info(url, download=False)
|
url_info = youtube_dl.YoutubeDL(obs).extract_info(url, download=False)
|
||||||
|
try:
|
||||||
channel_id = url_info["channel_id"]
|
channel_id = url_info["channel_id"]
|
||||||
|
except KeyError as error:
|
||||||
|
print(f"failed to extract channel id from {url}")
|
||||||
|
raise ValueError from error
|
||||||
|
|
||||||
return channel_id
|
return channel_id
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user