
    M@c                        d dl Z d dlZd dl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mZmZ d dlmZmZmZmZmZ d dlmZ d d	lmZ d d
lmZ  ee      ZdZdZ  G d de      Z!d Z"i dddddde
jF                  z  ddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1i d2d3d4d5d6d7d8d9d:d;d<d= e$ejJ                  d>      z  d?d@ e$ejJ                  d>      z  dAdBdCdDdEdF e$ejJ                  d>      z  dGdH e$ejJ                  d>      z  dIdJdKdLdMdNdOdPdQdRdSdTi dUdVdWdXdYdZd[jM                   e'ejP                  ejR                  d\z         D  cg c]  }  ejT                  |        c}       d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~d e"       z   ddddd
Z+yc c} w )    N)partial)ArgumentTypeError)LoaderPlugin)coreid3mp3)makeUniqueFileNameb
formatTime)printMsg
printErrorprintWarningboldText
getTtySize)
ImageFrame)guessMimetype)	getLogger:i   c                   l     e Zd ZdZdZdgZ fdZ fdZd Zd Z	e
dd       Zd	 Zd
 Zd Zd Z xZS )ClassicPluginz5Classic eyeD3 interface for viewing and editing tags.ay  
All PATH arguments are parsed and displayed. Directory paths are searched
recursively. Any editing options (--artist, --title) are applied to each file
read.

All date options (-Y, --release-year excepted) follow ISO 8601 format. This is
``yyyy-mm-ddThh:mm:ss``. The year is required, and each component thereafter is
optional. For example, 2012-03 is valid, 2012--12 is not.
classicc           
      ,   t         t        |   |       | j                  }d }|j	                  ddddt
        d          |j	                  ddd	dt
        d          |j	                  d
dddt
        d          |j	                  ddddt
        d          |j	                  dd|ddt
        d          |j	                  dd|ddt
        d          |j	                  dt        ddt
        d          |j	                  dddt
        d          |j	                  dddt
        d          |j	                  dd |d!dt
        d           |j	                  d"d#|d$dt
        d#          |j	                  d%d&d'd(t
        d&          |j	                  d)d*d+t
        d)   ,       |j	                  d-d.|d/d0t
        d.          |j	                  d1d2d3dt
        d2          |j	                  d4dd5t        j                   d67       |j	                  d8dd9t        j                   d67       |j	                  d:dd;t        j                   d67       |j	                  d<d=d>t
        d<          |j                  d?      }dd@fdA}fdBfdC}dD }fdEfdF}dG }	fdHfdI}
dJ }dK }dL }fdM}fdN}fdO}fdP}|j	                  dQdRdSt        j                  dTt        j                  t
        dR   U       |j	                  dVdWdSt        j                  dTt        j                  t
        dW   U       |j	                  dXdSt        j                  dYt
        dX   Z       |j	                  d[dSt        j                  dYt
        d[   Z       |j	                  d\dSt        j                   dYt
        d\   Z       |j	                  d]|	d^d_t
        d]          |j	                  d`|	dad_t
        d`          |j	                  db|	dcd_t
        db          |j	                  dd|	ded_t
        dd          |j	                  df|	dgd_t
        df          |j	                  dhdidjdt
        dh   k       |j	                  dl|dmdnd t
        dl   o       |j	                  dp|dqdd t
        dp   o       |j	                  drds|dtdug t
        dr   v       |j	                  dwdsdxdyg t
        dw   z       |j	                  d{ds|d|g d}t
        d{   ~       |j	                  dd+dt
        d          |j	                  dd+dt
        d          |j	                  dds|
dg dt
        d   ~       |j	                  dds|dg d}t
        d   ~       |j	                  dd+dt
        d          |j	                  ddsddg t
        d   v       |j	                  ddsddg t
        d   v       |j	                  dds|ddg t
        d   v       |j	                  dds|ddg t
        d   v       |j	                  dds|ddg t
        d   v       |j	                  ddsdg dt
        d          |j	                  dd+dt
        d          |j	                  ddd|t
        d          |j	                  dds|dg dt
        d   ~       |j	                  ddsdg dt
        d          |j	                  ddiddd t
        d          |j	                  dd+dt
        d          |j	                  dds|dg dt
        d   ~       |j	                  ddst"        dg dt
        d   ~       |j	                  dd+ddt
        d          |j	                  dd+ddt
        d          |j	                  dd+ddt
        d          |j	                  ddsg dd|t
        d          |j	                  dt        dddt
        d   ū       |j	                  dddSd t
        d   ǫ       g dȢ}|j	                  ddd |dj%                  |      t
        d   ̫       |j                  dͫ      }|j	                  dd+ddt
        d          |j	                  ddd+dt
        d          |j	                  dd+dt
        d          y )Nc                 <    t        |       } | dk  rt        d      | S )Nr   zpositive number required)intr   )is    7/usr/lib/python3/dist-packages/eyed3/plugins/classic.pyPositiveIntArgz.ClassicPlugin.__init__.<locals>.PositiveIntArg)   s#    AA1u'(BCCH    z-a--artistartistSTRING)destmetavarhelpz-A--albumalbumz-b--album-artistalbum_artistz-t--titletitlez-n--tracktrackNUM)typer"   r#   r$   z-N--track-totaltrack_total--track-offsettrack_offsetN
--composercomposer--orig-artistorig_artistz-d
--disc-numdisc_numz-D--disc-total
disc_totalz-G--genregenreGENRE--non-std-genresnon_std_genres
store_true)r"   actionr$   z-Y--release-yearrelease_yearYEARz-c	--commentsimple_commentz--artist-cityz:The artist's city of origin. Stored as a user text frame ``)r#   r$   z--artist-statez;The artist's state of origin. Stored as a user text frame `z--artist-countryz=The artist's country of origin. Stored as a user text frame `--renamerename_patternPATTERNzID3 optionsc                 b   dt        j                  dt        z  |       } t        fd| j	                  t              D              }||dk  rt        dj                  |            |rCt        |      |kD  r5|d |dz
   t        j                  ||dz
  d        fz   }t        |      |k  sJ |S )Nz#DELIM#z\\%sc              3   T   K   | ]  }t        j                  t        |       ! y wN)resubFIELD_DELIM).0s	NEW_DELIMs     r   	<genexpr>z=ClassicPlugin.__init__.<locals>._splitArgs.<locals>.<genexpr>f   s&      : ffYQ7 :s   %(   zInvalid maxsplit value: {}   )	rO   rP   rQ   tuplesplit
ValueErrorformatlenjoin)argmaxsplittrT   s      @r   
_splitArgsz*ClassicPlugin.__init__.<locals>._splitArgsc   s    !I&&;.	3?C :"%))K"8: :A#1 !=!D!DX!NOOc!fx/mx!|$(8(88a<=9I(J'LL1v)))Hr   c                      | d      }|d   }t        |      dkD  r|d   nt        j                  }|t        |      dd xs t        j                  fS )DESCRIPTION[:LANG]rV   r   rW   N   )r\   r   DEFAULT_LANGr
   )r^   valsdesclangra   s       r   DescLangArgz+ClassicPlugin.__init__.<locals>.DescLangArgo   sS    c1%D7D!$i!m471A1AD4!8(8(888r   c                      | d      }|d   j                         }t        j                  t        |      dkD  r|dd ng       }|xs d|xs dfS )zDESCRIPTION:TEXTrV   r   rW   N )striprQ   r]   r\   )r^   rf   rg   textra   s       r   DescTextArgz+ClassicPlugin.__init__.<locals>.DescTextArgv   sS    c1%D7==?D##D	ADH2FD:2tzr))r   c                 @     |       \  }}||j                  d      fS )Nlatin1encode)r^   rg   urlrn   s      r   
DescUrlArgz*ClassicPlugin.__init__.<locals>.DescUrlArg~   s%    #C(ID#H---r   c                 ^    | j                         j                  d      }|st        d      |S )NasciiNo frame ID)rl   rr   r   )r^   fids     r   FidArgz&ClassicPlugin.__init__.<locals>.FidArg   s+    ))+$$W-C'66Jr   c                      | d      }|d   j                         j                  d      }|st        d      t        |      dkD  r|d   nd}||fS )FID:TEXTrV   r   rv   rw   rW   rk   )rl   rr   r   r\   )r^   rf   rx   rm   ra   s       r   TextFrameArgz,ClassicPlugin.__init__.<locals>.TextFrameArg   sV    c1%Dq'--/((1C'66!$i!m47D9r   c                 @     |       \  }}||j                  d      fS )r{   rp   rq   )r^   rx   rs   r|   s      r   UrlFrameArgz+ClassicPlugin.__init__.<locals>.UrlFrameArg   s%    #C(HC

8,,,r   c                 H    | rt         j                  j                  |       S dS )Nrk   )r   Dateparse)date_strs    r   DateArgz'ClassicPlugin.__init__.<locals>.DateArg   s    08499??8,@b@r   c                      | d      }|d   }|st        d      t        |      dkD  r|d   nd}t        |      dkD  r|d   nt        j                  }||t	        |      dd fS )z5
            COMMENT[:DESCRIPTION[:LANG]
            rd   r   ztext requiredrW   rk   rV   N)r   r\   r   re   r
   )r^   rf   rm   rg   rh   ra   s        r   
CommentArgz*ClassicPlugin.__init__.<locals>.CommentArg   so     c1%D7D'88!$i!m47D!$i!m471A1ADqwr{**r   c                      |       \  }}}	 t        |d      5 }|j                         }d d d        ||fS # 1 sw Y   xY w# t        $ r t        d      w xY w)NrzUnable to read file)openread	Exceptionr   )r^   rm   rg   rh   fpdatar   s         r   	LyricsArgz)ClassicPlugin.__init__.<locals>.LyricsArg   sl    )#D$?$_ %779D% t##	% % ?'(=>>?s   A 9A AA Ac                     | st        d      d}| d   dk(  rt        | dd        } d}nt        |       } | dk  rt        d      || fS )Nzvalue requiredFr   +rW   Tout of range)r   r   )pc	increments     r   PlayCountArgz,ClassicPlugin.__init__.<locals>.PlayCountArg   sZ    '(899I!u|AB[ 	WAv'77b= r   c                 T    t        t        |       dz         } | dk  rt        d      | S )Ng      ?r   r   )r   floatr   )bpms    r   BpmArgz&ClassicPlugin.__init__.<locals>.BpmArg   s,    eCj3&'Cax'77Jr   c                 d    | rt         j                  j                  |       st        d| z        | S )Nzinvalid directory: %s)ospathisdirr   )ds    r   DirArgz&ClassicPlugin.__init__.<locals>.DirArg   s*    BGGMM!,'(?!(CDDHr   c                 <    | d      }t        |      dk  rt        d      |dd \  }}t        |      dkD  r|d   nd}	 t        j                  j                  j                  |      }|st        d      dd	D cg c]  }|j                  |       c}v rt        j                  }nBt        j                  j                  |      st        d
      t        |      }|t        d      ||||fS # t        $ r t        dj                  |            w xY wc c}w )z`PATH:TYPE[:DESCRIPTION]
            Returns (path, type_id, mime_type, description)
            rd   rV   z"Format is: PATH:TYPE[:DESCRIPTION]Nrk   zinvalid pic type: {}path requiredT)zhttp://zhttps://file does not existzCannot determine mime-type)r\   r   r   framesr   stringToPicTyper   r[   
startswithURL_MIME_TYPEr   r   isfiler   )	rS   argsr   type_strrg   type_idprefixmtra   s	           r   ImageArgz(ClassicPlugin.__init__.<locals>.ImageArg   s&    a#D4y1}'(LMM!"1XND(!$i!m47DQ**//??I '88(?A$ //&1 A A--ww~~d++,ABB"4(:+,HII"d**  Q'(>(E(Eh(OPPQ
As   )C2 =D2$Dc                 ~    | d      }t        |      dk  rt        d      |d   }|r|d   }t        |      dkD  r|d   nd}t        |      dkD  r|d   nt        j                  j	                  |      }t        j                  j                  |      st        d      |st        d	      t        d
      ||||fS )zvOBJ_PATH:MIME-TYPE[:DESCRIPTION[:FILENAME]],
            Returns (path, mime_type, description, filename)
               rV   ztoo few partsr   rW   rk   rd   r   zmime-type requiredr   )r\   r   r   r   basenamer   )rS   r   r   r   rg   filenamera   s         r   	ObjectArgz)ClassicPlugin.__init__.<locals>.ObjectArg   s     a#D4y1}'887D!W"%d)a-tAwR #D	A  7%'WW%5%5d%;  ww~~d++,ABB+,@AA'88"dH--r   c                      |       \  }}|st        d      |j                  d      }t        |      dkD  rt        d      ||fS )Nzowner_id requiredrp   @   zid must be <= 64 bytes)r   rr   r\   )r^   owner_ididKeyValueArgs      r   UniqFileIdArgz-ClassicPlugin.__init__.<locals>.UniqFileIdArg   sO    &s+LHb'(;<<8$B2w|'(@AAb>!r   c                     | d      }t        |      dk  rt        d      |d   }t        t        |d               }|dk  s|dkD  rt        d      d}t        |      dkD  rt        |d         }|dk  rt        d      |||fS )	zVEMAIL:RATING[:PLAY_COUNT]
            Returns (email, rating, play_count)
            rd   rV   z'Incorrect number of argument componentsr   rW      zRating out-of-rangezPlay count out-of-range)r\   r   r   r   )r^   r   emailrating
play_countra   s        r   PopularityArgz-ClassicPlugin.__init__.<locals>.PopularityArg  s     c1%D4y1}'(QRRGEtAw(FzVc\'(=>>J4y1} a\
A~'(ABB6:..r   z-1--v1store_consttag_version)rB   constr"   defaultr$   z-2--v2	--to-v1.1convert_version)rB   r   r"   r$   	--to-v2.3	--to-v2.4--release-daterelease_dateDATE--orig-release-dateorig_release_date--recording-daterecording_date--encoding-dateencoding_date--tagging-datetagging_date--publisherstore	publisher)rB   r"   r#   r$   --play-countr   z<+>N)r.   r"   r#   r   r$   --bpmr   --unique-file-idappendunique_file_idszOWNER_ID:ID)rB   r.   r"   r#   r   r$   --add-commentcommentszCOMMENT[:DESCRIPTION[:LANG]])rB   r"   r#   r   r.   r$   --remove-commentremove_commentrc   )rB   r.   r"   r   r#   r$   --remove-all-commentsremove_all_comments)rB   r"   r$   --remove-all-unknownremove_all_unknown--add-lyricslyricsz LYRICS_FILE[:DESCRIPTION[:LANG]]--remove-lyricsremove_lyrics--remove-all-lyricsremove_all_lyrics--text-frametext_framesr{   --user-text-frameuser_text_framesz	DESC:TEXT--url-frame
url_frameszFID:URL--user-url-frameuser_url_frameszDESCRIPTION:URL--add-imageimageszIMG_PATH:TYPE[:DESCRIPTION]--remove-imageremove_imageDESCRIPTION)rB   r"   r   r#   r$   --remove-all-imagesremove_all_images--write-imageswrite_images_dirDIR)r"   r#   r.   r$   --add-objectobjectsz+OBJ_PATH:MIME-TYPE[:DESCRIPTION[:FILENAME]]--remove-objectremove_object--write-objectswrite_objects_dir)rB   r"   r#   r   r$   --remove-all-objectsremove_all_objects--add-popularitypopularitieszEMAIL:RATING[:PLAY_COUNT]--remove-popularityremove_popularityEMAIL--remove-v1	remove_v1F)rB   r"   r   r$   --remove-v2	remove_v2--remove-all
remove_all)rB   r   r"   r$   --remove-frameremove_fidsFID)rB   r   r"   r#   r.   r$   --max-paddingmax_paddingT	NUM_BYTES)r.   r"   r   r#   r$   --no-max-padding)r"   rB   r   r$   )rp   utf8utf16zutf16-be
--encodingtext_encoding|)r"   r   choicesr#   r$   zMisc options--force-updateforce_updatez-v	--verboseverbose--preserve-file-timespreserve_file_timerN   )superr   __init__	arg_groupadd_argument	ARGS_HELPr   r   TXXX_ARTIST_ORIGINadd_argument_groupr   ID3_V1ID3_ANY_VERSIONID3_V2ID3_V1_1ID3_V2_3ID3_V2_4strr]   )self
arg_parsergr   gid3ri   rt   ry   r~   r   r   r   r   r   r   r   r   r   
_encodingsgid4r   rn   r   r|   ra   	__class__s                       @@@@@r   r!  zClassicPlugin.__init__%   s
   mT+J7NN	 	
tZh'i
.C 	 	E	tYW'i	.B 	 	D	t-*H%&67 	 	9 	
tYW'i	.B 	 	D	tY^'$9Y+? 	 	A	t_>)5%o6 	 	8 	
'c"3C)D 	 	F 	
|*'i.E 	 	G	]'i.H 	 	J	t\Z$9\+B 	 	D	t^.(%%n5 	 	7 	
tYW&Yy-A 	 	C	)0@*;M1N 	 	P	t-N*F%&67 	 	9 	
t[/?'%k2 	 	4 	
<<@<S<S;TTUW 	 	X 	
'77;7N7N6OqR 	 	S 	
)877;7N7N6OqR 	 	S 	
z(8)%j1 	 	3 ,,];
		9	* "	.			-
	A
	+	$	!		
	+<	..	"	/& 	$}CJJ,c6I6I(0 	 	2 	$}CJJ,c6I6I(0 	 	2 	+m3<<0y7M 	 	O+m3<<0y7M 	 	O+m3<<0y7M 	 	O 	*~"(()9: 	 	< 	/g2F()>? 	 	A 	,7/();< 	 	> 	+'"(y9J/K 	 	M*~"(y9I/J 	 	L 	-*H(7 	 	9 	.|,"($(8 	 	: 	'UC"&Yw-? 	 	A,X,3D"/();< 	 	> 	/("@")	/0J 	 	L 	,XK/"6();< 	 	> 	1,4()@A 	 	C 	03()?@ 	 	B 	.	'"D(8 	 	: 	+H;."6():; 	 	= 	/2()>? 	 	A 	.,j"(8 	 	: 	-h*1;"$95H+I 	 	K
 	-{+Y(7 	 	9 	,XJ0:K"$95G+H 	 	J 	-x'1N"$9]+C 	 	E 	*8-r"/()9: 	 	< 	/2()>? 	 	A 	*1C"'f()9: 	 	< 	.	(""O(8 	 	: 	+H."/():; 	 	= 	+G2E4():; 	 	= 	03()?@ 	 	B 	,X,>2"=();< 	 	> 	/s2B")()>? 	 	A
 	-;"'i.F 	 	H-;"'i.F 	 	H.u+)N2K 	 	M*8R,e&()9: 	 	<
 	/-"&(9 	 	; 	,=!.d();< 	 	> =
,_d",chhz6J(6 	 	8
 ,,^<*<-I>N4O 	 	Q$L(y/E 	 	G1,3()@A 	 	Cr   c                 
   | j                   j                  }	 t        |   ||       | j                  sy t               d   | _
        | j                  |       | j                  j                  rG| j                  | j                  j                        r"t        t        |   ||       | j                  sy d}| j                  j                  s| j                  j                  |       d}	 | j!                  | j                  j                        xsU | j#                  | j                  j                        xs. | j                   j$                  xs | j                   j&                  }| j+                  | j                  j,                         |s9|r7t        dt	        j.                  | j                   j                         d       y | j1                  | j                  j                         | j                   j2                  r| j                  j                  j4                  D ]  }|j6                  t8        j:                  vs | j                   j2                  t<        j>                  j@                  }t<        j>                  jC                  |      stE        d|z        tG        t<        j>                  jI                  ||jK                                     }	tM        d	|	z         tO        |	d
      5 }
|
jQ                  |jR                         d d d         |r| j                   j&                  xs  | j                  j                  jT                  }tM        dt	        j.                  |      z         | j                   jV                  }|du rtX        }| j                  j                  j[                  || j                   j\                  | j                   j^                  | j                   j`                  |       | j                   jb                  rddl2m3}  || j                   jb                        }|ji                  | j                  j                  d      }| j                  j>                  }	 | j                  jk                  |       tM        d| d| j                  j>                   d       tm        | jo                  | j                               y # t        j
                  $ r}t        t        |             Y d }~y d }~ww xY w# t(        $ r}t        t        |             Y d }~y d }~ww xY w# 1 sw Y   xY w# tD        $ r}t        t        |             Y d }~d }~ww xY w)N)r   rW   F)versionTzNo ID3 z tag found!Directory does not exist: %sWriting %s...wbzWriting ID3 version %s)r6  encodingbackupr  r  r   )TagTemplate)zeropadz	Renamed 'z' to '')8r   r   r   
handleFiler   TagExceptionr   r-  
audio_filer   terminal_widthprintHeadertaghandleRemovesr   initTaghandleEditshandlePaddingr  r   rZ   printAudioInfoinfoversionToStringprintTagr   r   	mime_typer   URL_MIME_TYPE_VALUESr   r   sepr   IOErrorr	   r]   makeFileNamer   r   write
image_datar6  r  DEFAULT_MAX_PADDINGsaver  r;  r  rJ   eyed3.id3.tagr<  
substituterenamer   _getHardRule)r.  fparse_versiontag_exnew_tagsave_tageximgimg_pathimg_filer   r6  r  r<  templatenameorigr4  s                    r   r?  zClassicPlugin.handleFile  s0   		--	Gqm<
 (l1o??4#5#5doo6I6I#J-1!1O??""OO##M#:G	(()<)<= L**4??+>+>?L		..L26))2K2K  	DOO001G!4!4TYY5J5J!K LKXYdoo))*99%%**11 
1==
(G(GG)-)C)C)+ 6H77==2%&Dx&OPP1 "Xs7G7G7I J LH 8!;<h- 101 1
1 yy00 3**22 1,,W56 7 ))//Kd"1OO$$#dii.E.E99++'+yy'C'C +	 % - 99##1"499#;#;<H&&t':':D&ID??''D$&&t,yfT__5I5I4J!LM 	""4#6#678e  	s6{#	2  	s2w	,1 1@  $3r7##$sU   S .A<T 6T73AU T
,TT
	T4T//T47U		U+U&&U+c                     t        | j                  || j                               t        | j                  | j                               y rN   )r   _getFileHeaderrB  rY  )r.  	file_paths     r   rC  zClassicPlugin.printHeader  s6    $$Y0C0CDE""4#6#678r   c           
         t        |t        j                        rt        t	        d      dt        |j                        |j                  j                  d|j                  j                  z  |j                  |j                  j                  |j                  j                  fz  z          t        | j                  | j                               y y )NzTime: z'%s	MPEG%d, Layer %s	[ %s @ %s Hz - %s ]I)
isinstancer   Mp3AudioInfor   r   r   	time_secs
mp3_headerr6  layerbit_rate_strsample_freqmoderY  rB  )r.  rJ  s     r   rI  zClassicPlugin.printAudioInfo  s    dC,,-Xh'@ 0oo--DOO111''oo114??3G3G	III J T&&t':':;< .r   c                     | j                   r| j                   }n0| j                  }|d| j                  j                  d      d   z  z  }|r||z  }|S )Nz.%s/rW   )r   descriptionrM  rY   )	obj_framesuffixname_strs      r   _getDefaultNameForObjectz&ClassicPlugin._getDefaultNameForObject  sX     ))H ,,H	 3 3 9 9# >q AAAHHr   c                 x   t        |t        j                        
r| j                  j                  rCt        dt        j                  |j                         dt        |j                         d       y t        dt        j                  |j                         d       |j                  r|j                  nd}|j                  r|j                  nd}|j                  r|j                  nd}t        t        d      d|       t        t        d      d|       t        t        d      d|       |j                  r#t        t        d	      d|j                         |j                  r#t        t        d
      d|j                         |j                   r#t        t        d      d|j                          |j"                  df|j$                  df|j&                  df|j(                  df|j*                  dffD ]*  \  }}|s	t        t        |      dt-        |             , d}|j.                  \  }}	|t-        |      }|	r|d|	z  z  }| j                  j0                  s|j2                  n|j4                  }
|
r(t        d       d|
j6                   d|
j8                   dnd}t        t        d       d| d|        |j:                  \  }}|.t-        |      }|r|d|z  z  }t        t        d      d|       |j<                  }|j<                  t        dt        d      |fz         |j>                  D ];  }t        dt        d      |j@                  |jB                  |jD                  fz         = |jF                  }|t        dt        d      |fz         |jH                  }|t        t        d      d|       |jJ                  D ]A  }t        t        d      d |jL                  d!|jN                  jQ                  d"             C |jR                  D ]Z  }t        t        d#      d$|jT                  xs dd%|jV                  jQ                  d&      xs dd'|jX                  xs d       \ |jZ                  D ]V  }t        t        d(      d$|jT                  xs dd%|jV                  jQ                  d&      xs dd'|jX                         X |j\                  D ]2  }t        t        d)      d$|jT                  d'|jX                         4 d*|j^                  fd+|j`                  fd,|jb                  fd-|jd                  fd.|jf                  fd/|jh                  fd0|jj                  fd1|jl                  ffD ]!  \  }}|s	t        t        |      d|       # |jn                  D ]3  }t        |j8                  d2|jT                  d3|jp                         5 |jr                  D ]  }|jt                  tv        jx                  vrwt        d4t        |j{                  |j|                        d5z         t        |j~                        |jt                  fz         t        d6|jT                  z         t        d       t        t        |j{                  |j|                        d5z         d7|jt                  d8|j                  d9       t        d6|jT                  z         t        d       	 |j                  D ]	  }t        d4t        d:      t        |j                        |jt                  fz         t        d6|jT                  z         t        d;|j                  z         t        d<       | j                  j                  s| j                  j                  t        j                  }t        j                  j                  |      st        d=|z        | j                  |      }d>}t        j                  j                  t        j                  j                  ||            r^| j                  |t-        |            }|d>z  }t        j                  j                  t        j                  j                  ||            r^t        d?t        j                  j                  ||      z         t        t        j                  j                  ||      d@      5 }|j                  |j                         d d d         |j                  D ]U  } t        dAt        dB      t        | j                        fz         t        dC| jL                  jQ                  d&      z         W |j                  r,t        dDt        dE      t        |j                        fz         |j                  r$t        dFt        dG      dH|j                         | j                  j                  rt        | j                  | j                               t        dIt        |j                        z         |j                  D ]y  }!|j                  |!   }"t        |"      }#|#d>kD  rdJ|#z  nd}|j                         st        t        dK |"D                    }$ndL}$|$sZt        dM|!jQ                  d&      ||$fz         { t        dN|j                  j                  fz         y y t        dOt-        t        |            z         # 1 sw Y   xY w)PNzID3 : z framesr   rk   r*   r    r&   album artistr5   zoriginal artistrelease dateoriginal release daterecording dateencoding datetagging datez/%dr=   z (id )r,   z		discz%s %dzPlay Count:z,%s [email: %s] [rating: %d] [play count: %d]zPopularity:zBPM:zPublisher/label: zUnique File ID:z [z] : unicode_escapeCommentz: [Description: z	] [Lang: rv   z]
LyricsUserTextFramez
Artist URLzAudio source URLzAudio file URLzInternet radio URLzCommercial URLzPayment URLzPublisher URLzCopyright URLz [Description: z]: z%s: [Size: %d bytes] [Type: %s]z ImagezDescription: %sz	: [Type: z] [URL: ]GEOBzFilename: %s
r7  rW   r8  r9  z%s: [Data: %d bytes]PRIVzOwner Id: %sz
%s: [Data: %d bytes]MCDIz
Terms of Use (USERz): z%d ID3 Frames:z x %dc              3      K   | ]=  }|j                   r/|j                   j                  |j                   j                  z    ? y wrN   )header	data_sizesize)rR   frames     r   rU   z)ClassicPlugin.printTag.<locals>.<genexpr>  s9      &O.3 ',ll&<&<u||?P?P&P &Os   AA   z%s%s (%d bytes)z%d bytes unused (padding)zUnknown tag type: )^rk  r   Tagr   quietr   rK  r6  r\   	frame_setr    r*   r&   r   r(   r5   original_artistr   original_release_dater   r   r   r-  	track_numr@   r=   non_std_genrerd  r   r9   r   r  r   r   countr   r   r   r   uniq_iddecoder   ru  rh   rm   r   r   
artist_urlaudio_source_urlaudio_file_urlinternet_radio_urlcommercial_urlpayment_urlpublisher_urlcopyright_urlr   rs   r   rM  r   rN  picTypeToStringpicture_typerS  	image_urlr   object_datar   r   r   rO  r   r   rP  ry  existsr]   r   r   rR  privatesr   cd_idterms_of_user  rY  rB  isV1sumrX   	file_infotag_padding_size	TypeErrorr.   )%r.  rD  r    r*   r&   date
date_label	track_strr  r0   r=   	genre_strnumtotaldisc_strr   popmr   pubufidclrZ  rg   rs   ur`  objobj_pathobj_filer  r   prx   r   
num_framestotal_bytess%                                        r   rL  zClassicPlugin.printTag&  s	   c377#yy4 3 3CKK @ACDVCWW^_`tC//<=Q?@#&::SZZ2F!$CIIE!$CIIE'!2E:;(!3V<='!2E:;Xn%=%(%5%57 8||Xj%93<<HI""X.?%@#BUBUVW %%~6..0GH'')9:&&8%%~6% K j *)=s4yIJK I'*}}$Y$	N	!44I%)YY%=%=CII3CTCTEPU8G,-R

|5
!L[]I)*"YKtI;GH<<LS%s8-HXf%5x@A J~~)H]$;Z#HHI (( 'G"=14::t{{**&& '' ''CHV$4c#::; --CH-?$@#FG ++ A!"34dmm,,-=>@ AA \\ G"9-q}}/B/B&&--06B6"F GG ZZ A"8,amm.Ar.A&&--06B6@ AA )) M"?3Q]]AFFL MM
  ,S^^<133G3GH/1C1CD3S5K5KL/1C1CD,coo>.0A0AB.0A0AB 
?	c $=>
? (( ?qttQ]]78uu> ??
 zz !==
(G(GG>!#"5"5c6F6F"G"*#+ ,CNN+'' (
 .@ARL!#"5"5c6F6F"G"*#+ ,s}}6 7 .@ARL!$ {{ 2:"6*C,@--)) * *S__<=#,,6799..)-)D)DbffMH77==2%&Dx&OPP#<<SAHE''..h)IJ#'#@#@ADU$M
 ''..h)IJ !277<<@H4J "J Kbggll8X>E 212 2'2. \\ F/8F3C36qvv;3@ @ A!***;*;G*DDEF yy1Xf5E58^5E E F hv6F696F6FH I yy  **4+>+>?@)C,>>?== KC ]]3/F!$VJ4>NGj0E88:&) % &O7=&O !O'P ')" !2cjj6I6;[6J "J KK 4--88;< =! !& 03tCy>ABBO2 2s   l//l9	c                    d}d}d}| j                   j                  rt        j                  }d}nQ| j                   j                  rt        j
                  }d}n(| j                   j                  rt        j                  }d}|r_t        j                  j                  |j                  j                  || j                   j                        }t        d| d	|rd
nd        |S )Nr   Frk   zv1.x and/or v2.xzv1.xzv2.x)r  zRemoving ID3 z tag: SUCCESSFAIL)r   r  r   r(  r  r'  r
  r)  r  remover  rd  r  r   )r.  rD  remove_versionstatusrm_strs        r   rE  zClassicPlugin.handleRemoves  s    99 00N'FYY   ZZNFYY   ZZNFWW^^CMM$6$67;yy7S7S $ UF=FyPV6WXYr   c                 v    | j                   j                  }||du ry|j                  j                  }||kD  }|S )NTF)r   r  r  r  )r.  rD  r  paddingneeds_changes        r   rH  zClassicPlugin.handlePadding  s@    ii+++"5--00,r   c                    d}d| j                   j                  t        j                  j                  fd| j                   j
                  t        j                  j                  fd| j                   j                  t        j                  j                  fd| j                   j                  t        j                  j                  ffD ]6  \  }}}|s
|j                  |   st        d|z         |j                  |= d}8 | j                   j                  r.|j                  D ]  }t        d|z         |j                  |= d}! d	t        |j                   | j                   j"                        fd
t        |j$                  | j                   j&                        fdt        |j(                  | j                   j*                        fdt        |j,                  | j                   j.                        fdt        |j0                  | j                   j2                  | j                   j4                         fdt        |j6                  | j                   j8                        fdt        |j:                  | j                   j<                        fdt        |j>                  | j                   j@                        fdt        |jB                  | j                   jD                        fdt        |jF                  | j                   jH                        fdt        |jJ                  | j                   jL                        fdt        |jN                  | j                   jP                        fdt        |jR                  | j                   jT                        fdt        |jV                  | j                   jX                        ffD ]<  \  }}|j                   d   t        d|d|j                   d           |        d}> d }t[        j\                  | j                   j^                  | j                   j`                  | j                   jb                        }|s$te        jf                  |      dk7  r#|jh                  rt        d|        ||_4        d} ||jj                  | j                   jl                  | j                   jn                  f      }	|	 t        dtq        |	      z         |	|_5        d}| j                   jr                  rc| j                   jr                  }
|jj                  d   |
z   |jj                  d   f|_5        t        d |
dkD  rd!nd"|
|jj                  d   fz         d} ||jt                  | j                   jt                  | j                   jv                  f      }| t        d#tq        |      z         ||_:        d}| j                   jx                  :| j                   jx                  }t        d$|        |rt{        |      nd |_        d}| j                   j|                  rJ| j                   j~                  j                  | j                   j|                  d%t        j                  f       d&| j                   j                  |j~                  fd| j                   j                  |j                  fd'| j                   j                  |j                  fd(| j                   j                  |j                  ffD ]y  \  }}}|D ]n  }t        |      tp        u r|j                  |      }n |j                  | }|rt        d)|d*tq        |             d}Tt        d+|d,tq        |      d-       p { d&| j                   j~                  |j~                  fd| j                   j                  |j                  ffD ]M  \  }}}|D ]B  \  }}}t        d|d|d.tq        |d/             |j                  ||t        |             d}D O | j                   j                  }|rB|\  }}|r$t        d0|z         |xj                  |z  c_N        nt        d1|z         ||_N        d}| j                   j                  D ]4  \  }}}|j                  j                  |j                  d2      ||       d}6 | j                   j                  D ]1  }|j                  j                  |j                  d2            }|s0d}3 d3| j                   j                  |j                  fd4| j                   j                  |j                  ffD ]D  \  }}}|D ]9  \  }}|rt        d|d*|d5|d6       nt        d+|d*|        |||       d}; F d7| j                   j                  |j                  fd8| j                   j                  |j                  ffD ]^  \  }}}|D ]S  \  }}|r(t        d9| d:| d5| d6       |j                  ||       n"t        d;| d:|        |j                  |       d}U ` | j                   j                  D ]  \  }}}}|sJ t        d<|z         |t        j                  vrBt        |d=      5 }|j                  j                  ||j                         ||       d d d        n |j                  j                  |d d ||>       d} | j                   j                  xs g D ]\  \  } }!}"}#| sJ t        d?| z         t        | d=      5 }$|j                  j                  |$j                         |!|"|#       d d d        d}^ | j                   j                  D ]  }|\  }%}&|&s;|j                  j                  |%      rt        d@|%z         d}6t        dA|%z         E|j                  j                  |&|%j                  d2             t        dB|%dC|&       d} | j                   j                  D ]2  }t        |t              sJ ||j                  v s$|j                  |= d}4 |S # 1 sw Y   oxY w# 1 sw Y   xY w)DNFr   r   r   r   zRemoving all %s...TzRemoving unknown (%s)...r    r&   r|  r*   r=   )id3_stdr}  r~  r  r  r  zbeats per minuter   r5   zorig-artistr   zSetting r{  c                     d }|d| fvr5d gdz  }dD ]  }||   dk(  rd ||<   ||   xs | |   ||<   ! t        |      }|S )N)NNrV   )r   rW   r   )rX   )currnewnr   s       r   _checkNumberedArgTuplesz:ClassicPlugin.handleEdits.<locals>._checkNumberedArgTuples7  sh    A<..FQJ 1A1v{#!"1v0a!	1
 !HHr   )NNNzSetting artist origin: zSetting track info: %srW   z%s track info by %d: %dIncrementingDecrementingzSetting disc info: %szSetting release year: rk   commentimageobjectzRemoved r  z	Removing z	 failed, z
 not foundrt  rv   zIncrement play count by %dzSetting play count to %drp   z
text framez	url framez to 'r>  zuser text framezuser url framez	Setting 'z' z
Removing 'zAdding image %srb)img_urlzAdding object %szRemoved unique file ID '%s'zUnique file ID '%s' not foundzSetting unique file ID 'z' to )`r   r   r   r   COMMENT_FIDr   
LYRICS_FIDr   	IMAGE_FIDr  
OBJECT_FIDr  r   r   unknown_frame_idsr   
_setArtistr    	_setAlbumr&   _setAlbumArtistr(   	_setTitler*   	_setGenrer=   r@   _setReleaseDater   _setOrigReleaseDater   _setRecordingDater   _setEncodingDater   _setTaggingDater   _setBpmr   _setPublisherr   _setComposerr5   _setOrigArtistr7   r   ArtistOriginartist_cityartist_stateartist_countrydataclassesastupleartist_originr  r,   r0   r-  r2   r9   r;   rD   r   rG   r   r   re   r   r   r   r   r   r   r   r.   r  r   setr
   r   r  rr   r  r   setTextFramer   _setUrlFramer   r   r   rN  r   r   r   r  rk  bytes)'r.  rD  retvalwhatr^   rx   setFuncr  origin
track_infooffset	disc_infoyearaccessorrf   r  rm   rg   rh   playcount_argr   r   r   r   r   r  setterra  img_typeimg_mtimg_descimg_fpr  obj_mtobj_desc	obj_fnameobj_fpr   r   s'                                          r   rG  zClassicPlugin.handleEdits  s1    !+DII,I,I #

 6 6 8 ($))*E*E #

 5 5 7 ($))*E*E #

 4 4 6 )499+G+G #

 5 5 7! 	ND#s s}}S)1D89MM#&	 99'',, 7#=>MM#& 73>>4993C3CDE'#--AB)<)<)-)?)?"A B'#--AB'#--.2ii.F.F*FH I)<)<)-)?)?"A B('#2I2I26))2M2M+O P!73+@+@+/99+C+C$E F '#*>*>*.))*A*A#C D)<)<)-)?)?"A B#WS[[$))--%HIgc&7&79L9LMNWS%5%5tyy7I7IJK(:(:DII<Q<Q RS+  	OT7. ||A*w||AGH	5	8	 ""499#8#8#'99#9#9#'99#;#;= k))&15GGCL]L]26(;< &CF -S]].2iioo.2ii.C.C.EF
 !1C
OCD&CMF 99!!YY++F ]]1-6a8HICM2,2QJ.Nq!133 4 F ,CLL-1YY-?-?-1YY-A-A-CD	  03y>AB$CLF 99!!-99))D1$89,0s4ydCF 99##II%%tyy'?'?'*'7'7'9 : &/		0H0H%(\\%3%-tyy/F/F%(ZZ%1%,dii.D.D%(ZZ%1%-tyy/F/F%([[%2$% 	2D#x  
2:$$OOD1E+HOOT2E D#d)!DE!F $c$i 1 2
2	2, &/		0B0B%(\\%3%-tyy/?/?$L$% 	D#x %(  dD"D#dG*<> ?T441			 		,,)MIr9B>?"$7"<=!#F *.)?)? 	%E6:  h!7LF	
 YY00 	E##**5<<+ABD	 tyy44c6F6FGdii22C4D4DE" 
	D#v ! 	T Ct!LM S$!?@sD!	
	 #DII$>$>%%'!499#<#<$$&$ 	D#x " 
d 9TF"TF%vQ!GHLLt, :dV2dV!<=OOD)	  59II4D4D 	0HhO8*X56Z<<<(D) NVJJNN8V[[]FHMN N 

xtXxPF	 6:YY5F5F5L" 	1Hfh	O8+h67h% LvxKLF	 99,, 	CLHb&&--h7 !>!IJ!F !@8!KL##''HOOH,EF'- .	 99(( 	Cc5)*)cmm#MM#&		 IN NL Ls   =-p8-q8q	q	)rk   )__name__
__module____qualname__SUMMARYr   NAMESr!  r?  rC  rI  staticmethodry  rL  rE  rH  rG  __classcell__)r4  s   @r   r   r      s]    EGK KELC\W9r9	=  |C|*sr   r   c                      t        t        j                  d      j                  d d      j	                               } | j                          dj                  | D cg c]  }d|z  	 c}      S c c}w )Nrk   F, z$%s)listr   r<  _makeMappingkeyssortr]   )r  vs     r   _getTemplateKeysr    sU    #00u=BBDEDIIK99.Aeai.//.s   A/r   zSet the artist name.r%   zSet the album name.r'   zSet the album artist name. '%s', for example. Another example is collaborations when the track artist might be 'Eminem featuring Proof' the album artist would be 'Eminem'.r)   zSet the track title.r+   z%Set the track number. Use 0 to clear.r/   z+Set total number of tracks. Use 0 to clear.r8   z$Set the disc number. Use 0 to clear.r:   z1Set total number of discs in set. Use 0 to clear.r<   zSet the genre. If the argument is a standard ID3 genre name or number both will be set. Otherwise, any string can be used. Run 'eyeD3 --plugin=genres' for a list of standard ID3 genre names/ids.r?   zDisables certain ID3 genre standards, such as the mapping of numeric value to genre names. For example, genre=1 is taken literally, not mapped to 'Classic Rock'.rC   znSet the year the track was released. Use the date options for more precise values or dates other than release.r   zwOnly read and write ID3 v1.x tags. By default, v1.x tags are only read or written if there is not a v2 tag in the file.r   zZOnly read/write ID3 v2.x tags. This is the default unless the file only contains a v1 tag.r   zGConvert the file's tag to ID3 v1.1 (Or 1.0 if there is no track number)r   z"Convert the file's tag to ID3 v2.3r   z"Convert the file's tag to ID3 v2.4r   z)Set the date the track/album was releasedr   z2Set the original date the track/album was releasedr   z)Set the date the track/album was recordedr   z!Set the date the file was encodedr   z Set the date the file was taggedrF   z{Set a comment. In ID3 tags this is the comment with an empty description. See --add-comment to add multiple comment frames.r   zAdd or replace a comment. There may be more than one comment in a tag, as long as the DESCRIPTION and LANG values are unique. The default DESCRIPTION is '' and the default language code is '%s'.rv   r   zPRemove comment matching DESCRIPTION and LANG. The default language code is '%s'.r   z!Remove all comments from the tag.r   z'Remove all unknown frames from the tag.r   zAdd or replace a lyrics. There may be more than one set of lyrics in a tag, as long as the DESCRIPTION and LANG values are unique. The default DESCRIPTION is '' and the default language code is '%s'.r   zORemove lyrics matching DESCRIPTION and LANG. The default language code is '%s'.r   zRemove all lyrics from the tag.r   zSet the publisher/label namer   zSet the number of times played counter. If the argument value begins with '+' the tag's play count is incremented by N, otherwise the value is set to exactly N.r   zSet the beats per minute value.r   zmSet the value of a text frame. To remove the frame, specify an empty value. For example, --text-frame='TDRC:'r   zSet the value of a user text frame (i.e., TXXX). To remove the frame, specify an empty value. e.g., --user-text-frame='SomeDesc:'r   zdSet the value of a URL frame. To remove the frame, specify an empty value. e.g., --url-frame='WCOM:'r   zSet the value of a user URL frame (i.e., WXXX). To remove the frame, specify an empty value. e.g., --user-url-frame='SomeDesc:'r   a"  Add or replace an image. There may be more than one image in a tag, as long as the DESCRIPTION values are unique. The default DESCRIPTION is ''. If PATH begins with 'http[s]://' then it is interpreted as a URL instead of a file containing image data. The TYPE must be one of the following: r  rW   .r   z"Remove image matching DESCRIPTION.r   zRemove all images from the tagr   zRCauses all attached images (APIC frames) to be written to the specified directory.r   zAdd or replace an object. There may be more than one object in a tag, as long as the DESCRIPTION values are unique. The default DESCRIPTION is ''.r   z#Remove object matching DESCRIPTION.r   zRemove all objects from the tagr   zSCauses all attached objects (GEOB frames) to be written to the specified directory.r  a  Adds a pupularity metric. There may be multiples popularity values, but each must have a unique email address component. The rating is a number between 0 (worst) and 255 (best). The play count is optional, and defaults to 0, since there is already a dedicated play count frame.r  z:Removes the popularity frame with the specified email key.r  zRemove ID3 v1.x tag.r	  zRemove ID3 v2.x tag.r  zRemove ID3 v1.x and v2.x tags.r  zQRemove all frames with the given ID. This option may be specified multiple times.r  zShrink file if tag padding (unused space) exceeds the given number of bytes. (Useful e.g. after removal of large cover art.) Default is 64 KiB, file will be rewritten with default padding (1 KiB) or max padding, whichever is smaller.z!Disable --max-padding altogether.z4Rewrite the tag despite there being no edit options.zShow all available tag datazAdd a unique file ID frame. If the ID arg is empty the frame is removed. An OWNER_ID is required. The ID may be no more than 64 bytes.zSet the encoding that is used for all text frames. This option is only applied if the tag is updated as the result of an edit option (e.g. --artist, --title, etc.) or --force-update is specified.zcRename file (the extension is not affected) based on data in the tag using substitution variables: z4When writing, do not update file modification times.z\Increment/decrement the track number by [-]N. This option is applied after --track=N is set.zSet the composer's name.zeSet the orignal artist's name. For example, a cover song can include the orignal author of the track.)
r  r  r  r   r  rI   r  r1   r4   r6   ),r   rO   r  	functoolsr   argparser   eyed3.pluginsr   eyed3r   r   r   eyed3.utilsr	   r
   r   eyed3.utils.consoler   r   r   r   r   eyed3.id3.framesr   eyed3.mimetyper   eyed3.utils.logr   r  logrQ   rT  r   r  VARIOUS_ARTISTSr-  re   r]   rangeMIN_TYPEMAX_TYPEr  r$  )r`   s   0r   <module>r.     s   	 	   & &     9 9  ( ( % \L \~0X*X(X 	 @ ..	/X 	)X 	:X 	FX 	<X 	KX 	 3X" 	 X#X( 	 *)X0 	 M1X4 	 35X: 	 (;X> 	9?X@ 	9AXD 	EEXF 	  *GXJ 	GKXL 	>MXN 	<OXR 	 'SXX 	M c
()[Xb 	 A 0 0':;cXh 	 !DiXl 	 ImXp 	 (('23sXz 	 A 0 0':;{X@ 	@AXD 	5EXF 	 %GXN 	2OXR 	 /SXX 	 CYX^ 	 K_Xb 	 AcXj 	 ))-2:3F3F3=3F3F3J.L%M() &@Z%?%?%B %M N	kX~ 	>X@ 	?AXB 	 @CXH 	 EIXN 	@OXP 	 AQXR 	 ASXX 	 CYXd 	  6eXj 	-kXl 	-mXn 	8oXr 	 =sXx 	 'yXD @%2MH"$4$67"7K0<mX	v%Ms   )G