Skip to content

Commit

Permalink
Merge pull request #859 from AI4Bharat/minorchange-02
Browse files Browse the repository at this point in the history
changes for export filename
  • Loading branch information
kartikvirendrar authored Dec 19, 2024
2 parents 2c500f5 + 4cb8f43 commit d8a7b37
Showing 1 changed file with 48 additions and 11 deletions.
59 changes: 48 additions & 11 deletions src/utils/subtitleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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], {
Expand Down Expand Up @@ -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}`;
}
Expand Down

0 comments on commit d8a7b37

Please sign in to comment.