Ñò
yÞKc           @   sœ  d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k l Z l	 Z	 d d k
 l Z l Z l Z l Z l Z l Z d d k Td Z d Z d Z e Z d	 d d
 „  ƒ  YZ e d j oÄ d d k l Z e ƒ  Z e i d d d d d d d d ƒe i ƒ  \ Z Z e i  oE e i! i" e i  ƒ p e i  Gd GHd GHe# d ƒ n d Ge i  GHn d GHd Ge GHe ƒ  i$ e e i  ƒ n d S(   s1   
Class and methods to convert video for the fuze
iÿÿÿÿN(   t
   check_callt   call(   t
   QT_TR_NOOPt   SIGNALt   QObjectt   QStringt   QVariantt	   QSettings(   t   *s  mencoder -msglevel all=0:statusline=5 -ffourcc DX50 -ofps 20 -vf pp=li,expand=:::::224/176,scale=224:176,harddup     -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=683:vmax_b_frames=0:keyint=15:turbo:vpass=1 -srate 44100 -af resample=44100:0:1,format=s16le -oac mp3lame -lameopts cbr:br=128s  mencoder -msglevel all=0:statusline=5 -ffourcc DX50 -ofps 20 -vf pp=li,expand=:::::224/176,scale=224:176,harddup     -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=683:vmax_b_frames=0:keyint=15:vpass=2 -srate 44100 -af resample=44100:0:1,format=s16le -oac mp3lame -lameopts cbr:br=128sì   mencoder  -msglevel all=0:statusline=5 -ofps 20 -ovc lavc -lavcopts vcodec=mpeg4:vqscale=3:keyint=15  -vf field,expand=:::::224/176,scale=224:176,harddup -srate 44100 -af resample=44100:0:1,format=s16le -oac mp3lame -lameopts cbr:br=128t   Fuzec           B   s/   e  Z d  Z d d „ Z d „  Z d d „ Z RS(   s\   
    This class implements a convert() method used to convert video files for the fuze.
    c         C   sÑ  | |  _  t i ƒ  |  _ t ƒ  |  _ |  i  o® |  i i |  i t d ƒ | i ƒ |  i i |  i t d ƒ | i	 ƒ |  i i |  i t d ƒ | i
 ƒ |  i i |  i t d ƒ | i ƒ |  i i |  i t d ƒ | i ƒ n |  i ƒ  d  |  _ t i ƒ  |  _ t i d j o: t i i |  i d ƒ |  _ t i i |  i d ƒ |  _ n† d	 |  _ d
 |  _ t i d j oJ |  i  d  j o: t i d ƒ } | d d j o | d |  _ qÍd GHn |  i  d  j o	 d GHn d  S(   Nt   stopt   workingt	   Exceptiont   itemDonet   finishedt   nts
   ffmpeg.exes   fuzemux.exet   ffmpegt   fuzemuxt   posixs   which xtermi    i   s   xterm not founds   No terminal emulator available(   t   GUIt   ost   getcwdt   CWDR   t   qobjectt   connectR   t   WAITt   Statust	   ErrorDiagt   DelItemt   getReadyt   LoadSettingst   Nonet   xtermt   tempfilet
   gettempdirt   fuzemuxPrefixt   namet   patht   joint   FFMPEGR   t   commandst   getstatusoutput(   t   selfR   t   termloc(    (    s>   /home/ken/Programs/video4fuze/0.6+/src/video4fuze-0.6+/fuze.pyt   __init__   s0    	
""""&
			 	c         C   s  t  t  i t  i t i t i ƒ |  _ t |  i i d t	 t
 ƒ ƒ i ƒ  ƒ |  _
 t |  i i d t	 t ƒ ƒ i ƒ  ƒ |  _ t |  i i d t	 t ƒ ƒ i ƒ  ƒ |  _ |  i i d t	 t ƒ ƒ i ƒ  |  _ d GHH|  i o! d GHd G|  i
 GHd G|  i GHn d	 GHd
 G|  i GHd S(   s?   
        Loads video4fuze's settings for this instance
        t   mencoderpass1t   mencoderpass2t   mencodersinglepasst   2passs   Current settings:s   Two-pass conversion;s   Pass 1: s   Pass 2: s   Single-pass conversion;s   Options used: N(   R   t	   IniFormatt	   UserScopet   infot   ORGNAMEt   NAMEt   Settingst   unicodet   valueR   R-   t   toStringR.   R/   t   pass2t   toBool(   R*   (    (    s>   /home/ken/Programs/video4fuze/0.6+/src/video4fuze-0.6+/fuze.pyR   6   s    $***$
c         C   sÿ  |  i  o# |  i i t d ƒ |  i  i ƒ n xË| D]Ã} t i i | ƒ } t i |  i	 ƒ | GHt i i
 | ƒ oCt i d j o< t i i |  i	 t i i t i i | ƒ ƒ d d ƒ } nZ t i d t i i |  i	 i d ƒ t i i t i i | ƒ ƒ d d ƒ ƒ i d d ƒ } yÄ |  i o d	 GHt |  i ƒ } n d
 GH|  i } |  i i t d ƒ d | d ƒ |  i d$ j o |  i d | } n | i ƒ  } | i | ƒ | i d ƒ | i | ƒ d G| Gd GHt | ƒ Wn6 t j
 o* } | GH|  i i t d ƒ | ƒ q4 n X|  i oØ y› d GHt |  i ƒ } |  i i t d ƒ d | d ƒ |  i d$ j o |  i d | } n | i ƒ  } | i | ƒ | i d ƒ | i | ƒ t | ƒ Wqøt j
 o* } | GH|  i i t d ƒ | ƒ q4 qøXn | d$ j o t i i | ƒ d d } n6 t i i | t i i t i i | ƒ ƒ d ƒ d } yž |  i }	 t i i | ƒ d d }
 |  i i t d ƒ d |	 ƒ |  i d$ j o |  i d |	 }	 n |	 i ƒ  }	 |	 i | ƒ |	 i |
 ƒ d GHt |	 ƒ WnC t j
 o7 } | GH|  i i t d ƒ | ƒ t i  |
 ƒ q4 n Xd |
 d | d GH| GHyð yz |  i i t d ƒ d ƒ d GHt i t i i | ƒ d ƒ t! |
 t i i t i i | ƒ ƒ d d g  t" t# |  i$ ƒ Wn9 t j
 o- } | GH| ‚ |  i i t d ƒ | ƒ n Xt% i& |
 | ƒ |  i i t d ƒ | ƒ t i  | ƒ Wn8 t j
 o, } | GHd GH|  i i t d ƒ | ƒ n X|  i  o( |  i i t d  ƒ |  i  i ƒ d! GHqçn1 d" | d" d# } |  i i t d ƒ | ƒ | GHt i |  i' ƒ q4 Wd$ S(%   so   
        This method converts any video file passed as argument to a file suitable for the sansa fuze.
        R
   R   i    s	   .temp.avit   NFKDs   utf-8t   asciit   ignores   Calling mencoder #1s!   Calling a single pass of mencoderR   s   Using mencoder on s   ...s    -e s   -os
   
Executings   
R   s   Calling mencoder #2s    (pass 2)...s	   _fuze.avis   _fuzemuxed.avis   Using s   Calling fuzemuxs   Moving s    to s    and cleaning temporary filess   Creating video thumbnailid   R   s   Ooops not moving final videoR   s	   Finished!s   's   : file not foundN((   R   R   t   emitR   t   VideoR   R%   t   abspatht   chdirR#   t   isfileR$   R&   t   splitextt   basenamet   unicodedatat	   normalizet   decodet   encodeR:   R7   R-   R/   R    R   t   splitt   appendR    R   t   strR.   R   t   removet
   find_thumbt   Truet   FalseR'   t   shutilt   moveR   (   R*   t   argst   FINALPREFIXt   argumentt   OUTPUTR-   t   eR.   t   FINALR   t   fuzemux_tempt   error(    (    s>   /home/ken/Programs/video4fuze/0.6+/src/video4fuze-0.6+/fuze.pyt   convertI   s¶    
# <Y
	!
!5	?
N(   t   __name__t
   __module__t   __doc__R   R,   R   R[   (    (    (    s>   /home/ken/Programs/video4fuze/0.6+/src/video4fuze-0.6+/fuze.pyR	      s   	t   __main__(   t   OptionParsers   -os   --outputdirt   destt	   outputdirt   helps%   save the converted files to OUTPUTDIRt   metavart	   OUTPUTDIRs   is not a directory!s   Aborting...i   s   Output directory:s    Output directory: same as sources   Files to convert:(    (%   R^   R   R!   RQ   R(   RF   R3   t
   subprocessR    R   t   PyQt4.QtCoreR   R   R   R   R   R   t   vthumbR-   R.   R/   RP   R:   R	   R\   t   optparseR`   t   parsert
   add_optiont
   parse_argst   optionsRS   Rb   R%   t   isdirt   exitR[   (    (    (    s>   /home/ken/Programs/video4fuze/0.6+/src/video4fuze-0.6+/fuze.pyt   <module>   s0   <.
œ	"
	