Skip to content

Commit

Permalink
Merge pull request #3 from edly-io/rehan/raccoongang-working-branch-c…
Browse files Browse the repository at this point in the history
…hanges

Brings changes from working branch in raccoongang repo
  • Loading branch information
rehan99000 authored Apr 21, 2020
2 parents c8bbce6 + 4d3338d commit 1b1c612
Show file tree
Hide file tree
Showing 29 changed files with 224 additions and 686 deletions.
10 changes: 3 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,12 @@ def package_data(pkg, roots):
packages=[
'video_xblock',
],
dependency_links=[
# At the moment of writing PyPI hosts outdated version of xblock-utils, hence git
# Replace dependency links with numbered versions when it's released on PyPI
'git+https://github.com/edx/[email protected]#egg=xblock-utils==1.0.5',
],
install_requires=[
'XBlock>=0.4.10,<2.0.0',
'xblock-utils',
'le-pycaption',
'requests>=2.9.1,<3.0.0',
'babelfish>=0.5.5,<0.6.0',
'XBlock>=0.4.10,<2.0.0',
],
entry_points={
'xblock.v1': [
Expand All @@ -71,5 +67,5 @@ def package_data(pkg, roots):
'html5-player = video_xblock.backends.html5:Html5Player',
]
},
package_data=package_data("video_xblock", ["static", ]),
package_data=package_data("video_xblock", ["static", "backends", "public", "tests", "workbench"]),
)
2 changes: 1 addition & 1 deletion video_xblock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Video xblock module.
"""

__version__ = '0.10.1'
__version__ = '0.9.1'

# pylint: disable=wildcard-import
from .video_xblock import * # nopep8
1 change: 0 additions & 1 deletion video_xblock/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def get_frag(self, **context):
'static/vendor/js/video.min.js',
'static/vendor/js/videojs-contextmenu.min.js',
'static/vendor/js/videojs-contextmenu-ui.min.js',
'static/vendor/js/array-from-polyfill.js',
'static/js/videojs/video-speed.js',
'static/js/student-view/player-state.js',
'static/js/videojs/videojs-speed-handler.js'
Expand Down
64 changes: 20 additions & 44 deletions video_xblock/backends/brightcove.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,10 @@ def _refresh_access_token(self):
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic " + auth_string
}
try:
resp = requests.post(url, headers=headers, data=params)
if resp.status_code == httplib.OK:
result = resp.json()
return result['access_token']
except IOError:
log.exception(_("Connection issue. Couldn't refresh API access token."))
return None
resp = requests.post(url, headers=headers, data=params)
if resp.status_code == httplib.OK:
result = resp.json()
return result['access_token']

def get(self, url, headers=None, can_retry=True):
"""
Expand Down Expand Up @@ -157,21 +153,13 @@ 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)

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
else:
raise BrightcoveApiClientError


class BrightcoveHlsMixin(object):
Expand All @@ -181,8 +169,6 @@ 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 @@ -254,7 +240,6 @@ 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 @@ -270,18 +255,9 @@ 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))
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']
)
)
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 Expand Up @@ -412,7 +388,6 @@ def get_frag(self, **context):
Because of this it doesn't use `super.get_frag()`.
"""
context['player_state'] = json.dumps(context['player_state'])
log.debug('CONTEXT: player_state: %s', context.get('player_state'))

frag = Fragment(
self.render_template('brightcove.html', **context)
Expand All @@ -425,14 +400,13 @@ def get_frag(self, **context):
)
js_files = [
'static/js/base.js',
'static/vendor/js/array-from-polyfill.js',
'static/js/videojs/toggle-button.js',
'static/js/student-view/player-state.js'
]
js_files += [
'static/js/videojs/videojs-tabindex.js',
'static/js/videojs/toggle-button.js',
'static/js/videojs/videojs-event-plugin.js',
'static/js/videojs/brightcove-videojs-init.js',
'static/js/videojs/brightcove-videojs-init.js'
]

for js_file in js_files:
Expand All @@ -441,24 +415,26 @@ def get_frag(self, **context):
frag.add_css(
self.resource_string('static/css/brightcove.css')
)
log.debug("[get_frag] initialized scripts: %s", js_files)
return frag

def get_player_html(self, **context):
"""
Add VideoJS plugins to the context and render player html using base class logic.
"""
vjs_plugins = [
'static/vendor/js/videojs-offset.min.js',
'static/js/videojs/videojs-speed-handler.js'
self.resource_string(
'static/vendor/js/videojs-offset.min.js'
),
self.resource_string('static/js/videojs/videojs-speed-handler.js')
]
if context.get('transcripts'):
vjs_plugins += [
'static/vendor/js/videojs-transcript.min.js',
'static/js/videojs/videojs-transcript.js'
self.resource_string(
'static/vendor/js/videojs-transcript.min.js'
),
self.resource_string('static/js/videojs/videojs-transcript.js')
]
context['vjs_plugins'] = map(self.resource_string, vjs_plugins)
log.debug("Initialized scripts: %s", vjs_plugins)
context['vjs_plugins'] = vjs_plugins
return super(BrightcovePlayer, self).get_player_html(**context)

def dispatch(self, _request, suffix):
Expand Down
32 changes: 3 additions & 29 deletions video_xblock/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from xblock.exceptions import NoSuchServiceError
from xblock.fields import Scope, Boolean, Float, String

from .constants import DEFAULT_LANG, TPMApiTranscriptFormatID, TPMApiLanguage, TranscriptSource, Status, PlayerName
from .constants import DEFAULT_LANG, TPMApiTranscriptFormatID, TPMApiLanguage, TranscriptSource, Status
from .utils import import_from, ugettext as _, underscore_to_mixedcase, Transcript

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -99,18 +99,6 @@ def convert_caps_to_vtt(caps):
return WebVTTWriter().write(reader().read(caps))
return u''

@staticmethod
def vtt_to_text(vtt_content):
"""
Utility method to extract text from WebVTT format transcript.
"""
text_lines = []
for line in vtt_content.splitlines():
if '-->' in line or line == '':
continue
text_lines.append(line)
return ' '.join(text_lines)

def route_transcripts(self):
"""
Re-route transcripts to appropriate handler.
Expand All @@ -121,21 +109,12 @@ def route_transcripts(self):
Arguments:
transcripts (unicode): Raw transcripts.
"""
log.debug("Routing transcripts: 3PM status={}".format(self.threeplaymedia_streaming))
transcripts = self.get_enabled_transcripts()
for tran in transcripts:
if self.threeplaymedia_streaming:
# download URL remains hidden behind the handler:
tran['download_url'] = self.runtime.handler_url(
tran['url'] = self.runtime.handler_url(
self, 'fetch_from_three_play_media', query="{}={}".format(tran['lang_id'], tran['id'])
)
# NOTE(wowkalucky): for some reason handler's URL doesn't work in combination
# Brightcove player/Safari browser. Safari just doesn't populate text tracks with cues!
# So, we have to expose raw 3PM URL for Brightcove users, for now...
if str(self.player_name) != PlayerName.BRIGHTCOVE:
tran['url'] = self.runtime.handler_url(
self, 'fetch_from_three_play_media', query="{}={}".format(tran['lang_id'], tran['id'])
)
elif not tran['url'].endswith('.vtt'):
tran['url'] = self.runtime.handler_url(
self, 'srt_to_vtt', query=tran['url']
Expand Down Expand Up @@ -259,7 +238,6 @@ def get_3pm_transcripts_list(self, file_id, apikey):
domain=domain, file_id=file_id, api_key=apikey
)
)
log.debug(response._content) # pylint: disable=protected-access
except IOError:
log.exception(failure_message)
return feedback, transcripts_list
Expand Down Expand Up @@ -366,7 +344,7 @@ def fetch_from_three_play_media(self, request, _suffix=''):
transcript = self.fetch_single_3pm_translation(transcript_data={'id': transcript_id, 'language_id': lang_id})
if transcript is None:
return Response()
return Response(transcript.content, content_type='text/vtt')
return Response(transcript.content)

@XBlock.handler
def validate_three_play_media_config(self, request, _suffix=''):
Expand Down Expand Up @@ -540,10 +518,6 @@ def save_player_state(self, request, _suffix=''):
if field_name not in player_state:
player_state[field_name] = request[underscore_to_mixedcase(field_name)]

# make sure player's volume is down when muted:
if player_state['muted']:
player_state['volume'] = 0.000

self.player_state = player_state
return {'success': True}

Expand Down
Loading

0 comments on commit 1b1c612

Please sign in to comment.