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:
commit
dd75803635
|
@ -134,7 +134,7 @@ class TranscriptList(object):
|
||||||
{
|
{
|
||||||
'language': translation_language['languageName']['simpleText'],
|
'language': translation_language['languageName']['simpleText'],
|
||||||
'language_code': translation_language['languageCode'],
|
'language_code': translation_language['languageCode'],
|
||||||
} for translation_language in captions_json['translationLanguages']
|
} for translation_language in captions_json.get('translationLanguages', [])
|
||||||
]
|
]
|
||||||
|
|
||||||
manually_created_transcripts = {}
|
manually_created_transcripts = {}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -108,6 +108,19 @@ class TestYouTubeTranscriptApi(TestCase):
|
||||||
with self.assertRaises(InvalidVideoId):
|
with self.assertRaises(InvalidVideoId):
|
||||||
YouTubeTranscriptApi.list_transcripts('https://www.youtube.com/watch?v=GJLlxj_dtq8')
|
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):
|
def test_translate_transcript(self):
|
||||||
transcript = YouTubeTranscriptApi.list_transcripts('GJLlxj_dtq8').find_transcript(['en'])
|
transcript = YouTubeTranscriptApi.list_transcripts('GJLlxj_dtq8').find_transcript(['en'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue