Skip to content

Commit

Permalink
Brightcove retranscode issue (#302)
Browse files Browse the repository at this point in the history
* Normalize retranscode studio editor section

* Add Brightcove API retranscode error handling
  • Loading branch information
wowkalucky authored Feb 9, 2018
1 parent fa4657c commit 3cf98d2
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 33 deletions.
30 changes: 25 additions & 5 deletions video_xblock/backends/brightcove.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,21 @@ def post(self, url, payload, headers=None, can_retry=True):
headers_.update(headers)

resp = requests.post(url, data=payload, headers=headers_)
log.debug("BC response status: {}".format(resp.status_code))
if resp.status_code in (httplib.OK, httplib.CREATED):
return resp.json()
elif resp.status_code == httplib.UNAUTHORIZED and can_retry:
self.access_token = self._refresh_access_token()
return self.post(url, payload, headers, can_retry=False)
else:
raise BrightcoveApiClientError

try:
resp_dict = resp.json()[0]
log.warn("API error code: %s - %s", resp_dict.get(u'error_code'), resp_dict.get(u'message'))
except (ValueError, IndexError):
message = _("Can't parse unexpected response during POST request to Brightcove API!")
log.exception(message)
resp_dict = {"message": message}
return resp_dict


class BrightcoveHlsMixin(object):
Expand All @@ -173,6 +181,8 @@ class BrightcoveHlsMixin(object):
These features are:
1. Video playback autoquality. i.e. adjusting video bitrate depending on client's bandwidth.
2. Video content encryption using short-living keys.
NOTE(wowkalucky): Dynamic Ingest is the legacy ingest system. New Video Cloud accounts use Dynamic Delivery.
"""

DI_PROFILES = {
Expand Down Expand Up @@ -244,6 +254,7 @@ def submit_retranscode_job(self, account_id, video_id, profile_type):
- default - re-transcode using default DI profile;
- autoquality - re-transcode using HLS only profile;
- encryption - re-transcode using HLS with encryption profile;
ref: https://support.brightcove.com/dynamic-ingest-api
"""
url = 'https://ingest.api.brightcove.com/v1/accounts/{account_id}/videos/{video_id}/ingest-requests'.format(
account_id=account_id, video_id=video_id
Expand All @@ -259,9 +270,18 @@ def submit_retranscode_job(self, account_id, video_id, profile_type):
if profile_type != 'default':
retranscode_params['profile'] = self.DI_PROFILES[profile_type]['name']
res = self.api_client.post(url, json.dumps(retranscode_params))
self.xblock.metadata['retranscode-status'] = (
'ReTranscode request submitted {:%Y-%m-%d %H:%M} UTC using profile "{}". Job id: {}'.format(
datetime.utcnow(), retranscode_params.get('profile', 'default'), res['id']))
if u'error_code' in res:
self.xblock.metadata['retranscode-status'] = (
'ReTranscode request encountered error {:%Y-%m-%d %H:%M} UTC using profile "{}".\nMessage: {}'.format(
datetime.utcnow(), retranscode_params.get('profile', 'default'), res['message']
)
)
else:
self.xblock.metadata['retranscode-status'] = (
'ReTranscode request submitted {:%Y-%m-%d %H:%M} UTC using profile "{}". Job id: {}'.format(
datetime.utcnow(), retranscode_params.get('profile', 'default'), res['id']
)
)
return res

def get_video_renditions(self, account_id, video_id):
Expand Down
19 changes: 19 additions & 0 deletions video_xblock/static/css/studio-edit.css
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,22 @@
color: #fff;
}

.retranscode-button {
box-sizing: border-box;
display: inline-block;
font-size: 1.2rem;
font-weight: 600;
transition: all 0.15s;
text-align: center;
text-decoration: none;
border-radius: 5px;
border: 1px solid #0075b4;
background-color: #fff;
color: #0075b4;
padding: 10px;
}

.retranscode-button:hover {
background-color: #065683;
color: #fff;
}
49 changes: 25 additions & 24 deletions video_xblock/static/html/studio-edit-brightcove-encryption.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@
>
<div class='wrapper-comp-setting {% if field.type == "set" %}metadata-list-enum{% endif %} {% if field.type == "handout" %}file-uploader{% endif %}{% if field.type == "transcripts" %}metadata-video-translations{% endif %}'>

<label class="label setting-label" for="xb-field-edit-retranscode-options">{% trans "Brightcove content protection" %}</label>
<div class="custom-field-list">
<div class="custom-field-section-label">{% trans "Video autoquality & encryption" %}</div>
<select
class="field-data-control"
id="xb-field-edit-retranscode-options"
>
<option value="default">
{% trans "Default profile" %}
</option>
<option value="autoquality">
{% trans "Autoquality" %}
</option>
<option value="encryption">
{% trans "Autoquality & Encryption" %}
</option>
</select>

<div class="field-elements-wrapper">
<button id="submit-re-transcode" class="studio-edit-button">
<span aria-hidden="true"></span>{% trans "Re-transcode this video" %}<span class="sr"></span>
</button>
</div>
<label class="label setting-label" for="xb-field-edit-retranscode-options">
{% trans "Brightcove content protection" %}
</label>
<div class="custom-field-list">
<div class="custom-field-section-label">
{% trans "Video autoquality & encryption" %}
</div>
<select class="field-data-control" id="xb-field-edit-retranscode-options">
<option value="default">
{% trans "Default profile" %}
</option>
<option value="autoquality">
{% trans "Autoquality" %}
</option>
<option value="encryption">
{% trans "Autoquality & Encryption" %}
</option>
</select>

<div id="brightcove-retranscode-status"></div>
<div class="field-elements-wrapper">
<button id="submit-re-transcode" class="studio-edit-button retranscode-button">
<span aria-hidden="true"></span>{% trans "Re-transcode this video" %}<span class="sr"></span>
</button>
</div>

<div id="brightcove-retranscode-status"></div>
</div>
</div>
</li>

Expand Down
11 changes: 7 additions & 4 deletions video_xblock/static/js/studio-edit/studio-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ function StudioEditableXBlock(runtime, element) {
$.when(
dispatch('POST', 'submit_retranscode_' + profile)
).then(function(response) {
$('#brightcove-retranscode-status').html(
var error = 'error_code' in response;
var color = error ? 'red' : 'green';
var message = error ?
response.message :
'Your retranscode request was successfully submitted to Brightcove VideoCloud. ' +
'It takes few minutes to process it. Job id ' + response.id);
'It takes few minutes to process it. Job id: ' + response.id;
$('#brightcove-retranscode-status').html(message).css('color', color);
});
}

Expand Down Expand Up @@ -156,8 +160,7 @@ function StudioEditableXBlock(runtime, element) {
$('#submit-re-transcode').click(function() {
var profile = $('#xb-field-edit-retranscode-options').val();
submitBCReTranscode(profile);
}
);
});

$('#settings-tab').ready(function() {
showBackendSettings();
Expand Down

0 comments on commit 3cf98d2

Please sign in to comment.