From 2203de4a85e8aaea7bb4437473540082277d88e1 Mon Sep 17 00:00:00 2001 From: muhammad-ammar Date: Wed, 13 Sep 2017 11:59:31 +0500 Subject: [PATCH] video ids info --- .../tests/test_transcripts_utils.py | 41 +++++++++++++++++++ .../xmodule/video_module/transcripts_utils.py | 23 +++++++++++ 2 files changed, 64 insertions(+) diff --git a/cms/djangoapps/contentstore/tests/test_transcripts_utils.py b/cms/djangoapps/contentstore/tests/test_transcripts_utils.py index 4e9de8075f..5914414c34 100644 --- a/cms/djangoapps/contentstore/tests/test_transcripts_utils.py +++ b/cms/djangoapps/contentstore/tests/test_transcripts_utils.py @@ -4,6 +4,7 @@ import copy import textwrap import unittest from uuid import uuid4 +import ddt from django.conf import settings from django.test.utils import override_settings @@ -643,3 +644,43 @@ class TestSubsFilename(unittest.TestCase): self.assertEqual(name, u'subs_˙∆©ƒƒƒ.srt.sjson') name = transcripts_utils.subs_filename(u"˙∆©ƒƒƒ", 'uk') self.assertEqual(name, u'uk_subs_˙∆©ƒƒƒ.srt.sjson') + + +@ddt.ddt +class TestVideoIdsInfo(unittest.TestCase): + """ + Tests for `get_video_ids_info`. + """ + @ddt.data( + { + 'edx_video_id': '000-000-000', + 'youtube_id_1_0': '12as34', + 'html5_sources': [ + 'www.abc.com/foo.mp4', 'www.abc.com/bar.webm', 'foo/bar/baz.m3u8' + ], + 'expected_result': (False, ['000-000-000', '12as34', 'foo', 'bar', 'baz']) + }, + { + 'edx_video_id': '', + 'youtube_id_1_0': '12as34', + 'html5_sources': [ + 'www.abc.com/foo.mp4', 'www.abc.com/bar.webm', 'foo/bar/baz.m3u8' + ], + 'expected_result': (True, ['12as34', 'foo', 'bar', 'baz']) + }, + { + 'edx_video_id': '', + 'youtube_id_1_0': '', + 'html5_sources': [ + 'www.abc.com/foo.mp4', 'www.abc.com/bar.webm', + ], + 'expected_result': (True, ['foo', 'bar']) + }, + ) + @ddt.unpack + def test_get_video_ids_info(self, edx_video_id, youtube_id_1_0, html5_sources, expected_result): + """ + Verify that `get_video_ids_info` works as expected. + """ + actual_result = transcripts_utils.get_video_ids_info(edx_video_id, youtube_id_1_0, html5_sources) + self.assertEqual(actual_result, expected_result) diff --git a/common/lib/xmodule/xmodule/video_module/transcripts_utils.py b/common/lib/xmodule/xmodule/video_module/transcripts_utils.py index 4e6b967818..d46944bbbf 100644 --- a/common/lib/xmodule/xmodule/video_module/transcripts_utils.py +++ b/common/lib/xmodule/xmodule/video_module/transcripts_utils.py @@ -469,6 +469,29 @@ def get_or_create_sjson(item, transcripts): return sjson_transcript +def get_video_ids_info(edx_video_id, youtube_id_1_0, html5_sources): + """ + Returns list internal or external video ids. + + Arguments: + edx_video_id (str): edx_video_id + youtube_id_1_0 (str): youtube id + html5_sources (list): html5 video ids + + Returns: + tuple: external or internal, video ids list + """ + clean = lambda item: item.strip() if isinstance(item, basestring) else item + external = not bool(clean(edx_video_id)) + + video_ids = [edx_video_id, youtube_id_1_0] + get_html5_ids(html5_sources) + + # video_ids cleanup + video_ids = filter(lambda item: bool(clean(item)), video_ids) + + return external, video_ids + + class Transcript(object): """ Container for transcript methods.