o
    ee                     @   s   d Z 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 ddl
mZ ddl
mZ dd	l
mZ dd
l
mZ ddlmZ ddlmZ ddlmZ ddlmZ eeZG dd deZdS )z0
This module provides a client class for Media.
    N)BceBaseClient)bce_v1_signer)BceResponse)bce_http_client)handler)http_content_types)http_headers)http_methods)BceClientError)BceServerError)media_handler)requiredc                   @   s  e Zd ZdZdZdSddZeeefd				dTddZ	eeefe
e
d	dSd
dZeeefddSddZeeefddSddZeeefeefddSddZdSddZeeefeefeefd			dUddZeeefee
fd	dSddZeeefddSddZeeefddSdd ZeeefddSd!d"ZdSd#d$Zeeefeefd%										dVd&d'Zeeefee
fd(	dSd)d*Zeeefd+dSd,d-Zeeefd+dSd.d/Zeeefd+dSd0d1Zeeefe
d2dUd3d4ZeeefddSd5d6Zeeefd				dTd7d8Zeeefeefeed9					dWd:d;Z eeefd<dSd=d>Z!dSd?d@Z"eeefd<dSdAdBZ#dSdCdDZ$eeefeefdE	dSdFdGZ%eeefdHdSdIdJZ&eeefdHdSdKdLZ'dMdN Z(e)dOdP Z*			dWdQdRZ+dS )XMediaClientz
    sdk client
    z/v3Nc                 C   s   t | | d S N)r   __init__selfconfig r   TD:\Projects\ConvertPro\env\Lib\site-packages\baidubce/services/media/media_client.pyr   ,   s   zMediaClient.__init__)pipeline_namec                 C   \   |dkrt dd|i}|dur||d< |dur||d< |dur$||d< | jtjd||d	S )
a  
        List jobs by pipelineName and jobStatus

        :param pipelineName: The pipeline name
        :type  pipelineName: string or unicode
        :param job_status: The job status, will not filter if None
        :type  job_status: string or unicode
        :param begin: The createTime should be later than or equals with begin, will not check if None
        :type  begin: string or unicode
        :param end: The createTime should be earlier than or equals with end, will not check if None
        :type  end: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
         #pipeline_name can't be empty stringpipelineNameN	jobStatusbeginend/job/transcodingparamsr   r
   _send_requestr	   GETr   r   Z
job_statusr   r   r   Z	my_paramsr   r   r   	list_jobs/   s    zMediaClient.list_jobs)r   sourcetargetc              	   C   s<   |dkrt d| jtjdt|||dtjtj	i|dS )a}  
        Create a job

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param source: source
        :type source: array
        :param target: source
        :type target: array
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   r   r   )r   r&   r'   bodyheadersr   
r
   r"   r	   POSTjsondumpsr   CONTENT_TYPEr   JSON)r   r   r&   r'   r   r   r   r   
create_jobW   s   
zMediaClient.create_job)job_idc                 C   &   |dkrt d| jtjd| |dS )a  
        Get the specific job information

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   job_id can't be empty stringz/job/transcoding/r   r!   r   r2   r   r   r   r   get_jobs   s   zMediaClient.get_jobc                 C   s*   |dkrt d| jtjd| tj|dS )ad  
        Get transcoding job encryption key

        :param job_id: The job Id want to query transcoding encryption key.
        :type job_id: string
        :param config: None
        :type config: BceClientConfiguration
        :returns: Response Object contains transcoding encryption Aes key.
        :rtype: baidubce.bce_response.BceResponse
        r   r4   z/transcoding/key/)body_parserr   )r
   r"   r	   r#   r   Zparse_secret_key_responser6   r   r   r   get_transcoding_encryption_key   s   z*MediaClient.get_transcoding_encryption_keybucketkeyc                 C   s:   |dkrt d|dkrt d| jtjd||d|dS )a$  
        Get the media info of media information

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   bucket can't be empty stringkey can't be empty stringz
/mediainfor:   r   r!   )r   r;   r<   r   r   r   r   get_mediainfo_of_file   s   z!MediaClient.get_mediainfo_of_filec                 C      | j tjd|dS )a  
        List pipelines

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        	/pipeliner5   r"   r	   r#   r   r   r   r   list_pipelines      zMediaClient.list_pipelines)r   source_buckettarget_bucketc                 C   s   i }|dur||d< nd|d< |dur||d< |dkrt d|dkr't d|dkr/t d||d< ||d	< ||d
< | jtjdt|tjtj	i|dS )a  
        Create a pipeline

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        Ndescriptionr   r   r   z#source_bucket can't be empty stringz#target_bucket can't be empty stringr   ZsourceBucketZtargetBucketrA   r(   r+   )r   r   rE   rF   rG   Zpipeline_configr   body_contentr   r   r   create_pipeline   s,   

zMediaClient.create_pipeline)r   pipelinec                 C   0   | j tjd| tj|dd dtjtji|dS )a]  
        Update a pipeline

        :param pipeline_name: the preset name
        :type pipeline_name: string
        :param pipeline: the update body
        :type pipeline: Object
        :returns:
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        
/pipeline/c                 S      | j S r   __dict__or   r   r   <lambda>      z-MediaClient.update_pipeline.<locals>.<lambda>defaultr(   	r"   r	   PUTr-   r.   r   r/   r   r0   )r   r   rJ   r   r   r   r   update_pipeline      
zMediaClient.update_pipeline)Zpipelien_namec                 C   *   |dkrt d| jtjd| |tjdS )aV  
        Get the specific pipeline information without converting camel key to a "pythonic" name

        :param pipeline_name: The pipeline name
        :type pipeline_name: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   r   rL   r   r8   r
   r"   r	   r#   r   
parse_jsonr   r   r   r   r   r   get_pipeline_for_update  
   z#MediaClient.get_pipeline_for_updatec                 C   r3   )a"  
        Get the specific pipeline information

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   r   rL   r5   r!   r^   r   r   r   get_pipeline     zMediaClient.get_pipelinec                 C   r3   )a  
        Delete the specific pipeline

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   r   rL   r5   r
   r"   r	   DELETEr^   r   r   r   delete_pipeline'  rb   zMediaClient.delete_pipelinec                 C   r@   )z
        List presets

        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        /presetr5   rB   r   r   r   r   list_presets7     	zMediaClient.list_presets)preset_name	containerc                 C   s   t  }|dkrtd|dkrtd||d< ||d< |du r$d|d< n||d< |dur0||d< |dur8||d	< |dur@||d
< |durH||d< |durP||d< |	durX|	|d< |
dur`|
|d< |durh||d< | jtjdt|tjt	j
i|dS )z
        Create a preset

        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   !preset_name can't be empty stringzcontainer can't be empty stringZ
presetNamerj   NrG   transmuxclipaudiovideo
encryptionZwatermarkIdZextraCfgZtransCfgrf   r(   )dictr
   r"   r	   r,   r-   r.   r   r/   r   r0   )r   ri   rj   rl   rG   rm   rn   ro   rp   watermark_idZextra_configZtrans_configr   rH   r   r   r   create_presetB  sB   

zMediaClient.create_preset)ri   presetc                 C   rK   )aS  
        Update a preset

        :param preset_name: the preset name
        :type preset_name: string
        :param preset: the update body
        :type preset: Object
        :returns:
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        /preset/c                 S   rM   r   rN   rP   r   r   r   rR     rS   z+MediaClient.update_preset.<locals>.<lambda>rT   r(   rV   )r   ri   rt   r   r   r   r   update_preset|  rY   zMediaClient.update_preset)ri   c                 C   r3   )a   
        Get the specific preset information

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   rk   ru   r5   r!   r   ri   r   r   r   r   
get_preset  rb   zMediaClient.get_presetc                 C   rZ   )aN  
        Get the specific preset information without converting camel key to a "pythonic" name

        :param preset_name: The preset name
        :type preset_name: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   rk   ru   r[   r\   rw   r   r   r   get_preset_for_update  r`   z!MediaClient.get_preset_for_updatec                 C   r3   )a  
        Delete a preset

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   rk   ru   r5   rc   rw   r   r   r   delete_preset  rb   zMediaClient.delete_preset)r   r&   c                 C   sh   i }|dkr
t d|dur||d< |dur||d< ||d< ||d< | jtjdt|tjtj	i|d	S )
a  
        Create thumbnail job

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   r   Nr'   capturer   r&   /job/thumbnailr(   r+   )r   r   r&   r'   r{   r   rH   r   r   r   create_thumbnail_job  s    
z MediaClient.create_thumbnail_jobc                 C   r3   )a  
        Get thumbnail job

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   r4   z/job/thumbnail/r5   r!   r6   r   r   r   get_thumbnail_job  rb   zMediaClient.get_thumbnail_jobc                 C   r   )
a  
        List thumbnail jobs by pipelineName

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param job_status: The thumbnail job status, will not filter if None
        :type  job_status: string or unicode
        :param begin: The createTime should be later than or equals with begin, will not check if None
        :type  begin: string or unicode
        :param end: The createTime should be earlier than or equals with end, will not check if None
        :type  end: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   r   r   Nr   r   r   r|   r   r!   r$   r   r   r   list_thumbnail_jobs_by_pipeline  s    z+MediaClient.list_thumbnail_jobs_by_pipeline)r;   r<   vertical_offset_in_pixelhori_offset_in_pixelc           	      C   s   |dkrt d|dkrt di }||d< ||d< |dur"||d< |dur*||d< |dur2||d	< |dur:||d
< | jtjdt|tjtj	i|dS )a  
        Create watermark

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   r=   r>   r;   r<   NZverticalAlignmentZhorizontalAlignmentZverticalOffsetInPixelZhorizontalOffsetInPixel
/watermarkr(   r+   )	r   r;   r<   Zvertical_alignmentZhorizontal_alignmentr   r   r   rH   r   r   r   create_watermark  s,   
zMediaClient.create_watermark)rr   c                 C   r3   )a#  
        Get the specific watermark information

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   "watermark_id can't be empty string/watermark/r5   r!   r   rr   r   r   r   r   get_watermarkJ  rb   zMediaClient.get_watermarkc                 C   r@   )a  
        List watermarks

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   r5   rB   r   r   r   r   list_watermarksZ  rD   zMediaClient.list_watermarksc                 C   r3   )a  
        Delete the specific watermark

        :param pipelineName: The pipeline name
        :type pipelineName: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   r   r   r5   rc   r   r   r   r   delete_watermarkg  rb   zMediaClient.delete_watermarkc                 C   r@   )z
        List notifications

        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        /notificationr5   rB   r   r   r   r   list_notificationsw  rh   zMediaClient.list_notificationsnameendpointc                 C   sN   |dkrt d|dkrt d||d}| jtjdt|tjtj	i|dS )aV  
        Create a notification

        :param name: The notification name
        :type name: string or unicode
        :param endpoint: The endpoint
        :type endpoint: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   name can't be empty stringzendpoint can't be empty stringr   r   r(   r+   )r   r   r   r   rH   r   r   r   create_notification  s   
zMediaClient.create_notification)r   c                 C   r3   )a  
        Get the specific notification information

        :param name: The notification name
        :type name: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   r   /notification/r5   r!   r   r   r   r   r   r   get_notification  rb   zMediaClient.get_notificationc                 C   r3   )a  
        Delete the specific notification

        :param name: The notification name
        :type name: string or unicode
        :param config: None
        :type config: BceClientConfiguration
        :returns:
        :rtype: baidubce.bce_response.BceResponse
        r   r   r   r5   rc   r   r   r   r   delete_notification  rb   zMediaClient.delete_notificationc                 C   s.   d }|d urt ||}|d ur|S t | j|S r   )getattrr   )r   r   attrresultr   r   r   _get_config_parameter  s   
z!MediaClient._get_config_parameterc                 C   s(   |d u r| j S t| j }|| |S r   )r   copyZmerge_non_none_values)r   r   Z
new_configr   r   r   _merge_config  s
   
zMediaClient._merge_configc           	   
   C   sJ   |  | |}|d u rtj}tj| }t|tjtj	|g|t
||||S r   )r   r   r]   r   prefixr   send_requestr   signZparse_errorstrencode)	r   Zhttp_methodpathr)   r*   r    r   r8   realpathr   r   r   r"     s   
zMediaClient._send_requestr   )NNNN)NNN)
NNNNNNNNNN)NNNNN),__name__
__module____qualname____doc__r   r   r   bytesr   r%   rq   r1   r7   r9   r?   rC   rI   r   rX   r_   ra   re   rg   rs   rv   rx   ry   rz   r}   r~   r   intr   r   r   r   r   r   r   r   r   staticmethodr   r"   r   r   r   r   r   %   s    
'
	)
9(	)



r   )r   r   r-   loggingZbaidubce.bce_base_clientr   Zbaidubce.authr   Zbaidubce.bce_responser   Zbaidubce.httpr   r   r   r   r	   Zbaidubce.exceptionr
   r   Zbaidubce.services.mediar   Zbaidubce.utilsr   	getLoggerr   Z_loggerr   r   r   r   r   <module>   s$   
