From 5125bb9461e656f12c68553051d988e8297c333d Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sat, 10 Apr 2021 12:50:18 +1200 Subject: [PATCH] Don't fail if captions field is missing --- extractors/video.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/extractors/video.py b/extractors/video.py index c6f95a5..6f34a88 100644 --- a/extractors/video.py +++ b/extractors/video.py @@ -285,26 +285,27 @@ def get_more_stuff_from_file(id, result): f["qualityLabel"] = label f["second__order"] = format_order(f) - for track in player_response["captions"]["playerCaptionsTracklistRenderer"]["captionTracks"]: - # safely editing the track format by taking apart the url... - url = track["baseUrl"] - parts = urlparse(url) - qs = parse_qs(parts.query) - qs["format"] = ["vtt"] - qs = urlencode(qs, doseq=True) - # ...and putting it back together... - parts = parts._replace(query=qs) - url = parts.geturl() - # now make the caption object - label = combine_runs(track["name"]) - language_code = track["languageCode"] - subtitle_api_url = get_subtitle_api_url(id, label, language_code) - result["captions"].append({ - "label": label, - "languageCode": language_code, - "url": subtitle_api_url, - "second__remoteUrl": url - }) + if "captions" in player_response: + for track in player_response["captions"]["playerCaptionsTracklistRenderer"]["captionTracks"]: + # safely editing the track format by taking apart the url... + url = track["baseUrl"] + parts = urlparse(url) + qs = parse_qs(parts.query) + qs["format"] = ["vtt"] + qs = urlencode(qs, doseq=True) + # ...and putting it back together... + parts = parts._replace(query=qs) + url = parts.geturl() + # now make the caption object + label = combine_runs(track["name"]) + language_code = track["languageCode"] + subtitle_api_url = get_subtitle_api_url(id, label, language_code) + result["captions"].append({ + "label": label, + "languageCode": language_code, + "url": subtitle_api_url, + "second__remoteUrl": url + }) except Exception: print("messed up extracting recommendations.")