diff --git a/video_xblock/backends/brightcove.py b/video_xblock/backends/brightcove.py index 2dacfe60..03a0e860 100644 --- a/video_xblock/backends/brightcove.py +++ b/video_xblock/backends/brightcove.py @@ -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): @@ -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 = { @@ -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 @@ -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): diff --git a/video_xblock/static/css/studio-edit.css b/video_xblock/static/css/studio-edit.css index efde1183..f50d6853 100644 --- a/video_xblock/static/css/studio-edit.css +++ b/video_xblock/static/css/studio-edit.css @@ -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; +} diff --git a/video_xblock/static/html/studio-edit-brightcove-encryption.html b/video_xblock/static/html/studio-edit-brightcove-encryption.html index b275f62a..ff9cd048 100644 --- a/video_xblock/static/html/studio-edit-brightcove-encryption.html +++ b/video_xblock/static/html/studio-edit-brightcove-encryption.html @@ -6,32 +6,33 @@ >
- -
- - - -
- -
+ +
+ + -
+
+
+ +
+
diff --git a/video_xblock/static/js/studio-edit/studio-edit.js b/video_xblock/static/js/studio-edit/studio-edit.js index 54e389ec..a554869b 100644 --- a/video_xblock/static/js/studio-edit/studio-edit.js +++ b/video_xblock/static/js/studio-edit/studio-edit.js @@ -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); }); } @@ -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();