Ignore missing thumbnail
This commit is contained in:
parent
ea9653a5be
commit
07280587a9
5
app.py
5
app.py
|
@ -29,6 +29,7 @@ def proxy(video_id):
|
||||||
|
|
||||||
soup = BeautifulSoup(r.text, "html.parser")
|
soup = BeautifulSoup(r.text, "html.parser")
|
||||||
thumbnail_url = None
|
thumbnail_url = None
|
||||||
|
try:
|
||||||
if soup.find("meta", {"name": "server-response"}):
|
if soup.find("meta", {"name": "server-response"}):
|
||||||
params = json.loads(soup.find("meta", {"name": "server-response"})["content"])["data"]["response"] # type: ignore
|
params = json.loads(soup.find("meta", {"name": "server-response"})["content"])["data"]["response"] # type: ignore
|
||||||
thumbnail_url = ( # Use highest quality thumbnail available
|
thumbnail_url = ( # Use highest quality thumbnail available
|
||||||
|
@ -38,9 +39,11 @@ def proxy(video_id):
|
||||||
or params["video"]["thumbnail"]["middleUrl"]
|
or params["video"]["thumbnail"]["middleUrl"]
|
||||||
or params["video"]["thumbnail"]["url"]
|
or params["video"]["thumbnail"]["url"]
|
||||||
)
|
)
|
||||||
|
except (KeyError, json.JSONDecodeError):
|
||||||
|
pass
|
||||||
og_tags = soup.find_all("meta", property=lambda x: x) # type: ignore
|
og_tags = soup.find_all("meta", property=lambda x: x) # type: ignore
|
||||||
for tag in og_tags:
|
for tag in og_tags:
|
||||||
if tag.get("property") == "og:image":
|
if tag.get("property") == "og:image" and thumbnail_url:
|
||||||
tag["content"] = thumbnail_url
|
tag["content"] = thumbnail_url
|
||||||
og_tags_str = "\n".join(str(tag) for tag in og_tags)
|
og_tags_str = "\n".join(str(tag) for tag in og_tags)
|
||||||
html_response = f"""
|
html_response = f"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user