Commit 8c24c786 by Qubad786 Committed by muzaffaryousaf

Add Api util to get available transcript languages.

parent 4855051e
...@@ -223,6 +223,25 @@ def get_video_transcript_data(video_ids, language_code): ...@@ -223,6 +223,25 @@ def get_video_transcript_data(video_ids, language_code):
return transcript_data return transcript_data
def get_available_transcript_languages(video_ids):
"""
Get available transcript languages
Arguments:
video_ids(list): list containing edx_video_id and external video ids extracted from
external sources of a video component.
Returns:
A list containing unique transcript language codes for the video ids.
"""
available_languages = VideoTranscript.objects.filter(
video_id__in=video_ids
).values_list(
'language_code', flat=True
)
return list(set(available_languages))
def get_video_transcript_url(video_id, language_code): def get_video_transcript_url(video_id, language_code):
""" """
Returns course video transcript url or None if no transcript Returns course video transcript url or None if no transcript
......
...@@ -1936,6 +1936,20 @@ class TranscriptTest(TestCase): ...@@ -1936,6 +1936,20 @@ class TranscriptTest(TestCase):
self.assertEqual(file_open_exception.exception.strerror, u'No such file or directory') self.assertEqual(file_open_exception.exception.strerror, u'No such file or directory')
def test_get_available_transcript_languages(self):
"""
Verify that `get_available_transcript_languages` works as expected.
"""
dupe_lang_video_id = 'duplicate_lang_video'
VideoTranscript.objects.create(**dict(constants.VIDEO_TRANSCRIPT_CIELO24, video_id=dupe_lang_video_id))
# `super-soaker` has got 'en' and 'de' transcripts
# `self.video_id` has got 'ur' transcript
# `duplicate_lang_video` has got 'en' transcript
# `non_existent_video_id` that does not have transcript
video_ids = ['super-soaker', self.video_id, dupe_lang_video_id, 'non_existent_video_id']
transcript_languages = api.get_available_transcript_languages(video_ids=video_ids)
self.assertItemsEqual(transcript_languages, ['de', 'en', 'ur'])
@ddt @ddt
class TranscriptPreferencesTest(TestCase): class TranscriptPreferencesTest(TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment