
    M@cb6                     v   d dl Z d dlZddlmZ ddlmZ ddlmZ  ee      ZdZ	dZ
dZd	Zd
ZdZdZeZe	d    ed    z  ddfZdZdZdZdZdZdZdZd#dZd Zd Z G d de      Zej:                   G d d             Z G d de      Z  G d dejB                        Z"g da# e        Z$d d!lm%Z% d d"l&m'Z'm(Z(m)Z)m*Z* y)$    N   )core)Error)	getLogger)   NN)r   r   r   )r   r   r   )r   NNr   r   r   )r      r   )r      r                s   engzapplication/x-id3)z.id3z.tagc           	          | t         t        t        t        t        t
        t        t        fv }|sy|rd| d   | d   | d   fvS y)zCheck the tuple ``v`` against the list of valid ID3 version constants.
    If ``fully_qualified`` is ``True`` it is enforced that there are 3
    components to the version in ``v``. Returns ``True`` when valid and
    ``False`` otherwise.FNr   r   r   T)ID3_V1ID3_V1_0ID3_V1_1ID3_V2ID3_V2_2ID3_V2_3ID3_V2_4ID3_ANY_VERSION)vfully_qualifiedvalids      4/usr/lib/python3/dist-packages/eyed3/id3/__init__.pyisValidVersionr   -   sQ    
 &(H(Hh!# #E AaD!A$!---    c                     | t         k(  rt        } n4| t        k(  rt        d   t        d   z  sJ t        } n| t        k(  rt        } | dd dk(  r
| d   dk7  rd} | S )zsIf version tuple ``v`` is of the non-specific type (v1 or v2, any, etc.)
    a fully qualified version is returned.r   Nr   )r   r   r   )r   r   r   ID3_DEFAULT_VERSIONr   r   s    r   normalizeVersionr!   >   sc     	F{	
f"1%q	111	
o	 	!u1Q419Hr   c                     | t         k(  ry| d   dk(  r| t        k(  ry| t        k(  ry| t        k(  r1y| d   dk(  r(| t        k(  ry| t
        k(  ry	| t        k(  ry
| t        k(  ryt        dt        |       z        )z7Conversion version tuple ``v`` to a string description.z	v1.x/v2.xr   r   zv1.0zv1.1zv1.xr   zv2.2zv2.3zv2.4zv2.xz Invalid ID3 version constant: %s)
r   r   r   r   r   r   r   r   
ValueErrorstrr    s    r   versionToStringr%   Q   s~    O	
1=(]&[	
1=(](]&[
7#a&@
AAr   c                       e Zd ZdZy)GenreExceptionz0Excpetion type for exceptions related to genres.N)__name__
__module____qualname____doc__ r   r   r'   r'   h   s    :r   r'   c                       e Zd ZdZddefdZed        Zej                  d        Zed        Z	e	j                  d        Z	e
dd	       Zd
 Zd Zd Zy)GenrezA genre in terms of a ``name`` and and ``id``. Only when ``name`` is
    a "standard" genre (as defined by ID3 v1) will ``id`` be a value other
    than ``None``.Nidc                    d\  | _         | _        |xs t        | _        |s|y|@	 || _        |r5|| j
                  k7  r&t        j                  d| d| j
                   d       n|| _        | j                  s| j
                  sJ yy# t        $ r, t        j                  d|        |s || _        d| _        Y Pw xY w)a  Constructor takes an optional name and ID. If `id` is
        provided the `name`, regardless of value, is set to the string the
        id maps to. Likewise, if `name` is passed and is a standard genre the
        id is set to the correct value. Any invalid id values cause a
        `ValueError` to be raised. Genre names that are not in the standard
        list are still accepted but the `id` value is set to `None`.)NNNz(Genre ID takes precedence and remapped 'z' to ''zInvalid numeric genre ID: )	_id_namegenres
_genre_mapr/   namelogwarningr#   )selfr6   r/   	genre_maps       r   __init__zGenre.__init__r   s      *$*#-v
 >DDII-KK"J4&PVW[W`W`Vaab cd DIww$))##)w  8=> 	s   >B	 	2B>=B>c                     | j                   S )a  The Genre's id property.
        When setting the value is strictly enforced and if the value is not
        a valid genre code a ``ValueError`` is raised. Otherwise the id is
        set **and** the ``name`` property is updated to the code's string
        name.
        )r2   r9   s    r   r/   zGenre.id   s     xxr   c                     |d | _         y t        |      }|| j                  j                         vs| j                  |   st	        d|       | j                  |   }|| _         || _        y )NzUnknown genre ID: )r2   intr5   keysr#   r3   )r9   valr6   s      r   r/   zGenre.id   si    ;DH#hdoo**,,DOOC4H1#788s#
r   c                     | j                   S )a  The Genre's name property.
        When setting the value the name is looked up in the standard genre
        map and if found the ``id`` ppropery is set to the numeric valud **and**
        the name is normalized to the sting found in the map. Non standard
        genres are set (with a warning log) and the ``id`` is set to ``None``.
        It is valid to set the value to ``None``.
        )r3   r=   s    r   r6   z
Genre.name   s     zzr   c                 0   |d | _         y |j                         t        | j                  j	                               v r3| j                  |   | _        | j                  | j
                     | _         y t        j                  d|        d | _        || _         y )NzNon standard genre name: )r3   lowerlistr5   r@   r2   r7   r8   )r9   rA   s     r   r6   z
Genre.name   sw    ;DJ99;$t33566s+DH2DJKK3C59:DHDJr   c                    | j                         } | syd }|rt        j                  d      j                  |       rt	        t         ||                   S t        j                  d      j                  |       }|rL|j                         \  }}t         ||            }|r|r|}|j                         }n|}d}t	        ||      S t	        d|       S )a&  Parses genre information from `genre_str`.
        The following formats are supported:
        01, 2, 23, 125 - ID3 v1.x style.
        (01), (2), (129)Hardcore, (9)Metal, Indie - ID3v2 style with and without refinement.
        Raises GenreException when an invalid string is passed.
        Nc                 D    t        |       dkD  r| j                  d      S | S )Nr   0)lenlstrip)ss    r   strip0Paddingz"Genre.parse.<locals>.strip0Padding   s     1vzxx}$r   z[0-9][0-9]*$r/   z\(([0-9][0-9]*)\)(.*)$r/   r6   )striprecompilematchr.   r?   groups)g_strid3_stdrL   	v23_matchgidr6   s         r   parsezGenre.parse   s     	  zz/*007M%$8 9:: 

#<=CCEJI'..0d-,-4C::<DCD$//5))r   c                     d}| j                   |d| j                   ddz  }| j                  r|| j                  z  }|S )N (d)rN   )r9   rK   s     r   __str__zGenre.__str__   sC    771TWWQKq!!A99NAr   c                     |syt        |      t        u r| j                  |k(  S | j                  |j                  k(  xr | j                  |j                  k(  S NF)typer$   r6   r/   r9   rhss     r   __eq__zGenre.__eq__   sH    #Y#99##77cff$>chh)>>r   c                 z    |syt        |      t        u r| j                  |k(  S | j                  |j                  k  S r`   )ra   r$   r6   rb   s     r   __lt__zGenre.__lt__   s6    #Y#99##99sxx''r   )NNN)T)r(   r)   r*   r+   r?   r;   propertyr/   setterr6   staticmethodrX   r^   rd   rf   r,   r   r   r.   r.   l   s    $c $@   YY    
[[  (* (*T?(r   r.   c                   d     e Zd ZdZdZdZdZdZdZdZ	dZ
 fdZd	 Z fd
Zed        Zd Z xZS )GenreMapzClassic genres defined around ID3 v1 but suitable anywhere.  This class
    is used primarily as a way to map numeric genre values to a string name.
    Genre strings on the other hand are not required to exist in this list.
    r   NO   P         c                    t        |   |  t        t              D ]!  \  }}|| |<   || |r|j	                         nd<   # t        t              dz
  t        _        t        t        j                  dz   d      D ]  }d| |<   	 d| d<   y)zOThe optional ``*args`` are passed directly to the ``dict``
        constructor.Nr      ro   )	superr;   	enumerate
ID3_GENRESrD   rI   rk   	GENRE_MAXrange)r9   argsig	__class__s       r   r;   zGenreMap.__init__  s     	$ j) 	/DAqDG-.DaT*	/ !_q0x))A-w7 	ADG	T
r   c                 d    t        |      t        u r| |   |}}n
| |   }| |   }t        |||       S )N)r/   r:   )ra   r?   r.   )r9   keyr6   rW   s       r   getzGenreMap.get&  s<    9S	3#Ds)C9DTcT22r   c                 h    |r!t        |      t        ur|j                         }t        |   |      S N)ra   r?   rD   rr   __getitem__)r9   r|   rz   s     r   r   zGenreMap.__getitem__.  s,    49C'))+Cw"3''r   c           
          t        t        | j                         D cg c]  }t        |      t        u s| |   s| c}            S c c}w r   )rE   sortedr@   ra   r?   )r9   ks     r   idszGenreMap.ids3  s6    Ftyy{Q!d1gnaAQRSSQs   A	A	A	c              #   \   K   | j                   D ]  }| |   }|st        ||        y w)NrM   )r   r.   )r9   rW   ry   s      r   iterzGenreMap.iter7  s2     88 	'CS	AA#&&	's   ,,)r(   r)   r*   r+   	GENRE_MINru   ID3_GENRE_MINID3_GENRE_MAXWINAMP_GENRE_MINWINAMP_GENRE_MAXGENRE_ID3V1_MAXr;   r}   r   rg   r   r   __classcell__)rz   s   @r   rk   rk     sY     IIMMO"3(
 T T'r   rk   c                   *    e Zd ZdZefdZd ZefdZy)TagFilezS
    A shim class for dealing with files that contain only ID3 data, no audio.
    c                     || _         t        j                  j                  | |       | j                  t        j
                  k(  sJ y r   )_tag_versionr   	AudioFiler;   ra   
AUDIO_NONE)r9   pathversions      r   r;   zTagFile.__init__B  s4    #d+yyDOO+,+r   c                     t        | j                  d      5 }t               }|j                  || j                        }|r|nd | _        d d d        t        j                  | _        y # 1 sw Y   xY w)Nrb)	openr   TagrX   r   _tagr   r   ra   )r9   file_objtag	tag_founds       r   _readzTagFile._readG  s\    $))T" 	3h%C		(D,=,=>I(dDI	3
 OO		3 	3s   2A''A0c                     t               | _        || j                  _        t        | j                        | j                  _        y)zMAdd a id3.Tag to the file (removing any existing tag if one exists).
        N)r   r   r   FileInfor   	file_info)r9   r   s     r   initTagzTagFile.initTagP  s.     5"%dii0r   N)	r(   r)   r*   r+   r   r;   r   r   r   r,   r   r   r   r   >  s      &5 -
$ 2 1r   r   )BlueszClassic RockCountryDanceDiscoFunkGrungezHip-HopJazzMetalzNew AgeOldiesOtherPopzR&BRapReggaeRockTechno
IndustrialAlternativeSkazDeath MetalPranks
SoundtrackzEuro-TechnoAmbientzTrip-HopVocalz	Jazz+FunkFusionTrance	ClassicalInstrumentalAcidHouseGamez
Sound ClipGospelNoise
AlternRockBassSoulPunkSpace
MeditativezInstrumental PopzInstrumental RockEthnicGothicDarkwavezTechno-Industrial
ElectroniczPop-Folk	EurodanceDreamzSouthern RockComedyCultzGangsta RapzTop 40zChristian Rapz
Pop / FunkJunglezNative AmericanCabaretzNew WavePsychedelicRave	ShowtunesTrailerzLo-FiTribalz	Acid Punkz	Acid JazzPolkaRetroMusicalzRock & Rollz	Hard RockFolkz	Folk-RockzNational FolkSwingzFast FusionBebobLatinRevivalCeltic	Bluegrass
AvantgardezGothic RockzProgressive RockzPsychedelic RockzSymphonic Rockz	Slow RockzBig BandChoruszEasy ListeningAcousticHumourSpeechChansonOperazChamber MusicSonataSymphonyz
Booty BassPrimuszPorn GrooveSatirezSlow JamClubTangoSambaFolkloreBalladzPower BalladzRhythmic Soul	FreestyleDuetz	Punk Rockz	Drum Soloz
A Cappellaz
Euro-Housez
Dance HallGoazDrum & Bassz
Club-HouseHardcoreTerrorIndieBritPop	Negerpunkz
Polsk PunkBeatzChristian Gangsta RapzHeavy MetalzBlack Metal	CrossoverzContemporary ChristianzChristian RockMerengueSalsazThrash MetalAnimeJPopSynthpopAbstractzArt RockBaroqueBhangrazBig Beat	BreakbeatChillout	DowntempoDubEBMEclecticElectroElectroclashEmoExperimentalGarageGlobalIDMIllbientzIndustro-GothzJam Band	Krautrock	LeftfieldLoungez	Math RockzNew Romanticz	Nu-Breakzz	Post-Punkz	Post-Rock	PsytranceShoegazez
Space Rockz	Trop RockzWorld MusicNeoclassical	AudiobookzAudio TheatrezNeue Deutsche WellePodcastz
Indie RockzG-FunkDubstepzGarage RockPsybientr   )frames)r   TagExceptionTagTemplater   )F)+rP   	functoolsrZ   r   r   	utils.logr   r(   r7   r   r   r   r   r   r   r   r   r   LATIN1_ENCODINGUTF_16_ENCODINGUTF_16BE_ENCODINGUTF_8_ENCODINGDEFAULT_LANGID3_MIME_TYPEID3_MIME_TYPE_EXTENSIONSr   r!   r%   r'   total_orderingr.   dictrk   r   r   rt   r4   r  r   r   r  r  r   r,   r   r   <module>r)     s   	    ! 
	 !9vay($5   #+ "&B.;U ; X( X( X(v3't 3'l1dnn 16B
J 
  9 9r   