diff options
author | James Taylor <28744867+user234683@users.noreply.github.com> | 2022-03-23 00:34:39 -0700 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2022-03-30 00:37:43 +0800 |
commit | dcd4b0f0aeee19755d3d732695e94c51be54522c (patch) | |
tree | 8ead59d12131b7df2cc9ce1e9ca8dca8eba09611 /youtube/yt_data_extract | |
parent | e8cbc5074a7f25b3c513c9ce7f3a4a9797330d11 (diff) | |
download | yt-local-dcd4b0f0aeee19755d3d732695e94c51be54522c.tar.lz yt-local-dcd4b0f0aeee19755d3d732695e94c51be54522c.tar.xz yt-local-dcd4b0f0aeee19755d3d732695e94c51be54522c.zip |
Fix exception when _captions_base_url is not present
Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'youtube/yt_data_extract')
-rw-r--r-- | youtube/yt_data_extract/__init__.py | 2 | ||||
-rw-r--r-- | youtube/yt_data_extract/watch_extraction.py | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/youtube/yt_data_extract/__init__.py b/youtube/yt_data_extract/__init__.py index ad7bd03..9016810 100644 --- a/youtube/yt_data_extract/__init__.py +++ b/youtube/yt_data_extract/__init__.py @@ -10,4 +10,4 @@ from .watch_extraction import (extract_watch_info, get_caption_url, update_with_age_restricted_info, requires_decryption, extract_decryption_function, decrypt_signatures, _formats, update_format_with_type_info, extract_hls_formats, - extract_watch_info_from_html) + extract_watch_info_from_html, captions_available) diff --git a/youtube/yt_data_extract/watch_extraction.py b/youtube/yt_data_extract/watch_extraction.py index d90d9ad..31f6466 100644 --- a/youtube/yt_data_extract/watch_extraction.py +++ b/youtube/yt_data_extract/watch_extraction.py @@ -732,10 +732,15 @@ def extract_watch_info_from_html(watch_html): return extract_watch_info(fake_polymer_json) +def captions_available(info): + return bool(info['_captions_base_url']) + def get_caption_url(info, language, format, automatic=False, translation_language=None): '''Gets the url for captions with the given language and format. If automatic is True, get the automatic captions for that language. If translation_language is given, translate the captions from `language` to `translation_language`. If automatic is true and translation_language is given, the automatic captions will be translated.''' url = info['_captions_base_url'] + if not url: + return None url += '&lang=' + language url += '&fmt=' + format if automatic: |