Commit 610f43af by Qubad786

EDUCATOR-1992 – Make transcript filenames human readable

parent cd3d5f30
...@@ -247,7 +247,7 @@ def get_video_transcript_data(video_ids, language_code): ...@@ -247,7 +247,7 @@ def get_video_transcript_data(video_ids, language_code):
try: try:
video_transcript = VideoTranscript.objects.get(video_id=video_id, language_code=language_code) video_transcript = VideoTranscript.objects.get(video_id=video_id, language_code=language_code)
transcript_data = dict( transcript_data = dict(
file_name=video_transcript.transcript.name, file_name=video_transcript.filename,
content=video_transcript.transcript.file.read() content=video_transcript.transcript.file.read()
) )
break break
......
...@@ -417,6 +417,28 @@ class VideoTranscript(TimeStampedModel): ...@@ -417,6 +417,28 @@ class VideoTranscript(TimeStampedModel):
class Meta: class Meta:
unique_together = ('video_id', 'language_code') unique_together = ('video_id', 'language_code')
@property
def filename(self):
"""
Returns readable filename for a transcript
"""
try:
video = Video.objects.get(edx_video_id=self.video_id)
client_id, __ = os.path.splitext(video.client_video_id)
file_name = u'{name}-{language}.{format}'.format(
name=client_id,
language=self.language_code,
format=self.file_format
)
except Video.DoesNotExist:
file_name = u'{name}-{language}.{format}'.format(
name=self.video_id,
language=self.language_code,
format=self.file_format
)
return file_name
@classmethod @classmethod
def get_or_none(cls, video_id, language_code): def get_or_none(cls, video_id, language_code):
""" """
......
...@@ -373,7 +373,7 @@ VIDEO_TRANSCRIPT_CIELO24 = dict( ...@@ -373,7 +373,7 @@ VIDEO_TRANSCRIPT_CIELO24 = dict(
VIDEO_TRANSCRIPT_3PLAY = dict( VIDEO_TRANSCRIPT_3PLAY = dict(
video_id='super-soaker', video_id='super-soaker',
language_code='de', language_code='de',
transcript='wow.sjson', transcript='edxval/tests/data/wow.sjson',
provider=TranscriptProviderType.THREE_PLAY_MEDIA, provider=TranscriptProviderType.THREE_PLAY_MEDIA,
file_format=TranscriptFormat.SJSON, file_format=TranscriptFormat.SJSON,
) )
......
{
"start": [10],
"end": [100],
"text": ["Hi, welcome to edxval."],
}
\ No newline at end of file
...@@ -137,7 +137,6 @@ class CreateVideoTest(TestCase): ...@@ -137,7 +137,6 @@ class CreateVideoTest(TestCase):
api.create_video(data) api.create_video(data)
@ddt @ddt
class UpdateVideoTest(TestCase): class UpdateVideoTest(TestCase):
""" """
...@@ -957,7 +956,7 @@ class ExportTest(TestCase): ...@@ -957,7 +956,7 @@ class ExportTest(TestCase):
<encoded_video url="http://www.meowmagic.com" file_size="33" bitrate="44" profile="desktop"/> <encoded_video url="http://www.meowmagic.com" file_size="33" bitrate="44" profile="desktop"/>
<encoded_video url="https://www.tmnt.com/tmnt101.m3u8" file_size="100" bitrate="0" profile="hls"/> <encoded_video url="https://www.tmnt.com/tmnt101.m3u8" file_size="100" bitrate="0" profile="hls"/>
<transcripts> <transcripts>
<transcript file_format="sjson" file_name="wow.sjson" language_code="de" provider="3PlayMedia" video_id="super-soaker"/> <transcript file_format="sjson" file_name="edxval/tests/data/wow.sjson" language_code="de" provider="3PlayMedia" video_id="super-soaker"/>
<transcript file_format="srt" file_name="wow.srt" language_code="en" provider="Cielo24" video_id="super-soaker" /> <transcript file_format="srt" file_name="wow.srt" language_code="en" provider="Cielo24" video_id="super-soaker" />
</transcripts> </transcripts>
</video_asset> </video_asset>
...@@ -1296,7 +1295,7 @@ class ImportTest(TestCase): ...@@ -1296,7 +1295,7 @@ class ImportTest(TestCase):
<video_asset> <video_asset>
<transcripts> <transcripts>
<transcript file_name="wow.srt" language_code="en" file_format="srt" provider='Cielo24' video_id="{video_id}"/> <transcript file_name="wow.srt" language_code="en" file_format="srt" provider='Cielo24' video_id="{video_id}"/>
<transcript file_name="wow.sjson" language_code="de" file_format="sjson" provider='3PlayMedia' video_id="{video_id}"/> <transcript file_name="edxval/tests/data/wow.sjson" language_code="de" file_format="sjson" provider='3PlayMedia' video_id="{video_id}"/>
</transcripts> </transcripts>
</video_asset> </video_asset>
""".format(video_id=external_video_id)) """.format(video_id=external_video_id))
...@@ -1328,7 +1327,7 @@ class ImportTest(TestCase): ...@@ -1328,7 +1327,7 @@ class ImportTest(TestCase):
<video_asset> <video_asset>
<transcripts> <transcripts>
{transcript_xml} {transcript_xml}
<transcript file_name="wow.sjson" language_code="de" file_format="sjson" provider='3PlayMedia' video_id="{video_id}"/> <transcript file_name="edxval/tests/data/wow.sjson" language_code="de" file_format="sjson" provider='3PlayMedia' video_id="{video_id}"/>
</transcripts> </transcripts>
</video_asset> </video_asset>
""".format(transcript_xml=transcript_xml, video_id=video_id)) """.format(transcript_xml=transcript_xml, video_id=video_id))
...@@ -1765,17 +1764,22 @@ class TranscriptTest(TestCase): ...@@ -1765,17 +1764,22 @@ class TranscriptTest(TestCase):
transcript = api.get_video_transcript_data(video_ids, language_code) transcript = api.get_video_transcript_data(video_ids, language_code)
self.assertEqual(transcript, result) self.assertEqual(transcript, result)
def test_get_video_transcript_data(self): @data(
('de', 'Shallow Swordfish-de.sjson', 'edxval/tests/data/wow.sjson'),
('ur', '0987654321-ur.srt', 'edxval/tests/data/The_Arrow.srt')
)
@unpack
def test_get_video_transcript_data(self, language_code, expected_file_name, expected_transcript_path):
""" """
Verify that `get_video_transcript_data` api function works as expected. Verify that `get_video_transcript_data` api function works as expected.
""" """
expected_transcript = { expected_transcript = {
'file_name': self.transcript_url, 'file_name': expected_file_name,
'content': File(open(self.arrow_transcript_path)).read() 'content': File(open(expected_transcript_path)).read()
} }
transcript = api.get_video_transcript_data( transcript = api.get_video_transcript_data(
video_ids=['super-soaker', '0987654321'], video_ids=['super-soaker', '0987654321'],
language_code=u'ur' language_code=language_code
) )
self.assertDictEqual(transcript, expected_transcript) self.assertDictEqual(transcript, expected_transcript)
......
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