@@ -167,9 +167,7 @@ def translate(self, language_code: str) -> "Transcript":
167
167
return Transcript (
168
168
self ._http_client ,
169
169
self .video_id ,
170
- "{url}&tlang={language_code}" .format (
171
- url = self ._url , language_code = language_code
172
- ),
170
+ "{url}&tlang={language_code}" .format (url = self ._url , language_code = language_code ),
173
171
self ._translation_languages_dict [language_code ],
174
172
language_code ,
175
173
True ,
@@ -204,9 +202,7 @@ def __init__(
204
202
self ._translation_languages = translation_languages
205
203
206
204
@staticmethod
207
- def build (
208
- http_client : Session , video_id : str , captions_json : Dict
209
- ) -> "TranscriptList" :
205
+ def build (http_client : Session , video_id : str , captions_json : Dict ) -> "TranscriptList" :
210
206
"""
211
207
Factory method for TranscriptList.
212
208
@@ -282,9 +278,7 @@ def find_generated_transcript(self, language_codes: Iterable[str]) -> Transcript
282
278
"""
283
279
return self ._find_transcript (language_codes , [self ._generated_transcripts ])
284
280
285
- def find_manually_created_transcript (
286
- self , language_codes : Iterable [str ]
287
- ) -> Transcript :
281
+ def find_manually_created_transcript (self , language_codes : Iterable [str ]) -> Transcript :
288
282
"""
289
283
Finds a manually created transcript for a given language code.
290
284
@@ -293,9 +287,7 @@ def find_manually_created_transcript(
293
287
it fails to do so.
294
288
:return: the found Transcript
295
289
"""
296
- return self ._find_transcript (
297
- language_codes , [self ._manually_created_transcripts ]
298
- )
290
+ return self ._find_transcript (language_codes , [self ._manually_created_transcripts ])
299
291
300
292
def _find_transcript (
301
293
self ,
@@ -321,8 +313,7 @@ def __str__(self) -> str:
321
313
).format (
322
314
video_id = self .video_id ,
323
315
available_manually_created_transcript_languages = self ._get_language_description (
324
- str (transcript )
325
- for transcript in self ._manually_created_transcripts .values ()
316
+ str (transcript ) for transcript in self ._manually_created_transcripts .values ()
326
317
),
327
318
available_generated_transcripts = self ._get_language_description (
328
319
str (transcript ) for transcript in self ._generated_transcripts .values ()
@@ -338,8 +329,7 @@ def __str__(self) -> str:
338
329
339
330
def _get_language_description (self , transcript_strings : Iterable [str ]) -> str :
340
331
description = "\n " .join (
341
- " - {transcript}" .format (transcript = transcript )
342
- for transcript in transcript_strings
332
+ " - {transcript}" .format (transcript = transcript ) for transcript in transcript_strings
343
333
)
344
334
return description if description else "None"
345
335
@@ -363,11 +353,7 @@ def _fetch_captions_json(self, video_id: str, try_number: int = 0) -> Dict:
363
353
innertube_data = self ._fetch_innertube_data (video_id , api_key )
364
354
return self ._extract_captions_json (innertube_data , video_id )
365
355
except RequestBlocked as exception :
366
- retries = (
367
- 0
368
- if self ._proxy_config is None
369
- else self ._proxy_config .retries_when_blocked
370
- )
356
+ retries = 0 if self ._proxy_config is None else self ._proxy_config .retries_when_blocked
371
357
if try_number + 1 < retries :
372
358
return self ._fetch_captions_json (video_id , try_number = try_number + 1 )
373
359
raise exception .with_proxy_config (self ._proxy_config )
@@ -384,20 +370,15 @@ def _extract_innertube_api_key(self, html: str, video_id: str) -> str:
384
370
def _extract_captions_json (self , innertube_data : Dict , video_id : str ) -> Dict :
385
371
self ._assert_playability (innertube_data .get ("playabilityStatus" ), video_id )
386
372
387
- captions_json = innertube_data .get ("captions" , {}).get (
388
- "playerCaptionsTracklistRenderer"
389
- )
373
+ captions_json = innertube_data .get ("captions" , {}).get ("playerCaptionsTracklistRenderer" )
390
374
if captions_json is None or "captionTracks" not in captions_json :
391
375
raise TranscriptsDisabled (video_id )
392
376
393
377
return captions_json
394
378
395
379
def _assert_playability (self , playability_status_data : Dict , video_id : str ) -> None :
396
380
playability_status = playability_status_data .get ("status" )
397
- if (
398
- playability_status != _PlayabilityStatus .OK .value
399
- and playability_status is not None
400
- ):
381
+ if playability_status != _PlayabilityStatus .OK .value and playability_status is not None :
401
382
reason = playability_status_data .get ("reason" )
402
383
if playability_status == _PlayabilityStatus .LOGIN_REQUIRED .value :
403
384
if reason == _PlayabilityFailedReason .BOT_DETECTED .value :
@@ -417,17 +398,13 @@ def _assert_playability(self, playability_status_data: Dict, video_id: str) -> N
417
398
.get ("subreason" , {})
418
399
.get ("runs" , [])
419
400
)
420
- raise VideoUnplayable (
421
- video_id , reason , [run .get ("text" , "" ) for run in subreasons ]
422
- )
401
+ raise VideoUnplayable (video_id , reason , [run .get ("text" , "" ) for run in subreasons ])
423
402
424
403
def _create_consent_cookie (self , html : str , video_id : str ) -> None :
425
404
match = re .search ('name="v" value="(.*?)"' , html )
426
405
if match is None :
427
406
raise FailedToCreateConsentCookie (video_id )
428
- self ._http_client .cookies .set (
429
- "CONSENT" , "YES+" + match .group (1 ), domain = ".youtube.com"
430
- )
407
+ self ._http_client .cookies .set ("CONSENT" , "YES+" + match .group (1 ), domain = ".youtube.com" )
431
408
432
409
def _fetch_video_html (self , video_id : str ) -> str :
433
410
html = self ._fetch_html (video_id )
0 commit comments