Merge pull request #243 from jdepoix/bugfix/no-translation-languages-provided

Added condition to initialize empty translation language list when translationLanugage key is missing
This commit is contained in:
Jonas Depoix 2023-12-27 13:04:22 +01:00 committed by GitHub
commit dd75803635
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 917 additions and 1 deletions

View File

@ -134,7 +134,7 @@ class TranscriptList(object):
{
'language': translation_language['languageName']['simpleText'],
'language_code': translation_language['languageCode'],
} for translation_language in captions_json['translationLanguages']
} for translation_language in captions_json.get('translationLanguages', [])
]
manually_created_transcripts = {}

File diff suppressed because one or more lines are too long

View File

@ -108,6 +108,19 @@ class TestYouTubeTranscriptApi(TestCase):
with self.assertRaises(InvalidVideoId):
YouTubeTranscriptApi.list_transcripts('https://www.youtube.com/watch?v=GJLlxj_dtq8')
def test_list_transcripts__no_translation_languages_provided(self):
httpretty.register_uri(
httpretty.GET,
'https://www.youtube.com/watch',
body=load_asset('youtube_no_translation_languages.html.static')
)
transcript_list = YouTubeTranscriptApi.list_transcripts('GJLlxj_dtq8')
for transcript in transcript_list:
self.assertEqual(len(transcript.translation_languages), 0)
def test_translate_transcript(self):
transcript = YouTubeTranscriptApi.list_transcripts('GJLlxj_dtq8').find_transcript(['en'])