Commit c9e9f6e6 by Alexander Kryklia

Remove duplicate code in transcripts_ajax.

parent 982f24ae
...@@ -115,29 +115,20 @@ def upload_transcripts(request): ...@@ -115,29 +115,20 @@ def upload_transcripts(request):
# Allow upload only if any video link is presented # Allow upload only if any video link is presented
if video_list: if video_list:
sub_attr = source_subs_name sub_attr = source_subs_name
try:
try: # Generate and save for 1.0 speed, will create subs_sub_attr.srt.sjson subtitles file in storage. # Generate and save for 1.0 speed, will create subs_sub_attr.srt.sjson subtitles file in storage.
generate_subs_from_source({1: sub_attr}, source_subs_ext, source_subs_filedata, item) generate_subs_from_source({1: sub_attr}, source_subs_ext, source_subs_filedata, item)
except TranscriptsGenerationException as e:
return error_response(response, e.message) for video_dict in video_list:
statuses = {} video_name = video_dict['video']
for video_dict in video_list: # We are creating transcripts for every video source, if in future some of video sources would be deleted.
video_name = video_dict['video'] # Updates item.sub with `video_name` on success.
# We are creating transcripts for every video source,
# for the case that in future, some of video sources can be deleted.
statuses[video_name] = copy_or_rename_transcript(video_name, sub_attr, item, user=request.user)
try:
# updates item.sub with `video_name` if it is successful.
copy_or_rename_transcript(video_name, sub_attr, item, user=request.user) copy_or_rename_transcript(video_name, sub_attr, item, user=request.user)
selected_name = video_name # name to write to item.sub field, chosen at random.
except NotFoundError:
# subtitles file `sub_attr` is not presented in the system. Nothing to copy or rename.
return error_response(response, "Can't find transcripts in storage for {}".format(sub_attr))
item.sub = selected_name # write one of new subtitles names to item.sub attribute. response['subs'] = item.sub
item.save_with_metadata(request.user) response['status'] = 'Success'
response['subs'] = item.sub except Exception as ex:
response['status'] = 'Success' return error_response(response, ex.message)
else: else:
return error_response(response, 'Empty video sources.') return error_response(response, 'Empty video sources.')
......
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