From 8287d1088ef0efcc2df08ec9547f7bfbdfa3aed4 Mon Sep 17 00:00:00 2001 From: Jonas Depoix Date: Mon, 30 Dec 2019 14:38:27 +0100 Subject: [PATCH] fixed bug where nontranslatable transcripts would throw an exception --- youtube_transcript_api/_transcripts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/youtube_transcript_api/_transcripts.py b/youtube_transcript_api/_transcripts.py index 95f4ead..19e9044 100644 --- a/youtube_transcript_api/_transcripts.py +++ b/youtube_transcript_api/_transcripts.py @@ -120,7 +120,7 @@ class TranscriptList(): caption['name']['simpleText'], caption['languageCode'], caption.get('kind', '') == 'asr', - translation_languages if caption['isTranslatable'] else [] + translation_languages if caption.get('isTranslatable', False) else [] ) return TranscriptList( @@ -295,7 +295,7 @@ class _TranscriptParser(): { 'text': re.sub(self.HTML_TAG_REGEX, '', unescape(xml_element.text)), 'start': float(xml_element.attrib['start']), - 'duration': float(xml_element.attrib['dur']), + 'duration': float(xml_element.attrib.get('dur', '0.0')), } for xml_element in ElementTree.fromstring(plain_data) if xml_element.text is not None