
    nzh)                         S SK JrJr  S SKrS SKJr  S SKJr  S SK7  S r	 " S S\\5      r
 " S	 S
\
5      r " S S\5      r " S S\5      rg)    )ListUnionN)ComponentHandler)RequestHandler)*c                    ^  U 4S jnU$ )Nc                 >   > U R                   [        T5      ;   d   eU $ N)__name__dir)methodinterface_classs    ]/home/james-whalen/.local/lib/python3.13/site-packages/youtubesearchpython/legacy/__init__.py	overrideroverrides.<locals>.overrider	   s    #o"6676     )r   r   s   ` r   	overridesr      s     r   c            	           \ rS rSrSr\" \5      SS\S\S\4S jj5       r	\" \5      S\S\4S j5       r
\" \5      S\S\4S	 j5       rS
\S\\   S\\\\4   4S jrSrg)LegacyComponentHandler   r   Nelement
shelfTitlereturnc                 2   U[            nU R                  US/5      nSn/ nU R                  USS/5       H+  nUR                  5       (       d  M  US-  [        U5      -   nM-     / SQnU H   n	UR	                  SU-   S-   U	-   S	-   5        M"     U R
                  US
U-   U R                  U/ SQ5      U R                  U/ SQ5      U R                  USS/5      UUU R                  U/ SQ5      U R                  USS/5      S.
n
U =R
                  S-  sl        U
$ )NvideoIdr   viewCountText
simpleText
   default	hqdefault	mqdefault	sddefaultmaxresdefaulthttps://img.youtube.com/vi//.jpgz https://www.youtube.com/watch?v=)titlerunsr   text)	ownerTextr*   r   r+   
lengthText)r,   r*   r   navigationEndpointbrowseEndpointbrowseIdpublishedTimeText)
indexidlinkr)   channeldurationviews
thumbnailschanneIdpublishTime   )videoElementKey!_LegacyComponentHandler__getValue	isnumericintappendr2   )selfr   r   videor   	viewCountr8   	charactermodesmode	components              r   _getVideoComponent)LegacyComponentHandler._getVideoComponent   s.   (//%)5	
,0OPI""$$%NS^;	 Q TD;gEKdRU[[\  /3jj.5.PSZ.Z.2ooeEa.b.2ooeEe.f.2ooelT`Ea.b.7.8.2ooe  FR  /S.2ooeFY[gEh.i
	 	

a
r   c                    U[            nU R                  US/5      nU R                  U/ SQ5      n/ n/ SQnU H   nUR                  SU-   S-   U-   S-   5        M"     U R                  USU-   U R                  USS	/5      UU R                  US
/5      U R                  U/ SQ5      S.nU =R                  S-  sl        U$ )N
playlistId)r.   watchEndpointr   r    r&   r'   r(   z&https://www.youtube.com/playlist?list=r)   r   
videoCount)shortBylineTextr*   r   r+   )r2   r3   r4   r)   r8   countr5   r;   )playlistElementKeyr=   r@   r2   )	rA   r   playlistrK   thumbnailVideoIdr8   rE   rF   rG   s	            r   _getPlaylistComponent,LegacyComponentHandler._getPlaylistComponent-   s    -.__X~>
??85gh
SD;>NNQTTW[[^dde  /3jj.8.VYc.c.2oohR^H_.`.8.2ooh.W.2oohHn.o
	 	

a
r   c                 f    U[            nU R                  USS/5      U R                  U/ SQ5      S.$ )Nr)   r   )contentverticalListRendereritems)r)   elements)shelfElementKeyr=   )rA   r   shelfs      r   _getShelfComponent)LegacyComponentHandler._getShelfComponentB   s8    (.2ooeg|E\.].2ooeEq.r
 	
r   rG   pathc                     UnU H_  n[        U5      [        L a  XCR                  5       ;   a  X4   nM.  Sn  U$ [        U5      [        L d  MG  [	        U5      S:w  a  X4   nM\  Sn  U$    U$ )NLIVEr   )typestrkeysr?   len)rA   rG   r^   valuekeys        r   
__getValue!LegacyComponentHandler.__getValueJ   ss    CCyC**,&!JE"E  cc!u:?!JE"E  r   r   r
   )r   
__module____qualname____firstlineno__r2   r   r   dictrb   rH   rS   r\   r   r   r?   r=   __static_attributes__r   r   r   r   r      s    E $ C 4  !4  T d  !(  
$ 
4 
 !
D S	 eCdN>S r   r   c                   B    \ rS rSrSr/ r/ rS rS\\	\
\S4   4S jrSrg)LegacySearchInternal[   Fc                 h    X l         Xl        X0l        X@l        XPl        X`l        S U l        S U l        g r
   )pagequeryrF   limitlanguageregioncontinuationKeytimeout)rA   keywordoffsetrF   max_resultsru   rv   s          r   __init__LegacySearchInternal.__init__`   s/    	
	 
 #r   r   Nc                    U R                   (       d  [        U R                  5      S:X  a  gU R                  S:X  a  SU R                  0$ U R                  S:X  a!  [        R
                  " SU R                  0SS9$ U R                  S:X  aT  / nU R                   H@  n/ nUR                  5        H  nUR                  X$   5        M     UR                  U5        MB     U$ g)	zReturns the search result.

Returns:
    Union[str, dict, list, None]: Returns JSON, list or dictionary & None in case of any exception.
r   Nrl   search_resultjson   )indentlist)	exceptionrd   resultComponentsrF   r   dumpsrc   r@   )rA   resultrG   listComponentrf   s        r   r   LegacySearchInternal.resultj   s     >>S!6!671<yyF"')>)>??f$zz?D4I4I"JUVWWf$!%!6!6I$&M(~~/%,,Y^<  0MM-0	 "7
  %r   )rw   ru   rt   rF   rr   rs   rv   rx   )r   ri   rj   rk   r   r   responseSourcer|   r   rb   rl   r   r   rm   r   r   r   ro   ro   [   s1    INc4t34 r   ro   c                   :   ^  \ rS rSrSrSU 4S jjrSS jrSrU =r$ )SearchVideos   u$  
DEPRECATED
----------
Use `VideosSearch` instead.

Searches for playlists in YouTube.

Args:
    keyword (str): Sets the search query.
    offset (int, optional): Sets the search result page number. Defaults to 1.
    mode (str, optional): Sets the result type, can be 'json', 'dict' or 'list'. Defaults to 'json'. 
    max_results (int, optional): Sets limit to the number of results. Defaults to 20.
    language (str, optional): Sets the result language. Defaults to 'en-US'.
    region (str, optional): Sets the result region. Defaults to 'US'.

Examples:
    Calling `result` method gives the search result.

    >>> search = SearchPlaylists('Harry Styles', max_results = 1)
    >>> print(search.result())
    {
        "search_result": [
            {
                "index": 0,
                "id": "PLj-vAPBrjcxoBfEk3q2Jp-naXRFpekySW",
                "link": "https://www.youtube.com/playlist?list=PLj-vAPBrjcxoBfEk3q2Jp-naXRFpekySW",
                "title": "Harry Styles - Harry Styles Full Album videos with lyrics",
                "thumbnails": [
                    "https://img.youtube.com/vi/Y9yOG_dJwFg/default.jpg",
                    "https://img.youtube.com/vi/Y9yOG_dJwFg/hqdefault.jpg",
                    "https://img.youtube.com/vi/Y9yOG_dJwFg/mqdefault.jpg",
                    "https://img.youtube.com/vi/Y9yOG_dJwFg/sddefault.jpg",
                    "https://img.youtube.com/vi/Y9yOG_dJwFg/maxresdefault.jpg"
                ],
                "count": "10",
                "channel": "Jana Holúbková"
            }
        ]
    }
c                    > [         TU ]  XX4XV5        SU l        U R                  5         U R	                  5         U R                  5         g )NzEgIQAQ%3D%3D)superr|   searchPreferences_makeRequest_parseSource_SearchVideos__makeComponentsrA   ry   rz   rF   r{   ru   rv   	__class__s          r   r|   SearchVideos.__init__   @    $XN!/r   c                    / U l         U R                   H  n[        UR                  5       ;   a*  U R                   R	                  U R                  U5      5        [        UR                  5       ;   aE  U R                  U5      S    H-  nU R                   R	                  U R                  U5      5        M/     [        U R                   5      U R                  :  d  M    g    g )NrY   )
r   r   r<   rc   r@   rH   rZ   r\   rd   rt   )rA   r   shelfElements      r   __makeComponentsSearchVideos.__makeComponents   s     "**G',,.0%%,,T-D-DW-MN',,.0$($;$;G$DZ$PL))001H1H1VW %Q4(()TZZ7 +r   r   r   r;   r      enUSr   N)	r   ri   rj   rk   __doc__r|   r   rm   __classcell__r   s   @r   r   r      s    'P 	 	r   r   c                   :   ^  \ rS rSrSrSU 4S jjrSS jrSrU =r$ )SearchPlaylists   aw  
DEPRECATED
----------
Use `PlaylistsSearch` instead.

Searches for playlists in YouTube.

Args:
    keyword (str): Sets the search query.
    offset (int, optional): Sets the search result page number. Defaults to 1.
    mode (str, optional): Sets the result type, can be 'json', 'dict' or 'list'. Defaults to 'json'. 
    max_results (int, optional): Sets limit to the number of results. Defaults to 20.
    language (str, optional): Sets the result language. Defaults to 'en-US'.
    region (str, optional): Sets the result region. Defaults to 'US'.

Examples:
    Calling `result` method gives the search result.

    >>> search = SearchVideos('Watermelon Sugar', max_results = 1)
    >>> print(search.result())
    {
        "search_result": [
            {
                "index": 0,
                "id": "E07s5ZYygMg",
                "link": "https://www.youtube.com/watch?v=E07s5ZYygMg",
                "title": "Harry Styles - Watermelon Sugar (Official Video)",
                "channel": "Harry Styles",
                "duration": "3:09",
                "views": 162235006,
                "thumbnails": [
                    "https://img.youtube.com/vi/E07s5ZYygMg/default.jpg",
                    "https://img.youtube.com/vi/E07s5ZYygMg/hqdefault.jpg",
                    "https://img.youtube.com/vi/E07s5ZYygMg/mqdefault.jpg",
                    "https://img.youtube.com/vi/E07s5ZYygMg/sddefault.jpg",
                    "https://img.youtube.com/vi/E07s5ZYygMg/maxresdefault.jpg"
                ],
                "channeId": "UCZFWPqqPkFlNwIxcpsLOwew",
                "publishTime": "6 months ago"
            }
        ]
    }
c                    > [         TU ]  XX4XV5        SU l        U R                  5         U R	                  5         U R                  5         g )NzEgIQAw%3D%3D)r   r|   r   r   r    _SearchPlaylists__makeComponentsr   s          r   r|   SearchPlaylists.__init__   r   r   c                    / U l         U R                   Hj  n[        UR                  5       ;   a*  U R                   R	                  U R                  U5      5        [        U R                   5      U R                  :  d  Mj    g    g r
   )r   r   rP   rc   r@   rS   rd   rt   )rA   r   s     r   r    SearchPlaylists.__makeComponents   sa     "**G!W\\^3%%,,T-G-G-PQ4(()TZZ7	 +r   r   r   r   )	r   ri   rj   rk   r   r|   r   rm   r   r   s   @r   r   r      s    *V  r   r   )typingr   r   r   -youtubesearchpython.handlers.componenthandlerr   +youtubesearchpython.handlers.requesthandlerr   "youtubesearchpython.core.constantsr   r   ro   r   r   r   r   r   <module>r      sT      J F 0J^-= JX#1 #L9' 9v9* 9r   