diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-12-14 14:42:39 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-12-14 14:42:39 -0800 |
commit | a04aa63efee5813c6083dcdb3defcbcf32ce88f4 (patch) | |
tree | 1326a50aee620bc7fbbac01bb5e8373ec5aa2b0f | |
parent | 8c16062ea823532a191f06284a6b850c5d20e810 (diff) | |
download | yt-local-a04aa63efee5813c6083dcdb3defcbcf32ce88f4.tar.lz yt-local-a04aa63efee5813c6083dcdb3defcbcf32ce88f4.tar.xz yt-local-a04aa63efee5813c6083dcdb3defcbcf32ce88f4.zip |
Extraction: Fix subtitles error when video has no automatic captions but has foreign language captions
-rw-r--r-- | youtube/watch.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/youtube/watch.py b/youtube/watch.py index 4575c1e..77a4b45 100644 --- a/youtube/watch.py +++ b/youtube/watch.py @@ -59,12 +59,16 @@ def make_caption_src(info, lang, auto=False, trans_lang=None): def lang_in(lang, sequence): '''Tests if the language is in sequence, with e.g. en and en-US considered the same''' + if lang is None: + return False lang = lang[0:2] return lang in (l[0:2] for l in sequence) def lang_eq(lang1, lang2): '''Tests if two iso 639-1 codes are equal, with en and en-US considered the same. Just because the codes are equal does not mean the dialects are mutually intelligible, but this will have to do for now without a complex language model''' + if lang1 is None or lang2 is None: + return False return lang1[0:2] == lang2[0:2] def equiv_lang_in(lang, sequence): @@ -116,7 +120,7 @@ def get_subtitle_sources(info): # foreign_langs (Manual) -> pref_lang for lang in info['manual_caption_languages']: - if not lang_eq(lang, native_video_lang): + if not lang_eq(lang, native_video_lang) and not lang_eq(lang, pref_lang): sources.append(make_caption_src(info, lang, trans_lang=pref_lang)) # native_video_lang (Manual) -> pref_lang |