"""Elastic Transcoder common functions.""" import boto3 from . import common_config from .util import boto3_error_handling from .util import generate_unique_filename PRESET_FLAC = '1351620000001-300110' # System preset: Audio FLAC - CD PRESET_MP3_320K = '1351620000001-300010' # System preset: Audio MP3 - 320 kilobits/second EXTENSIONS = { PRESET_FLAC: 'flac', PRESET_MP3_320K: 'mp3' } client = boto3.client('elastictranscoder', region_name=common_config.AWS_REGION) @boto3_error_handling def get_job_by_id(job_id): """Get Elastic Transcoder Job by Id.""" return client.read_job(Id=job_id) @boto3_error_handling def create_job(pipeline_id, key, presets): """Create Elastic Transcoder Job. Args: pipeline_id (str): The Pipeline ID to be used. key (str): Input file presets (list): List of preset constants that are declared in this module. Returns: bool: True if success else raise Exception. """ outputs = [] for preset in presets: outputs.append({ 'Key': '{file}.{ext}'.format(file=generate_unique_filename(), ext=EXTENSIONS[preset]), 'PresetId': preset }) return client.create_job( PipelineId=pipeline_id, Inputs=[{'Key': key}], Outputs=outputs )