
     iS                     "   d dl Z d dlZd dlZd dlmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZ ddlmZmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl&m(Z(  G d de          Z)dS )    N)DictAnyUnionList)Optional)ExponentialRetry)AudioSegment)
Recognizer	SignatureSearchParams   )
HTTPClient)	Converter
GeoService)
deprecated)
GenreMusic)HTTPClientInterface)RequestDevice)	ShazamUrl)ArtistQuery)DecodedMessage)CountryCode)ArtistQueryGenerator)get_songc                       e Zd ZdZ	 	 	 	 d3dededee         d	ef fd
Z	 	 	 d4dededee         de	ee
f         fdZ	 	 d5dedee         dee         de	ee
f         fdZ	 d6dedee         de	ee
f         fdZ	 	 	 d4dedededee         de	ee
f         f
dZ	 	 	 d4dededededee         de	ee
f         fdZ	 	 	 d7deeef         dededee         de	ee
f         f
dZ	 	 	 d4dedeeef         dededee         de	ee
f         fdZ	 	 	 d8dedededee         de	ee
f         f
d Z	 	 	 d9dedededee         de	ee
f         f
d!Z	 	 	 d9dedededee         de	ee
f         f
d"Z	 d6dedee         de	ee
f         fd#Z	 d6d$ee         dee         dee	ee
f                  fd%Z	 	 	 d9dedededee         fd&Z	 d6d'edee         fd(Z	 d6d)edee         de	ee
f         fd*Z ed+          	 d6d,eeej         e!e"e#f         dee         de	ee
f         fd-            Z$	 d6d.e%dee         de	ee
f         fd/Z&	 	 d5d,eee!e"f         dee         d0ee'         de	ee
f         fd1Z(	 d6d.e)dee         de	ee
f         fd2Z* xZ+S ):Shazamz{
    Is asynchronous framework for reverse engineered Shazam API written in Python 3.10+ with
    asyncio and aiohttp.
    en-USGBN
   languageendpoint_countryhttp_clientsegment_duration_secondsc                    t                                          |           t          |          | _        || _        || _        |p!t          t          ddh d                    | _        t          | j                  | _
        d S )Nr!   )r$      <   >             )attemptsmax_timeoutstatuses)retry_options)super__init__r
   core_recognizerr!   r"   r   r   r#   r   geo_service)selfr!   r"   r#   r$   	__class__s        T/root/.openclaw/workspace/.venvs/songid/lib/python3.11/site-packages/shazamio/api.pyr3   zShazam.__init__   s     	(+++)%= 
  
  
 ! 0& 
**222  +
 +
 +
 &d&677       r   limitoffsetproxyreturnc           
        K   | j                                          d{V }| j                            dt          j                            || j        | j        ||          | 	                                |           d{V S )a  
        Search top world tracks

            :param limit: Determines how many songs the maximum can be in the request.
                Example: If 5 is specified, the query will return no more than 5 songs.
            :param offset: A parameter that determines with which song to display the request.
                The default is 0. If you want to skip the first few songs, set this parameter to
                your own.
            :param proxy: Proxy server
            :return: dict tracks
        NGETplaylist_idr!   r"   r;   r<   headersr=   )
r5   get_topr#   requestr   TOP_TRACKS_PLAYLISTformatr!   r"   rD   )r6   r;   r<   r=   top_playlist_ids        r8   top_world_trackszShazam.top_world_tracks7   s      $ !% 0 8 8 : :::::::%--)00+!%!6 1   LLNN . 
 
 
 
 
 
 
 
 	
r9   	artist_idqueryc                   K   |r%t          |          }|                                }ni }| j                            dt          j                            | j        |          ||                                 |           d{V S )a"  
        Retrieving information from an artist profile

            :param artist_id: Artist number. Example (203347991)
            :param query: Foo
            https://www.shazam.com/artist/203347991/
            :param proxy: Proxy server
            :return: dict about artist
        )sourcer@   )r"   rK   paramsrD   r=   N)	r   rP   r#   rF   r   SEARCH_ARTIST_V2rH   r"   rD   )r6   rK   rL   r=   pgparams_dicts         r8   artist_aboutzShazam.artist_aboutW   s         	%U333B))++KKK%--&--!%!6# .   LLNN . 	
 	
 	
 	
 	
 	
 	
 	
 		
r9   track_idc                    K   | j                             dt          j                            | j        | j        |          |                                 |           d{V S )z
        Get track information

            :param track_id: Track number. Example: (549952578)
            https://www.shazam.com/track/549952578/
            :param proxy: Proxy server
            :return: dict about track
        r@   )r!   r"   rU   rC   N)r#   rF   r   ABOUT_TRACKrH   r!   r"   rD   r6   rU   r=   s      r8   track_aboutzShazam.track_aboutx   s       %--!((!%!6! )  
 LLNN . 	
 	
 	
 	
 	
 	
 	
 	
 		
r9   country_codec                 (  K   | j                             t          |                     d{V }| j                            dt
          j                            || j        | j	        |||          | 
                                |           d{V S )a  
        Get the best tracks by country code
        https://www.shazam.com/charts/discovery/netherlands

            :param country_code: ISO 3166-3 alpha-2 code. Example: RU,NL,UA
            :param limit: Determines how many songs the maximum can be in the request.
                Example: If 5 is specified, the query will return no more than 5 songs.
            :param offset: A parameter that determines with which song to display the request.
                The default is 0. If you want to skip the first few songs, set this parameter to
                your own.
            :param proxy: Proxy server
            :return: dict songs
        )countryNr@   rB   r!   r"   rZ   r;   r<   rC   )r5   get_country_playlistr   r#   rF   r   rG   rH   r!   r"   rD   )r6   rZ   r;   r<   r=   country_playlist_ids         r8   top_country_trackszShazam.top_country_tracks   s      ( %)$4$I$I-- %J %
 %
 
 
 
 
 
 
 %--)00/!%!6) 1   LLNN . 
 
 
 
 
 
 
 
 	
r9   	city_namec                 *  K   | j                             t          |          |           d{V }| j                            dt
          j                            || j        | j	        |||          | 
                                |           d{V S )a$  
        Retrieving information from an artist profile
        https://www.shazam.com/charts/top-50/russia/moscow

            :param country_code: ISO 3166-3 alpha-2 code. Example: RU,NL,UA
            :param city_name: City name from https://github.com/dotX12/dotX12/blob/main/city.json
                Example: Budapest, Moscow
            :param limit: Determines how many songs the maximum can be in the request.
                Example: If 5 is specified, the query will return no more than 5 songs.
            :param offset: A parameter that determines with which song to display the request.
                The default is 0. If you want to skip the first few songs, set this parameter to
                your own.
            :param proxy: Proxy server

            :return: dict songs
        )r\   cityNr@   r]   rC   )r5   get_city_playlistr   r#   rF   r   rG   rH   r!   r"   rD   )r6   rZ   ra   r;   r<   r=   city_playlist_ids          r8   top_city_trackszShazam.top_city_tracks   s      0 "&!1!C!C-- "D "
 "
 
 
 
 
 
 

 %--)00,!%!6) 1   LLNN . 
 
 
 
 
 
 
 
 	
r9   d   genrec           
      T  K   t          |t                    rt          |          }| j                            |           d{V }| j                            dt          j        	                    || j
        | j        ||          |                                 |           d{V S )a  
        Get world tracks by certain genre
        https://www.shazam.com/charts/genre/world/rock

            :param genre: Genre urlName from https://www.shazam.com/services/charts/locations
            :param limit: Determines how many songs the maximum can be in the request.
                    Example: If 5 is specified, the query will return no more than 5 songs.
            :param offset: A parameter that determines with which song to display the request.
                    The default is 0. If you want to skip the first few songs, set this parameter
                    to your own.
            :param proxy: Proxy server
            :return: dict songs
        )rh   Nr@   rA   rC   )
isinstancestrr   r5   	get_genrer#   rF   r   rG   rH   r!   r"   rD   )r6   rh   r;   r<   r=   genre_playlist_ids         r8   top_world_genre_trackszShazam.top_world_genre_tracks   s      * eS!! 	&u%%E"&"2"<"<5"<"I"IIIIIII%--)00-!%!6 1   LLNN . 
 
 
 
 
 
 
 
 	
r9   c                 r  K   t          |t                    rt          |          }| j                            t          |          |           d{V }| j                            dt          j	        
                    || j        | j        |||          |                                 |           d{V S )a9  
        The best tracks by a genre in the country
        https://www.shazam.com/charts/genre/spain/hip-hop-rap
            :param country_code: ISO 3166-3 alpha-2 code. Example: RU,NL,UA
            :param genre: Genre name or ID:
                POP = 1, HIP_HOP_RAP = 2, DANCE = 3, ELECTRONIC = 4, RNB_SOUL = 5, ALTERNATIVE =
                6, ROCK = 7
                LATIN = 8, FILM_TV_STAGE = 9, COUNTRY = 10, AFRO_BEATS = 11, WORLDWIDE = 12,
                REGGAE_DANCE_HALL = 13
                HOUSE = 14, K_POP = 15, FRENCH_POP = 16, SINGER_SONGWRITER = 17,
                REGIONAL_MEXICANO = 18
            :param limit: Determines how many songs the maximum can be in the request.
                Example: If 5 is specified, the query will return no more than 5 songs
            :param offset: A parameter that determines with which song to display the request.
                The default is 0. If you want to skip the first few songs, set this parameter to
                your own.
            :param proxy: Proxy server
            :return: dict songs
        )r\   rh   Nr@   r]   rC   )rj   rk   r   r5   get_genre_from_countryr   r#   rF   r   rG   rH   r!   r"   rD   )r6   rZ   rh   r;   r<   r=   rm   s          r8   top_country_genre_trackszShazam.top_country_genre_tracks  s      6 eS!! 	&u%%E"&"2"I"I-- #J #
 #
 
 
 
 
 
 

 %--)00-!%!6) 1   LLNN . 
 
 
 
 
 
 
 
 	
r9   r'   c           
         K   | j                             dt          j                            | j        | j        |||          |                                 |           d{V S )a  
        Similar songs based song id
        https://www.shazam.com/track/546891609/2-phu%CC%81t-ho%CC%9Bn-kaiz-remix
            :param track_id: Track number. Example: (549952578)
            https://www.shazam.com/track/549952578/
            :param limit: Determines how many songs the maximum can be in the request.
                Example: If 5 is specified, the query will return no more than 5 songs
            :param offset: A parameter that determines with which song to display the request.
                The default is 0. If you want to skip the first few songs, set this parameter to
                your own.
            :param proxy: Proxy server
            :return: dict tracks
        r@   )r!   r"   r;   r<   rU   rC   N)r#   rF   r   RELATED_SONGSrH   r!   r"   rD   )r6   rU   r;   r<   r=   s        r8   related_trackszShazam.related_tracks8  s      ( %--#**!%!6! +   LLNN . 
 
 
 
 
 
 
 
 	
r9   c           
         K   | j                             dt          j                            | j        | j        |||          |                                 |           d{V S )aG  
        Search all artists by prefix or fullname
            :param query: Artist name or search prefix
            :param limit: Determines how many artists the maximum can be in the request.
                Example: If 5 is specified, the query will return no more than 5 artists.
            :param offset: A parameter that determines with which song to display the request.
                The default is 0. If you want to skip the first few songs, set this parameter to
                your own.
            :param proxy: Proxy server
            :return: dict artists
        r@   r!   r"   r;   r<   rL   rC   N)r#   rF   r   SEARCH_ARTISTrH   r!   r"   rD   r6   rL   r;   r<   r=   s        r8   search_artistzShazam.search_artistY  s      $ %--#**!%!6 +   LLNN . 
 
 
 
 
 
 
 
 	
r9   c           
         K   | j                             dt          j                            | j        | j        |||          |                                 |           d{V S )a8  
        Search all tracks by prefix
            :param query: Track full title or prefix title
            :param limit: Determines how many songs the maximum can be in the request.
                Example: If 5 is specified, the query will return no more than 5 songs.
            :param offset: A parameter that determines with which song to display the request.
                The default is 0. If you want to skip the first few songs, set this parameter to
                your own.
            :param proxy: Proxy server
            :return: dict songs
        r@   rv   rC   N)r#   rF   r   SEARCH_MUSICrH   r!   r"   rD   rx   s        r8   search_trackzShazam.search_trackx  s      $ %--"))!%!6 *   LLNN . 
 
 
 
 
 
 
 
 	
r9   c                    K   | j                             dt          j                            || j                  |                                 |           d{V S )a*  
        Returns the total track listener counter.
            :param track_id: Track number. Example: (559284007)
            https://www.shazam.com/track/559284007/rampampam
            :param proxy: Proxy server
            :return: The data dictionary that contains the listen counter.
        r@   r&   rC   N)r#   rF   r   LISTENING_COUNTERrH   r!   rD   rX   s      r8   listening_counterzShazam.listening_counter  s|       %--'.. /   LLNN . 
 
 
 
 
 
 
 
 	
r9   	track_idsc                    K   | j                             dt          j        d|i|                                 |           d{V S )a5  
        Returns the total track listener counter.
            :param track_ids: Track numbers (list). Example: ([559284007])
            https://www.shazam.com/track/559284007/rampampam
            :param proxy: Proxy server
            :return: The data dictionary that contains the listen counter.
        r@   idrO   N)r#   rF   r   LISTENING_COUNTER_MANYrD   )r6   r   r=   s      r8   listening_counter_manyzShazam.listening_counter_many  se       %--,)$LLNN . 
 
 
 
 
 
 
 
 	
r9   c           	         K   | j                             dt          j                            | j        |||          |                                 |           d{V S )a8  
        Get all albums of a specific artist

          :param artist_id: Artist number. Example (203347991)
          :param limit: Determines how many songs the maximum can be in the request.
              Example: If 5 is specified, the query will return no more than 5 songs.
          :param offset: A parameter that determines with which song to display the request.
              The default is 0. If you want to skip the first few songs, set this parameter to
              your own.
          :param proxy: Proxy server
          :return: dict albums
        r@   )r"   r;   r<   rK   rC   N)r#   rF   r   ARTIST_ALBUMSrH   r"   rD   )r6   rK   r;   r<   r=   s        r8   artist_albumszShazam.artist_albums  s      ( %--#**!%!6#	 +   LLNN . 

 

 

 

 

 

 

 

 
	
r9   album_idc                    K   | j                             dt          j                            | j        |          |                                 |           d{V S )z
        Get album info by id

          :param album_id: Album number. Example (203347991)
          :param proxy: Proxy server
          :return: dict albums
        r@   )r"   r   rC   N)r#   rF   r   ARTIST_ALBUM_INFOrH   r"   rD   )r6   r   r=   s      r8   search_albumzShazam.search_album  s}       %--'..!%!6! /   LLNN . 
 
 
 
 
 
 
 
 	
r9   linkc                 r   K   | j                             d||                                 |           d {V S )Nr@   rC   )r#   rF   rD   )r6   r   r=   s      r8   get_youtube_datazShazam.get_youtube_data  sZ      
 %--LLNN	 . 
 
 
 
 
 
 
 
 	
r9   z.Use recognize method instead of recognize_songdatac                    K   t          |           d{V }t          j        |          }t          j        |          }|                                }|dg iS |                     ||           d{V S )a  
        Creating a song signature based on a file and searching for this signature in the shazam
        database.
            :param data: Path to song file or bytes
            :param proxy: Proxy server
            :return: Dictionary with information about the found song
        )r   Nmatches)r=   )r   r   normalize_audio_datacreate_signature_generatorget_next_signaturesend_recognize_request)r6   r   r=   songaudiosignature_generator	signatures          r8   recognize_songzShazam.recognize_song  s       4(((((((((.t44'B5II'::<<	r?"00 1 
 
 
 
 
 
 
 
 	
r9   sigc                   K   t          j        t          j        |                                t          |j        |j        z  dz            t          t          j                    dz                      }| j	        
                    dt          j                            | j        t          j                    j        | j        t'          t)          j                                                              t'          t)          j                                                                        |                                 ||           d {V S )Ni  POSTr!   devicer"   uuid_1uuid_2rD   r=   json)r   data_searchr   	TIME_ZONEencode_to_uriintnumber_samplessample_rate_hztimer#   rF   r   SEARCH_FROM_FILErH   r!   r   randomvaluer"   rk   uuiduuid4upperrD   r6   r   r=   r   s       r8   r   zShazam.send_recognize_request  s"     
 $"S%77$>??	d"##	
 
 %--&--},!%!64:<<((..004:<<((..00 .   LLNN . 
 
 
 
 
 
 
 
 	
r9   optionsc                 d  K   t          |t          t          j        f          r#| j                            ||           d{V }nNt          |t          t          f          r#| j                            ||           d{V }nt          d          | 
                    ||           d{V S )a  
        All logic and mathematics are transferred to RUST lang.

        Creating a song signature based on a file and searching for this signature in the shazam
        database.
            :param data: Path to song file or bytes
            :param proxy: Proxy server
            :param options: Search parameters
            :return: Dictionary with information about the found song
        )r   r   NzInvalid data type)r   r=   )rj   rk   pathlibPathr4   recognize_pathbytes	bytearrayrecognize_bytes
ValueErrorsend_recognize_request_v2)r6   r   r=   r   r   s        r8   	recognizezShazam.recognize8  s        dS',/00 	2"2AAV]A^^^^^^^^IIui011 	2"2BBW^B________II011133	3OOOOOOOOOr9   c                 ,  K   t          j        t          j        |j        j        |j        j        |j                  }| j        	                    dt          j                            | j        t          j                    j        | j        t%          t'          j                                                              t%          t'          j                                                                        |                                 ||           d {V S )Nr   r   r   )r   r   r   r   r   urisamples	timestampr#   rF   r   r   rH   r!   r   r   r   r"   rk   r   r   r   rD   r   s       r8   r   z Shazam.send_recognize_request_v2Q  s      
 $MM!M	
 
 %--&--},!%!64:<<((..004:<<((..00 .   LLNN . 
 
 
 
 
 
 
 
 	
r9   )r   r   Nr    )r:   r   N)NN)N)rg   r   N)r'   r   N)r    r   N),__name__
__module____qualname____doc__rk   r   r   r   r3   r   r   rJ   r   rT   rY   r`   rf   r   r   rn   rq   rt   ry   r|   r   r   r   r   r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   __classcell__)r7   s   @r8   r   r      s           $59(*8 88 8 12	8
 #&8 8 8 8 8 84 #	
 

 
 }	

 
c3h
 
 
 
F (,#	
 

 $
 }	

 
c3h
 
 
 
H  $
 

 }
 
c3h	
 
 
 
6 #$
 $
$
 $
 	$

 }$
 
c3h$
 $
 $
 $
T #)
 )
)
 )
 	)

 )
 })
 
c3h)
 )
 )
 )
\ #$
 $
Z_%$
 $
 	$

 }$
 
c3h$
 $
 $
 $
T #/
 /
/
 Z_%/
 	/

 /
 }/
 
c3h/
 /
 /
 /
h #
 

 
 	

 }
 
c3h
 
 
 
H #
 

 
 	

 }
 
c3h
 
 
 
D #
 

 
 	

 }
 
c3h
 
 
 
D  $
 

 }
 
c3h	
 
 
 
4  $
 
9
 }
 
d38n		
 
 
 
. #
 

 
 	

 }
 
 
 
F  $
 

 }
 
 
 
4  $

 



 }

 
c3h	

 

 

 

 Z@AA  $
 
CuiEF
 }
 
c3h	
 
 
 BA
8  $
 

 }
 
c3h	
 
 
 
8  $*.	P PC	)*P }P ,'	P
 
c3hP P P P8  $
 

 }
 
c3h	
 
 
 
 
 
 
 
r9   r   )*r   r   r   typingr   r   r   r   r   aiohttp_retryr   pydubr	   shazamio_corer
   r   r   clientr   	converterr   r   deprecated.decoratorr   enumsr   interfaces.clientr   miscr   r   r   schemas.artistsr   r   r   	typehintsr   utilsr   r   r    r9   r8   <module>r      s      ) ) ) ) ) ) ) ) ) ) ) )       * * * * * *       = = = = = = = = = =       , , , , , , , , , , , , , ,       2 2 2 2 2 2 ! ! ! ! ! ! ! !       ( ( ( ( ( ( % % % % % % " " " " " " ' ' ' ' ' '      O	
 O	
 O	
 O	
 O	
W O	
 O	
 O	
 O	
 O	
r9   