replace [] with .get()

This commit is contained in:
voidptr_t 2024-08-04 19:17:35 +03:00
parent a85e77a058
commit 7f02e044b7

View File

@ -21,17 +21,17 @@ def _real_extract(self, url):
api_url = f"https://api.g1.plvideo.ru/v1/videos/{video_id}?Aud=18" api_url = f"https://api.g1.plvideo.ru/v1/videos/{video_id}?Aud=18"
result = self._download_json(api_url, video_id, "Downloading video JSON") result = self._download_json(api_url, video_id, "Downloading video JSON")
assert result["code"] == 200, "Failed to download video JSON" assert result.get("code") == 200, "Failed to download video JSON"
item = result["item"] item = result.get("item")
assert item is not None, "Bad API response" assert item is not None, "Bad API response"
thumbnail = item["cover"]["paths"]["original"]["src"] thumbnail = item.get("cover").get("paths").get("original").get("src")
formats = [] formats = []
for key, value in item["profiles"].items(): for key, value in item.get("profiles").items():
hlsurl = value["hls"] hlsurl = value.get("hls")
fmt = { fmt = {
'url': hlsurl, 'url': hlsurl,
'ext': 'mp4', 'ext': 'mp4',
@ -46,7 +46,7 @@ def _real_extract(self, url):
return { return {
'id': video_id, 'id': video_id,
'title': item["title"], 'title': item.get("title"),
'formats': formats, 'formats': formats,
} }