
    M@c                         d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZmZmZmZmZ i a ee      ZddZ G d dej*                        Z G d	 d
e      Zy)    N)coreutils)	getLogger)guessMimetype
formatSize)printMsg
printErrorHEADER_COLORboldTextForec                 6   t        t        t        j                                     r|s	 | r	t        |    S t        S i ad }t
        j                  d|        t        j                  j                  t              g|r|ng z   D ]H  }t
        j                  d| d       t        j                  j                  |      s=|t        j                  vrt        j                  j                  |       	 t        j                  |      D ]  } |||      st        j                  j                  |      d   }	 t!        |t#               t%                     }t/        |      D 	cg c]  }	t1        ||	       c}	D ]  }
t3        |
      t2        k(  st5        |
t6              s(|
}|t        t        j9                               vsJt        |j:                        s`t
        j                  d| d| t        j                  j<                   | d       |j:                  d   }|t        |<   |j:                  dd	 D ]  }|t        |<    | s| |j:                  v s|c c |t        j                  v r"t        j                  j?                  |       c S c S   	 |t        j                  v s*t        j                  j?                  |       K t
        j                  dt                | ry	t        S # t        $ r i aY w xY w# t&        $ r(}t
        j)                  d||f d|        Y d	}~+d	}~wt*        $ r t
        j-                  d
||f        Y Tw xY wc c}	w # |t        j                  v r t        j                  j?                  |       w w xY w)a5  Returns the eyed3.plugins.Plugin *class* identified by ``name``.
    If ``name`` is ``None`` then the full list of plugins is returned.
    Once a plugin is loaded its class object is cached, and future calls to
    this function will returned the cached version. Use ``reload=True`` to
    refresh the cache.c                     t        t        j                  j                  t        j                  j	                  ||             xr | d   dvxr | j                  d            S )z2Determine if file `f` is a valid module file name.r   )_.z.py)boolospathisfilejoinendswith)fds     8/usr/lib/python3/dist-packages/eyed3/plugins/__init__.py_isValidModulezload.<locals>._isValidModule!   sU    
 BGGNN277<<1#56 AaD
*A/0zz%/@B 	B    zExtra plugin paths: zSearching 'z' for pluginsr   )globalslocalszPlugin z+ requires packages that are not installed: NzBad plugin zloading plugin 'z' from ''   zPlugins loaded: ) lenlist_PLUGINSkeysKeyErrorlogdebugr   r   dirname__file__isdirsysappendlistdirsplitext
__import__r   r   ImportErrorverbose	Exception	exceptiondirgetattrtype
issubclassPluginvaluesNAMESsepremove)namereloadpathsr   r   r   mod_namemodexaattrPluginClass	main_namealiass                 r   loadrG      s    4 !&	%)8D>7x7
 B II$UG,-ggooh'(UEC ,#		Ks-01ww}}QCHHHHOOA%	#ZZ]  3%a+77++A.q1$XwyRC 7:#h?WS!_? 3DDzT)jv.F&*'tHOO4E/FF #K$5$5 6II(8XaSVWUXXY&Z[ )4(9(9!(<I2=HY/)4):):12)> >2=>
  $0A0A(A'2 2 CHH}" +3 3F CHH}"Y,#\ II 
+,OC  	H	< # KK'1a&1\]_\` ab  MMKAx"89 @* CHH}" s   
K4 K4 2AM$8LM$#M6M$M$!!M$M$A/M$	M$M$M$4LL	ML2,M$2&MM$MM$$4Nc                   T    e Zd ZdZdZdZg Zd Zd Zd Z	d Z
ed        Zed	        Zy
)r7   z Base class for all eyeD3 pluginszeyeD3 plugin c                 r    || _         |j                  d| j                   d| j                         | _        y )NzPlugin options
)
arg_parseradd_argument_groupSUMMARYDESCRIPTION	arg_group)selfrL   s     r   __init__zPlugin.__init__k   s8    $#667G:>,,r$JZJZI[7\^r   c                      || _         || _        y)zCalled after command line parsing but before any paths are
        processed. The ``self.args`` argument (the parsed command line) and
        ``self.config`` (the user config, if any) is set here.N)argsconfig)rQ   rT   rU   s      r   startzPlugin.startp   s     	r   c                      y )N )rQ   r   s     r   
handleFilezPlugin.handleFilew   s    r   c                      y)zCalled after all file/directory processing; before program exit.
        The return value is passed to sys.exit (None results in 0).NrX   rQ   s    r   
handleDonezPlugin.handleDonez   s     	r   c                     d| z  S )N-rX   )widths    r   _getHardRulezPlugin._getHardRule   s    U{r   c                    t        j                  |       } | j                         j                  }t	        |       }t        |      }t        |      dz   }t        |      |z   |k\  rdt	        |       d|z
   d  z   }|t        |      z
  |z
  }dj                  t        |t                     t               d|z  |t        j                        S )N   z...K   z'{path}{color}{padding}[ {size} ]{reset})c )r   colorpaddingsizereset)pathlibPathstatst_sizestrr   r    formatr   r
   r   RESET)r   r_   	file_sizepath_strsize_strsize_lenpadding_lens          r   _getFileHeaderzPlugin._getFileHeader   s    ||D!IIK''	t9i(x=1$x=8#u,s4y2=)9):;;Hc(m+h68HX@)^"[0$!ZZ	  )	)r   N)__name__
__module____qualname____doc__rN   rO   r9   rR   rV   rY   r\   staticmethodr`   rv   rX   r   r   r7   r7   _   sW    * G K E^

   ) )r   r7   c                   6     e Zd ZdZd fd	Zd Zd Zd Z xZS )LoaderPluginz6A base class that provides auto loading of audio filesc                 l    t         |   |       d| _        |rg nd| _        |rg nd| _        d| _        y)zConstructor. If ``cache_files`` is True (off by default) then each
        AudioFile is appended to ``_file_cache`` during ``handleFile`` and
        the list is cleared by ``handleDirectory``.r   N)superrR   _num_loaded_file_cache_dir_images
audio_file)rQ   rL   cache_filestrack_images	__class__s       r   rR   zLoaderPlugin.__init__   s9     	$!,2$!-24r   c                    	 t        j                  |g|i || _        | j                  rH| xj                  dz  c_        | j                  &| j                  j                  | j                         yy| j                  <t        |      }|r.|j                  d      r| j                  j                  |       yyyy# t        $ r}t	        t        |             Y d}~yd}~ww xY w)a  Loads ``f`` and sets ``self.audio_file`` to an instance of
        :class:`eyed3.core.AudioFile` or ``None`` if an error occurred or the
        file is not a recognized type.

        The ``*args`` and ``**kwargs`` are passed to :func:`eyed3.core.load`.
        Nr   zimage/)r   rG   r   NotImplementedErrorr	   rn   r   r   r+   r   r   
startswith)rQ   r   rT   kwargsrA   mts         r   rY   zLoaderPlugin.handleFile   s    	"ii;D;F;DO ??!+  ''8 ,)q!BbmmH-  ''* .r * # 	s2w	s   B= =	C$CC$c                 R    | j                   g | _         | j                  g | _        yy)zOverride to make use of ``self._file_cache``. By default the list
        is cleared, subclasses should consider doing the same otherwise every
        AudioFile will be cached.N)r   r   )rQ   r   r   s      r   handleDirectoryzLoaderPlugin.handleDirectory   s1     '!D'!D (r   c                 :    | j                   dk(  rt        d       yy)zAIf no audio files were loaded this simply prints 'Nothing to do'.r   zNo audio files found.N)r   r   r[   s    r   r\   zLoaderPlugin.handleDone   s    q ,- !r   )FF)	rw   rx   ry   rz   rR   rY   r   r\   __classcell__)r   s   @r   r}   r}      s    @+0".r   r}   )NFN)r   r*   rj   eyed3r   r   eyed3.utils.logr   eyed3.utilsr   r   eyed3.utils.consoler   r	   r
   r   r   r"   rw   r%   rG   FileHandlerr7   r}   rX   r   r   <module>r      sR    	 
   % 1 R RM`4)U 4)n2.6 2.r   