Merge pull request #137 from xenova/master

Raise `TranscriptsDisabled` if 'playerCaptionsTracklistRenderer' is not found (Fixes #136)
This commit is contained in:
jdepoix 2021-12-13 10:16:37 +01:00 committed by GitHub
commit 161be4a422
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 1 deletions

View File

@ -60,7 +60,9 @@ class TranscriptListFetcher(object):
captions_json = json.loads( captions_json = json.loads(
splitted_html[1].split(',"videoDetails')[0].replace('\n', '') splitted_html[1].split(',"videoDetails')[0].replace('\n', '')
)['playerCaptionsTracklistRenderer'] ).get('playerCaptionsTracklistRenderer')
if captions_json is None:
raise TranscriptsDisabled(video_id)
if 'captionTracks' not in captions_json: if 'captionTracks' not in captions_json:
raise NoTranscriptAvailable(video_id) raise NoTranscriptAvailable(video_id)

File diff suppressed because one or more lines are too long

View File

@ -205,6 +205,14 @@ class TestYouTubeTranscriptApi(TestCase):
with self.assertRaises(TranscriptsDisabled): with self.assertRaises(TranscriptsDisabled):
YouTubeTranscriptApi.get_transcript('dsMFmonKDD4') YouTubeTranscriptApi.get_transcript('dsMFmonKDD4')
httpretty.register_uri(
httpretty.GET,
'https://www.youtube.com/watch',
body=load_asset('youtube_transcripts_disabled2.html.static')
)
with self.assertRaises(TranscriptsDisabled):
YouTubeTranscriptApi.get_transcript('Fjg5lYqvzUs')
def test_get_transcript__exception_if_language_unavailable(self): def test_get_transcript__exception_if_language_unavailable(self):
with self.assertRaises(NoTranscriptFound): with self.assertRaises(NoTranscriptFound):
YouTubeTranscriptApi.get_transcript('GJLlxj_dtq8', languages=['cz']) YouTubeTranscriptApi.get_transcript('GJLlxj_dtq8', languages=['cz'])