Skip to content

Commit

Permalink
feat: change youtube api for transcripts
Browse files Browse the repository at this point in the history
  • Loading branch information
amirtds committed Mar 3, 2022
1 parent 645a393 commit 4369535
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 236 deletions.
1 change: 1 addition & 0 deletions cms/djangoapps/contentstore/features/transcripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'download_to_edit': ('.setting-download', 'Download Transcript for Editing'),
'disabled_download_to_edit': ('.setting-download.is-disabled', 'Download Transcript for Editing'),
'upload_new_timed_transcripts': ('.setting-upload', 'Upload New Transcript'),
'download_youtube_transcripts': ('.setting-download-youtube-transcript', 'Download YouTube Transcript'),
'replace': ('.setting-replace', 'Yes, replace the edX transcript with the YouTube transcript'),
'choose': ('.setting-choose', 'Timed Transcript from {}'),
'use_existing': ('.setting-use-existing', 'Use Current Transcript'),
Expand Down
12 changes: 8 additions & 4 deletions cms/djangoapps/contentstore/views/transcripts_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def upload_transcripts(request):
except (InvalidKeyError, ItemNotFoundError):
return error_response(response, "Can't find item by locator.")

if 'transcript-file' not in request.FILES:
if 'transcript-file' not in request.FILES and not request.POST.get('transcript-file'):
return error_response(response, 'POST data without "file" form data.')

video_list = request.POST.get('video_list')
Expand All @@ -99,9 +99,13 @@ def upload_transcripts(request):
except ValueError:
return error_response(response, 'Invalid video_list JSON.')

# Used utf-8-sig encoding type instead of utf-8 to remove BOM(Byte Order Mark), e.g. U+FEFF
source_subs_filedata = request.FILES['transcript-file'].read().decode('utf-8-sig')
source_subs_filename = request.FILES['transcript-file'].name
if 'transcript-file' in request.FILES:
# Used utf-8-sig encoding type instead of utf-8 to remove BOM(Byte Order Mark), e.g. U+FEFF
source_subs_filedata = request.FILES['transcript-file'].read().decode('utf-8-sig')
source_subs_filename = request.FILES['transcript-file'].name
elif request.POST.get('transcript-file') and request.POST.get('transcript-name'):
source_subs_filedata = request.POST.get('transcript-file').encode('utf-8')
source_subs_filename = request.POST.get('transcript-name')

if '.' not in source_subs_filename:
return error_response(response, "Undefined file extension.")
Expand Down
Loading

0 comments on commit 4369535

Please sign in to comment.