diff --git a/src/utils/subtitleUtils.js b/src/utils/subtitleUtils.js index b434e1e6..bc9f50b2 100644 --- a/src/utils/subtitleUtils.js +++ b/src/utils/subtitleUtils.js @@ -5,6 +5,7 @@ import store from "../redux/store/store"; import { noiseTags } from "config"; import { specialOrgIds } from "config"; import getLocalStorageData from "./getLocalStorageData"; +import { FetchVideoDetailsAPI } from "redux/actions"; export const newSub = (item) => { return new Sub(item); @@ -677,42 +678,76 @@ export const paraphrase = (index) => { return copySub; }; -export const exportVoiceover = (data, taskDetails, exportTypes) => { +export const exportVoiceover = async (data, taskDetails, exportTypes) => { const userOrgId = getLocalStorageData("userData").organization.id; - const { video_name: videoName, target_language: targetLanguage } = + const { video_name: videoName, target_language: targetLanguage, project, video_url, src_language } = taskDetails; + const apiObj = new FetchVideoDetailsAPI( + video_url, + src_language, + project + ); + const res = await fetch(apiObj.apiEndPoint(), { + method: "GET", + headers: apiObj.getHeaders().headers, + }); + const video = await res.json(); + console.log(video); + const { voiceover } = exportTypes; if (data.azure_url) { - const link = document.createElement("a"); - link.href = data.azure_url; - let fileName = ""; if (specialOrgIds.includes(userOrgId)) { fileName = data.video_name + } else if (video?.video?.description?.length){ + fileName = `${video.video.description}.${voiceover}`; } else { fileName = `Chitralekha_Video_${videoName}_${getDateTime()}_${targetLanguage}.${voiceover}`; } - link.setAttribute("download", fileName); + fetch(data.azure_url) + .then(response => response.blob()) + .then(blob => { + const url = URL.createObjectURL(blob); + const link = document.createElement("a"); + link.href = url; + link.setAttribute("download", fileName); + + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); - document.body.appendChild(link); - link.click(); - link.parentNode.removeChild(link); + URL.revokeObjectURL(url); + }) + .catch(error => console.error("Error downloading file:", error)); } }; -export const exportFile = (data, taskDetails, exportType, type) => { +export const exportFile = async (data, taskDetails, exportType, type) => { const { video: videoId, src_language: sourceLanguage, target_language: targetLanguage, - description, + description, + project, + video_url } = taskDetails; const userOrgId = getLocalStorageData("userData").organization.id; + const apiObj = new FetchVideoDetailsAPI( + video_url, + sourceLanguage, + project + ); + const res = await fetch(apiObj.apiEndPoint(), { + method: "GET", + headers: apiObj.getHeaders().headers, + }); + const video = await res.json(); + let newBlob; if (exportType === "docx") { newBlob = new Blob([data], { @@ -740,6 +775,8 @@ export const exportFile = (data, taskDetails, exportType, type) => { let fileName = ""; if (specialOrgIds.includes(userOrgId) && description.length) { fileName = `${description}.${format}`; + } else if(video?.video?.description?.length){ + fileName = `${video.video.description}.${format}`; } else { fileName = `Chitralekha_Video${videoId}_${YYYYMMDD}_${HHMMSS}_${language}.${format}`; }