Skip to content
This repository was archived by the owner on Feb 28, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cds_sorenson/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

def start_encoding(input_file, output_file, desired_quality,
display_aspect_ratio, max_height=None, max_width=None,
**kwargs):
job_name=None, **kwargs):
"""Encode a video that is already in the input folder.

:param input_file: string with the filename, something like
Expand Down Expand Up @@ -70,7 +70,8 @@ def start_encoding(input_file, output_file, desired_quality,

# Build the request of the encoding job
json_params = generate_json_for_encoding(input_file, output_file,
preset_config['preset_id'])
preset_config['preset_id'],
job_name=job_name)
proxies = current_app.config['CDS_SORENSON_PROXIES']
headers = {'Accept': 'application/json'}

Expand All @@ -79,6 +80,13 @@ def start_encoding(input_file, output_file, desired_quality,
auth = (api_username, api_password) if api_username and api_password else \
None

# hide password info from the logs
to_log = json.dumps(json_params, indent=4, sort_keys=True)
to_log = to_log.replace(current_app.config['CDS_SORENSON_PASSWORD'], '***')

current_app.logger.debug(
'Sending job to Sorenson with payload:\n{0}\n'.format(to_log))

response = requests.post(current_app.config['CDS_SORENSON_SUBMIT_URL'],
headers=headers, json=json_params,
proxies=proxies, auth=auth)
Expand Down
7 changes: 5 additions & 2 deletions cds_sorenson/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@
from .error import SorensonError


def generate_json_for_encoding(input_file, output_file, preset_id):
def generate_json_for_encoding(input_file, output_file, preset_id,
job_name=None):
"""Generate JSON that will be sent to Sorenson server to start encoding."""
current_preset = _get_preset_config(preset_id)
# Make sure the preset config exists for a given preset_id
if not current_preset:
raise SorensonError('Invalid preset "{0}"'.format(preset_id))

default_job_name = 'CDS File:{0} Preset:{1}'.format(input_file, preset_id)

return dict(
Name='CDS File:{0} Preset:{1}'.format(input_file, preset_id),
Name=job_name or default_job_name,
QueueId=current_app.config['CDS_SORENSON_DEFAULT_QUEUE'],
JobMediaInfo=dict(
SourceMediaList=[dict(
Expand Down
24 changes: 24 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,30 @@ def test_generate_json_for_encoding(app):
validate(output, sorenson_schema)
assert output == expected_output

expected_output_with_custom_job_name = {
'QueueId': '064153dd-ade2-4824-8458-88e6ea03d395',
'JobMediaInfo': {
'CompressionPresetList': [{
'PresetId': 'dc2187a3-8f64-4e73-b458-7370a88d92d7'
}],
'DestinationList': [{
'FileUri': '/tmp/test_another_output.mp4'
}],
'SourceMediaList': [{
'Password': '',
'UserName': '',
'FileUri': '/tmp/test_another_file.mp4'
}]},
'Name': 'test job name'
}
output = generate_json_for_encoding('/tmp/test_another_file.mp4',
'/tmp/test_another_output.mp4',
'dc2187a3-8f64-4e73-b458-7370a88d92d7',
job_name='test job name')

validate(output, sorenson_schema)
assert output == expected_output_with_custom_job_name


def test_get_preset_config(app):
"""Test `_get_preset_config` function."""
Expand Down