
    nzhH	                     \    S SK JrJr  S SKJr  S SKrS SKrS SKJr  S SK	7   " S S\5      r
g)    )Requesturlopen)	urlencodeN)ComponentHandler)*c                   (    \ rS rSrSS jrSS jrSrg)RequestHandler	   Nc                 @   [         R                  " [        5      nU R                  US'   U R                  U R
                  S.US'   U R                  (       a  U R                  US'   U R                  (       a  U R                  US'   [        R                  " U5      R                  S5      n[        S[        S[        05      -   US	[        U5      [        S
.S9n [!        X0R"                  S9R%                  5       R'                  S5      U l        g!   [+        S5      e= f)z
Fixes #47 query)hlglclientparamscontinuationutf_8z+https://www.youtube.com/youtubei/v1/search?keyzapplication/json; charset=utf-8)zContent-TypezContent-Lengthz
User-Agent)dataheaders)timeoutzERROR: Could not make request.N)copydeepcopyrequestPayloadr   languageregionsearchPreferencescontinuationKeyjsondumpsencoder   r   	searchKeylen	userAgentr   r   readdecoderesponse	Exception)selfrequestBodyrequestBodyBytesrequests       e/home/james-whalen/.local/lib/python3.13/site-packages/youtubesearchpython/handlers/requesthandler.py_makeRequestRequestHandler._makeRequest
   s   mmN3#zzG--++!
H !!$($:$:K!*.*>*>K'::k299'B>yL B  $ A"%&6"7'

	>#G\\BGGIPPQXYDM	><==s   5D Dc                     U R                   (       d5  U R                  [        R                  " U R                  5      [
        5      nO4U R                  [        R                  " U R                  5      [        5      nU(       at  U Hm  n[        UR                  5       ;   a  U R                  U[        S/5      U l	        [        UR                  5       ;   d  MR  U R                  U[        5      U l         Mo     g U R                  [        R                  " U R                  5      [        5      U l	        U R                  U R                  S   [        5      U l         g !   [        S5      e= f)Ncontentsz(ERROR: Could not parse YouTube response.)r   	_getValuer   loadsr&   contentPathcontinuationContentPathitemSectionKeykeysresponseSourcecontinuationItemKeycontinuationKeyPathfallbackContentPathr'   )r(   responseContentelements      r,   _parseSourceRequestHandler._parseSource'   s    	H''"&..DMM1JK"X"&..DMM1JLc"d.G%7.2nnW~WaFb.c+*glln</3~~gGZ/[,	  / '+nnTZZ5NPc&d#'+~~d6I6I"6MOb'c$	HFGGs   CE E 7A!E E&)r   r&   r8   )returnN)__name__
__module____qualname____firstlineno__r-   r>   __static_attributes__     r,   r	   r	   	   s    >:HrG   r	   )urllib.requestr   r   urllib.parser   r   r   -youtubesearchpython.handlers.componenthandlerr   "youtubesearchpython.core.constantsr	   rF   rG   r,   <module>rL      s&    + "   J 0.H% .HrG   