1- import os
21import copy
32import json
43from typing import Union , List
2019 'context' : {
2120 'client' : {
2221 'clientName' : 'WEB' ,
23- 'clientVersion' : '2.20241210.01 .00' ,
22+ 'clientVersion' : '2.20210224.06 .00' ,
2423 'newVisitorCookie' : True
2524 },
2625 'user' : {
5958
6059
6160def _get_cleaned_url (video_link : str ) -> str :
61+ """
62+ Cleans the YouTube video link by removing any extra parameters,
63+ ensuring only the video ID is present.
64+ """
6265 parsed_url = urlparse (video_link )
6366 video_id = parse_qs (parsed_url .query ).get ("v" )
6467 if video_id :
@@ -75,18 +78,8 @@ def __init__(self, videoLink: str, componentMode: str, resultMode: int, timeout:
7578 self .videoLink = _get_cleaned_url (videoLink )
7679 self .enableHTML = enableHTML
7780 self .overridedClient = overridedClient
78-
79- proxy = os .environ .get ("YTS_PROXY" ) or os .environ .get ("HTTP_PROXY" ) or os .environ .get ("HTTPS_PROXY" )
80- if proxy :
81- self .proxies = {"http" : proxy , "https" : proxy }
82-
83- def _apply_token_and_headers (self ):
84- token = os .environ .get ("YTS_IDENTITY_TOKEN" )
85- if token :
86- if not hasattr (self , "headers" ) or self .headers is None :
87- self .headers = {}
88- self .headers ["x-youtube-identity-token" ] = token
89-
81+
82+ # We call this when we use only HTML
9083 def post_request_only_html_processing (self ):
9184 self .__getVideoComponent (self .componentMode )
9285 self .result = self .__videoComponent
@@ -104,7 +97,6 @@ def prepare_innertube_request(self):
10497 "videoId" : getVideoId (self .videoLink )
10598 })
10699 self .data = copy .deepcopy (CLIENTS [self .overridedClient ])
107- self ._apply_token_and_headers ()
108100
109101 async def async_create (self ):
110102 self .prepare_innertube_request ()
@@ -131,6 +123,7 @@ def sync_create(self):
131123 self .post_request_processing ()
132124 else :
133125 try :
126+ # Get full error response for debugging
134127 error_msg = response .text if hasattr (response , 'text' ) and response .text else 'No response text available'
135128 try :
136129 import json
@@ -157,7 +150,6 @@ def prepare_html_request(self):
157150 "videoId" : getVideoId (self .videoLink )
158151 })
159152 self .data = CLIENTS ["MWEB" ]
160- self ._apply_token_and_headers ()
161153
162154 def sync_html_create (self ):
163155 self .prepare_html_request ()
0 commit comments