66from youtubesearchpython .core .constants import *
77from youtubesearchpython .core .requests import RequestCore
88from youtubesearchpython .core .componenthandler import getValue , getVideoId
9+ from youtubesearchpython .core .exceptions import YouTubeRequestError
910
1011
1112
@@ -27,7 +28,7 @@ def extract_continuation_key(self, r):
2728 j = r .json ()
2829 panels = getValue (j , ["engagementPanels" ])
2930 if not panels :
30- raise Exception ("Failed to create first request - No engagementPanels is present." )
31+ raise YouTubeRequestError ("Failed to create first request - No engagementPanels is present." )
3132 key = ""
3233 for panel in panels :
3334 panel = panel ["engagementPanelSectionListRenderer" ]
@@ -44,12 +45,12 @@ def prepare_transcript_request(self):
4445 'key' : searchKey ,
4546 "prettyPrint" : "false"
4647 })
47-
48+ # clientVersion must be newer than in requestPayload
4849 self .data = {
4950 "context" : {
5051 "client" : {
5152 "clientName" : "WEB" ,
52- "clientVersion" : "2.20241210.01 .00" ,
53+ "clientVersion" : "2.20220318.00 .00" ,
5354 "newVisitorCookie" : True ,
5455 },
5556 "user" : {
@@ -65,6 +66,7 @@ def extract_transcript(self):
6566 segments = []
6667 languages = []
6768 if not transcripts :
69+ # No transcripts available
6870 self .result = {"segments" : segments , "languages" : languages }
6971 return
7072 for segment in transcripts :
@@ -111,14 +113,3 @@ def sync_create(self):
111113 self .prepare_transcript_request ()
112114 self .data = self .syncPostRequest ()
113115 self .extract_transcript ()
114-
115- def _safe_load_response (self , response ):
116- try :
117- if hasattr (response , "json" ):
118- return response .json ()
119- if hasattr (response , "text" ):
120- return json .loads (response .text )
121- if isinstance (response , (str , bytes )):
122- return json .loads (response )
123- except Exception :
124- return {}
0 commit comments