1- import { getCloudinaryUrl , extendCloudinaryConfig } from 'plugins/cloudinary/common' ;
1+ import { getCloudinaryUrlPrefix } from '../cloudinary/common' ;
2+ import { utf8ToBase64 } from '../../utils/utf8Base64' ;
23
34const fallbackFetch = async ( url , fallback ) => {
45 try {
@@ -32,6 +33,9 @@ function pacedTranscript(config) {
3233 const classNames = player . textTrackDisplay . el ( ) . classList ;
3334 classNames . add ( 'cld-paced-text-tracks' ) ;
3435
36+ const getTranscriptionFileUrl = ( urlPrefix , deliveryType , publicId , languageCode = null ) =>
37+ `${ urlPrefix } /_applet_/video_service/transcription/${ deliveryType } /${ languageCode ? `${ languageCode } /` : '' } ${ utf8ToBase64 ( publicId ) } .transcript` ;
38+
3539 // Load the transcription file
3640 const initTranscript = async ( ) => {
3741
@@ -42,14 +46,16 @@ function pacedTranscript(config) {
4246 } else {
4347 // If not, and provided language, try fetching translated transcript, fallback to base transcript
4448 const source = player . cloudinary . source ( ) ;
45- const basePath = getCloudinaryUrl (
46- source . publicId ( ) ,
47- extendCloudinaryConfig ( player . cloudinary . cloudinaryConfig ( ) , { resource_type : 'raw' } )
48- ) ;
49+ const sourcePublicId = source . publicId ( ) ;
50+ const sourceDeliveryType = source . resourceConfig ( ) . type ;
51+ const urlPrefix = getCloudinaryUrlPrefix ( player . cloudinary . cloudinaryConfig ( ) ) ;
52+ const transcriptionFileUrl = getTranscriptionFileUrl ( urlPrefix , sourceDeliveryType , sourcePublicId ) ;
53+
4954 if ( options . srclang ) {
50- transcriptResponse = await fallbackFetch ( `${ basePath } .${ options . srclang } .transcript` , `${ basePath } .transcript` ) ;
55+ const transcriptionTranslationFileUrl = getTranscriptionFileUrl ( urlPrefix , sourceDeliveryType , sourcePublicId , options . srclang ) ;
56+ transcriptResponse = await fallbackFetch ( transcriptionTranslationFileUrl , transcriptionFileUrl ) ;
5157 } else {
52- transcriptResponse = await fallbackFetch ( ` ${ basePath } .transcript` ) ;
58+ transcriptResponse = await fallbackFetch ( transcriptionFileUrl ) ;
5359 }
5460 }
5561 if ( ! transcriptResponse ?. ok ) return ;
0 commit comments