U
    3ìdª  ã                   @   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ÚnameÚsdÚ
has_optionÚgetÚcommandr   r   Ú	mimetypesÚguess_extensionÚget_objr   r   Úinput_queueÚreadÚqueue_files)ÚselfÚconfig_fileÚm©Ú	__class__© ú:/tmp/pip-unpacked-wheel-d7dsrkjd/boto/services/sonofmmm.pyr      s     zSonOfMMM.__init__c                 C   sl   t j d| jj ¡ | jD ]L}t j d|j ¡ tƒ }| jrJd| jji}nd }| ||¡ | j 	|¡ q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ÚbaseÚextZout_file_namer   Ú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$   r2   L   s
    zSonOfMMM.shutdown)N)Ú__name__Ú
__module__Ú__qualname__r   r   r0   r2   Ú__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
   