Commit 6c4e4e85 by muhammad-ammar

address feedback

parent ab1e81ba
...@@ -135,17 +135,21 @@ class TestUploadTranscripts(BaseTranscripts): ...@@ -135,17 +135,21 @@ class TestUploadTranscripts(BaseTranscripts):
self.ufeff_srt_file = tempfile.NamedTemporaryFile(suffix='.srt') self.ufeff_srt_file = tempfile.NamedTemporaryFile(suffix='.srt')
def assert_transcript_upload(self, filename, expected_transcript_content): def assert_transcript_upload(self, subs_id, expected_transcript_content):
""" """
Verify that transcript is uploaded as expected Verify that transcript is uploaded as expected.
Arguments:
subs_id (str): subtitle id
expected_transcript_content (str): transcript content be checked
""" """
# verify that transcript should not be in contentstore # verify that transcript should not be in contentstore
content_location = StaticContent.compute_location(self.course.id, 'subs_{0}.srt.sjson'.format(filename)) content_location = StaticContent.compute_location(self.course.id, 'subs_{0}.srt.sjson'.format(subs_id))
with self.assertRaises(NotFoundError): with self.assertRaises(NotFoundError):
contentstore().find(content_location) contentstore().find(content_location)
# verify uploaded transcript content # verify uploaded transcript content
transcript_data = edxval_api.get_video_transcript_data([filename], 'en') transcript_data = edxval_api.get_video_transcript_data([subs_id], 'en')
sjson_transcript = transcript_data['content'] sjson_transcript = transcript_data['content']
uploaded_transcript_content = transcripts_utils.Transcript.convert( uploaded_transcript_content = transcripts_utils.Transcript.convert(
sjson_transcript, sjson_transcript,
......
...@@ -11,15 +11,16 @@ import logging ...@@ -11,15 +11,16 @@ import logging
import os import os
import requests import requests
from django.conf import settings from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.core.files.base import ContentFile from django.core.files.base import ContentFile
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from edxval import api as edxval_api
from opaque_keys import InvalidKeyError from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import UsageKey from opaque_keys.edx.keys import UsageKey
from student.auth import has_course_author_access from student.auth import has_course_author_access
from util.json_request import JsonResponse from util.json_request import JsonResponse
from xmodule.contentstore.content import StaticContent from xmodule.contentstore.content import StaticContent
...@@ -28,20 +29,19 @@ from xmodule.exceptions import NotFoundError ...@@ -28,20 +29,19 @@ from xmodule.exceptions import NotFoundError
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.exceptions import ItemNotFoundError
from xmodule.video_module.transcripts_utils import ( from xmodule.video_module.transcripts_utils import (
GetTranscriptsFromYouTubeException,
Transcript,
TranscriptsRequestValidationException,
copy_or_rename_transcript, copy_or_rename_transcript,
download_youtube_subs, download_youtube_subs,
GetTranscriptsFromYouTubeException,
get_video_transcript_content,
generate_subs_from_source, generate_subs_from_source,
get_transcripts_from_youtube, get_transcripts_from_youtube,
get_video_transcript_content,
is_val_transcript_feature_enabled_for_course, is_val_transcript_feature_enabled_for_course,
manage_video_subtitles_save, manage_video_subtitles_save,
remove_subs_from_store, remove_subs_from_store,
Transcript, youtube_video_transcript_name
TranscriptsRequestValidationException,
youtube_video_transcript_name,
) )
from edxval import api as edxval_api
__all__ = [ __all__ = [
'upload_transcripts', 'upload_transcripts',
...@@ -125,20 +125,20 @@ def upload_transcripts(request): ...@@ -125,20 +125,20 @@ def upload_transcripts(request):
sjson_subs = generate_subs_from_source({}, source_subs_ext, source_subs_filedata, item) sjson_subs = generate_subs_from_source({}, source_subs_ext, source_subs_filedata, item)
for video_dict in video_list: for video_dict in video_list:
video_name = video_dict['video'] video_id = video_dict['video']
# We are creating transcripts for every video source in case a video source is deleted in future. # We are creating transcripts for every video source in case a video source is deleted in future.
edxval_api.create_or_update_video_transcript( edxval_api.create_or_update_video_transcript(
video_id=video_name, video_id=video_id,
language_code='en', language_code='en',
file_name='subs.sjson', # S3 filename will be `uuid.sjson` like 5d30d3e44cebacf6163976388cae.sjson file_name='subs.sjson', # S3 filename will be `{uuid}.sjson` like 5d30d3ehebacf6163976388cae.sjson
file_format='sjson', file_format='sjson',
provider='Custom', provider='Custom',
file_data=ContentFile(json.dumps(sjson_subs)), file_data=ContentFile(json.dumps(sjson_subs)),
) )
item.sub = video_name item.sub = video_id
item.save_with_metadata(request.user) item.save_with_metadata(request.user)
response['subs'] = video_name response['subs'] = video_id
response['status'] = 'Success' response['status'] = 'Success'
except Exception as ex: except Exception as ex:
return error_response(response, ex.message) return error_response(response, ex.message)
......
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