fix: importing transcript from YouTube TNL-9460
Co-authored-by: Crist Ye <iamCristYe@Outlook.com>
This commit is contained in:
committed by
Bernard Szabo
parent
5bb84e9962
commit
44158ec844
@@ -7,12 +7,10 @@ All user changes are saved immediately.
|
||||
"""
|
||||
|
||||
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
import requests
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.exceptions import PermissionDenied
|
||||
@@ -42,7 +40,7 @@ from xmodule.video_module.transcripts_utils import ( # lint-amnesty, pylint: di
|
||||
get_transcript_for_video,
|
||||
get_transcript_from_val,
|
||||
get_transcripts_from_youtube,
|
||||
youtube_video_transcript_name
|
||||
get_transcript_link_from_youtube
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
@@ -340,15 +338,7 @@ def check_transcripts(request): # lint-amnesty, pylint: disable=too-many-statem
|
||||
except NotFoundError:
|
||||
log.debug("Can't find transcripts in storage for youtube id: %s", youtube_id)
|
||||
|
||||
# youtube server
|
||||
youtube_text_api = copy.deepcopy(settings.YOUTUBE['TEXT_API'])
|
||||
youtube_text_api['params']['v'] = youtube_id
|
||||
youtube_transcript_name = youtube_video_transcript_name(youtube_text_api)
|
||||
if youtube_transcript_name:
|
||||
youtube_text_api['params']['name'] = youtube_transcript_name
|
||||
youtube_response = requests.get('http://' + youtube_text_api['url'], params=youtube_text_api['params'])
|
||||
|
||||
if youtube_response.status_code == 200 and youtube_response.text:
|
||||
if get_transcript_link_from_youtube(youtube_id):
|
||||
transcripts_presence['youtube_server'] = True
|
||||
#check youtube local and server transcripts for equality
|
||||
if transcripts_presence['youtube_server'] and transcripts_presence['youtube_local']:
|
||||
|
||||
@@ -1526,6 +1526,11 @@ YOUTUBE = {
|
||||
},
|
||||
},
|
||||
|
||||
'TRANSCRIPTS': {
|
||||
'CAPTION_TRACKS_REGEX': r"captionTracks\"\:\[(?P<caption_tracks>[^\]]+)",
|
||||
'YOUTUBE_URL_BASE': 'https://www.youtube.com/watch?v=',
|
||||
},
|
||||
|
||||
'IMAGE_API': 'http://img.youtube.com/vi/{youtube_id}/0.jpg', # /maxresdefault.jpg for 1920*1080
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user