
    nzhC                     t    S SK r S SKJr  S SKJr  S SKJr  S SKJr  S SK	J
r
  S SK7  S SKr " S S	\\
\5      rg)
    N)Union)	urlencode)RequestCore)ComponentHandler)RequestHandler)*c                      ^  \ rS rSrSrSr/ rS\S\S\S\S\S\4U 4S	 jjr	S
 r
S rSS jrSS jr\R                  4S\S\\\4   4S jjrS\4S jrS\4S jrS\S\S\SS4S jrSrU =r$ )
SearchCore   NquerylimitlanguageregionsearchPreferencestimeoutc                 x   > [         TU ]  5         Xl        X l        X0l        X@l        XPl        X`l        S U l        g N)	super__init__r   r   r   r   r   r   continuationKey)selfr   r   r   r   r   r   	__class__s          Y/home/james-whalen/.local/lib/python3.13/site-packages/youtubesearchpython/core/search.pyr   SearchCore.__init__   s5    

 !2#    c                 D    U R                  5         U R                  5         g r   )_makeRequest_parseSourcer   s    r   sync_createSearchCore.sync_create   s    r   c                 L   [         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'   S[        S[        05      -   U l
        Xl        g)	z
Fixes #47 r   )hlglclientparamscontinuationz+https://www.youtube.com/youtubei/v1/search?keyN)copydeepcopyrequestPayloadr   r   r   r   r   r   	searchKeyurldata)r   requestBodys     r   _getRequestBodySearchCore._getRequestBody    s    mmN3#zzG--++!
H !!$($:$:K!*.*>*>K'E	9S
 I   	r   returnc                     U R                  5         U R                  5       n UR                  U l        g !   [	        S5      e= fNzERROR: Could not make request.)r0   syncPostRequesttextresponse	Exceptionr   requests     r   r   SearchCore._makeRequest1   s?    &&(	>#LLDM	><==s	   4 Ac                    #    U R                  5         U R                  5       I S h  vN n UR                  U l        g  N!   [	        S5      e= f7fr4   )r0   asyncPostRequestr6   r7   r8   r9   s     r   _makeAsyncRequestSearchCore._makeAsyncRequest9   sI     --//	>#LLDM 0	><==s$   $A>AA  A AAmodec                     U[         R                  :X  a!  [        R                  " SU R                  0SS9$ U[         R                  :X  a  SU R                  0$ g)zReturns the search result.

Args:
    mode (int, optional): Sets the type of result. Defaults to ResultMode.dict.

Returns:
    Union[str, dict]: Returns JSON or dictionary.
result   )indentN)
ResultModejsondumpsresultComponentsdict)r   r@   s     r   rB   SearchCore.resultA   sN     :??"::x)>)>?JJZ__$d3344 %r   c                     U R                   (       aO  SU l        SU l        / U l        U R	                  5         U R                  5         U R                  " U R                  6   gg)zGets the subsequent search result. Call result

Args:
    mode (int, optional): Sets the type of result. Defaults to ResultMode.dict.

Returns:
    Union[str, dict]: Returns True if getting more results was successful.
NTF)r   r7   responseSourcerH   r   r   _getComponents
searchModer   s    r   _nextSearchCore._nextO   sT      DM"&D$&D!1r   c                    #    S U l         S U l        / U l        U R                  5       I S h  vN   U R	                  5         U R
                  " U R                  6   SU R                  0$  N;7f)NrB   )r7   rL   rH   r>   r   rM   rN   r   s    r   
_nextAsyncSearchCore._nextAsyncc   sf     " "$$&&&T__-d++
 	
 	's   )A)A'<A)
findVideosfindChannelsfindPlaylistsc           
         / U l         U R                   GH  n[        UR                  5       ;   a1  U(       a*  U R                   R	                  U R                  U5      5        [        UR                  5       ;   a1  U(       a*  U R                   R	                  U R                  U5      5        [        UR                  5       ;   a1  U(       a*  U R                   R	                  U R                  U5      5        [        UR                  5       ;   a\  U(       aU  U R                  U5      S    H=  nU R                   R	                  U R                  XPR                  U5      S   S95        M?     [        UR                  5       ;   ad  U(       a]  U R                  U[        S/5      n [        UR                  5       ;   a,  U R                  U5      nU R                   R	                  U5        [        U R                   5      U R                  :  d  GM    g    g )Nelementstitle)
shelfTitlecontent)rH   rL   videoElementKeykeysappend_getVideoComponentchannelElementKey_getChannelComponentplaylistElementKey_getPlaylistComponentshelfElementKey_getShelfComponentrichItemKey	_getValuelenr   )r   rT   rU   rV   elementshelfElementrichItemElementvideoComponents           r   rM   SearchCore._getComponentsn   s    "**G',,.0Z%%,,T-D-DW-MN GLLN2|%%,,T-F-Fw-OP!W\\^3%%,,T-G-G-PQ',,.0Z$($;$;G$DZ$PL))00//I`I`ahIijqIr/su %Q glln,"&..;	:R"SB"o&:&:&<<%)%<%<_%MN))00@4(()TZZ7% +r   )r   r.   r   r   r   r   r7   rL   rH   r   r   r-   )r2   N)__name__
__module____qualname____firstlineno__r7   rL   rH   strintr   r    r0   r   r>   rE   rI   r   rB   boolrO   rR   rM   __static_attributes____classcell__)r   s   @r   r
   r
      s    HN$c $# $ $c $^a $lo $ ">> ", 53 5U395E 5t (	
$ 	
 T RV [_  r   r
   )r)   typingr   urllib.parser   !youtubesearchpython.core.requestsr   -youtubesearchpython.handlers.componenthandlerr   +youtubesearchpython.handlers.requesthandlerr   "youtubesearchpython.core.constantsrF   r
    r   r   <module>r~      s0      " 9 J F 0 un.> ur   