Commit db6f587f by Qubad786

Check transcript avaialbility

parent 84482730
...@@ -142,6 +142,22 @@ def update_video_status(edx_video_id, status): ...@@ -142,6 +142,22 @@ def update_video_status(edx_video_id, status):
video.save() video.save()
def is_transcript_available(video_id, language_code=None):
"""
Returns whether the transcripts are available for a video.
Arguments:
video_id: it can be an edx_video_id or an external_id extracted from external sources in a video component.
language_code: it will the language code of the requested transcript.
"""
filter_attrs = {'video_id': video_id}
if language_code:
filter_attrs['language_code'] = language_code
transcript_set = VideoTranscript.objects.filter(**filter_attrs)
return transcript_set.exists()
def get_video_transcript(video_id, language_code): def get_video_transcript(video_id, language_code):
""" """
Get a video's transcript Get a video's transcript
......
...@@ -1512,6 +1512,21 @@ class TranscriptTest(TestCase): ...@@ -1512,6 +1512,21 @@ class TranscriptTest(TestCase):
) )
@data( @data(
{'video_id': 'super-soaker', 'language_code': 'en', 'expected_availability': True},
{'video_id': 'super-soaker', 'language_code': None, 'expected_availability': True},
{'video_id': 'super123', 'language_code': 'en', 'expected_availability': False},
{'video_id': 'super-soaker', 'language_code': 'ro', 'expected_availability': False},
)
@unpack
def test_is_transcript_available(self, video_id, language_code, expected_availability):
"""
Verify that `is_transcript_available` api function works as expected.
"""
is_transcript_available = api.is_transcript_available(video_id, language_code)
self.assertEqual(is_transcript_available, expected_availability)
@unpack
@data(
{'video_id': 'super-soaker', 'language_code': 'en', 'result': True}, {'video_id': 'super-soaker', 'language_code': 'en', 'result': True},
{'video_id': 'super-soaker', 'language_code': 'ur', 'result': False}, {'video_id': 'super-soaker', 'language_code': 'ur', 'result': False},
{'video_id': 'super123', 'language_code': 'en', 'result': False}, {'video_id': 'super123', 'language_code': 'en', 'result': False},
......
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