B
    è?F[ª  ã               @   sD   d dl Z d dlmZ d dlmZ d dlZd dlZG dd„ deƒZdS )é    N)ÚService)ÚServiceMessagec                   s:   e Zd Zd
‡ fdd„	Zdd„ Zdd„ Z‡ fdd	„Z‡  ZS )ÚSonOfMMMNc                sÖ   t t| ƒ |¡ d| j | _tj | j| j¡| _	t
 | j| j	¡ | j d¡r`d| j d¡ | _nd| _| j d¡| _| j d¡r| j d¡| _nt | j¡| _| j d¡| _| j d¡| _| j d	¡}|sÒ|  ¡  d S )
Nz%s.logZffmpeg_argsz/usr/local/bin/ffmpeg z!/usr/local/bin/ffmpeg -y -i %s %sÚoutput_mimetypeÚ
output_extÚoutput_bucketÚinput_bucketé   )Úsuperr   Ú__init__Zinstance_idÚlog_fileÚosÚpathÚjoinÚworking_dirÚlog_pathÚbotoZset_file_loggerÚnameZsdZ
has_optionÚgetÚcommandr   r   Ú	mimetypesZguess_extensionZget_objr   r   Úinput_queueÚreadÚqueue_files)ÚselfZconfig_fileÚm)Ú	__class__© ú5lib/python3.7/site-packages/boto/services/sonofmmm.pyr      s     zSonOfMMM.__init__c             C   sp   t j d| jj ¡ xV| jD ]L}t j d|j ¡ tƒ }| jrLd| jji}nd }| ||¡ | j 	|¡ qW d S )NzQueueing files from %szQueueing %sZOutputBucket)
r   ÚlogÚinfor   r   r   r   Zfor_keyr   Úwrite)r   Úkeyr   Údr   r   r   r   4   s    zSonOfMMM.queue_filesc             C   sj   t j |¡\}}t j | j|| j ¡}| j||f }tj 	d| ¡ |  
|¡}|dkrb|| jfgS g S d S )Nzrunning:
%sr   )r   r   Úsplitextr   r   r   r   r   r   r    Úrunr   )r   Zin_file_nameÚmsgÚbaseZextZout_file_namer   Zstatusr   r   r   Úprocess_file@   s    

zSonOfMMM.process_filec                s@   t j | j¡r.| jr.| j | j¡}| | j¡ tt	| ƒ 
¡  d S )N)r   r   Úisfiler   r   Znew_keyr   Zset_contents_from_filenamer
   r   Úshutdown)r   r"   )r   r   r   r*   L   s
    zSonOfMMM.shutdown)N)Ú__name__Ú
__module__Ú__qualname__r   r   r(   r*   Ú__classcell__r   r   )r   r   r      s   r   )r   Zboto.services.servicer   Zboto.services.messager   r   r   r   r   r   r   r   Ú<module>   s
   