diff --git a/cms/envs/npoed.py b/cms/envs/npoed.py index ebcb943add9f..8bdb3be85a7c 100644 --- a/cms/envs/npoed.py +++ b/cms/envs/npoed.py @@ -58,3 +58,6 @@ 'task': 'third_party_auth.fetch_saml_metadata', 'schedule': datetime.timedelta(hours=ENV_TOKENS.get('THIRD_PARTY_AUTH_SAML_FETCH_PERIOD_HOURS', 24)), } + +EVMS_API_KEY = AUTH_TOKENS.get('EVMS_API_KEY') + diff --git a/common/lib/xmodule/xmodule/video_module/video_module.py b/common/lib/xmodule/xmodule/video_module/video_module.py index f9134c820cbe..60d30ba33f9f 100644 --- a/common/lib/xmodule/xmodule/video_module/video_module.py +++ b/common/lib/xmodule/xmodule/video_module/video_module.py @@ -73,7 +73,9 @@ # of this particular import silliness. It's just that I haven't made one before, # and I was worried about trying it with my deadline constraints. try: - import edxval.api as edxval_api + # import edxval.api as edxval_api + # Use evms api instead of edxval_api + import openedx.core.djangoapps.video_evms.api as edxval_api except ImportError: edxval_api = None diff --git a/lms/envs/npoed.py b/lms/envs/npoed.py index 9e44ff8ff5fb..e49a70057f15 100644 --- a/lms/envs/npoed.py +++ b/lms/envs/npoed.py @@ -40,3 +40,5 @@ #OAUTH_OIDC_ISSUER = "https://rnoep.raccoongang.com/oauth2" +EVMS_URL = ENV_TOKENS.get('EVMS_URL') +EVMS_API_KEY = AUTH_TOKENS.get('EVMS_API_KEY') diff --git a/openedx/core/djangoapps/video_evms/__init__.py b/openedx/core/djangoapps/video_evms/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/openedx/core/djangoapps/video_evms/api.py b/openedx/core/djangoapps/video_evms/api.py new file mode 100644 index 000000000000..4947a19cea2b --- /dev/null +++ b/openedx/core/djangoapps/video_evms/api.py @@ -0,0 +1,119 @@ +import json +import urllib2 +import logging + +from lxml.etree import Element, SubElement +from django.conf import settings + +log = logging.getLogger(__name__) +API_URL = '{0}/api/v1/video'.format(getattr(settings, 'EVMS_URL')) + + +class ValError(Exception): + """ + An error that occurs during VAL actions. + This error is raised when the VAL API cannot perform a requested + action. + """ + pass + + +class ValInternalError(ValError): + """ + An error internal to the VAL API has occurred. + This error is raised when an error occurs that is not caused by incorrect + use of the API, but rather internal implementation of the underlying + services. + """ + pass + + +class ValVideoNotFoundError(ValError): + """ + This error is raised when a video is not found + If a state is specified in a call to the API that results in no matching + entry in database, this error may be raised. + """ + pass + + +class ValVideoNotFoundError(ValError): + """ + This error is raised when a video is not found + If a state is specified in a call to the API that results in no matching + entry in database, this error may be raised. + """ + pass + + +class ValCannotCreateError(ValError): + """ + This error is raised when an object cannot be created + """ + pass + + +def get_urls_for_profiles(edx_video_id, val_profiles): + raw_data = get_video_info(edx_video_id) + if raw_data is None: + raw_data = {} + else: + raw_data = raw_data[0] + log.warning(raw_data) + profile_data = {} + for profile in val_profiles: + url = '' + if 'encoded_videos' in raw_data: + videos = raw_data['encoded_videos'] + for video in videos: + if video.get('profile') == profile: + url = video.get('url', '') + profile_data[profile] = url + return json.loads(json.dumps(profile_data)) + + +def get_url_for_profile(edx_video_id, val_profile): + return get_urls_for_profiles(edx_video_id, [val_profile])[val_profile] + + +def get_video_info(edx_video_id): + token = getattr(settings, 'EVMS_API_KEY') + url_api = u'{0}/{1}?token={2}'.format(API_URL, edx_video_id, token) + try: + response = urllib2.urlopen(url_api) + except: + return None + data = response.read() + clean_data = json.loads(data) + return clean_data + + +def export_to_xml(edx_video_id): + video = get_video_info(edx_video_id) + if video is None: + return Element('video_asset') + else: + video = video[0] + video_el = Element( + 'video_asset', + attrib={ + 'client_video_id': video['client_video_id'], + 'duration': unicode(video['duration']), + } + ) + for encoded_video in video['encoded_videos']: + SubElement( + video_el, + 'encoded_video', + { + name: unicode(encoded_video.get(name)) + for name in ['profile', 'url', 'file_size', 'bitrate'] + } + ) + # Note: we are *not* exporting Subtitle data since it is not currently updated by VEDA or used + # by LMS/Studio. + return video_el + + +def import_from_xml(xml, edx_video_id, course_id=None): + return