Merge pull request #69 from JonasCz/use-actual-filename
Use actual filename of uploaded media instead of "subtitles.srt" when downloading transcription
This commit is contained in:
@@ -10,16 +10,19 @@
|
|||||||
console.log("download subtitle");
|
console.log("download subtitle");
|
||||||
let segments = [];
|
let segments = [];
|
||||||
let text = "";
|
let text = "";
|
||||||
|
let title = "subtitles";
|
||||||
|
|
||||||
console.log(language)
|
console.log(language)
|
||||||
if (language == "original") {
|
if (language == "original") {
|
||||||
segments = tr.result.segments;
|
segments = tr.result.segments;
|
||||||
text = tr.result.text;
|
text = tr.result.text;
|
||||||
|
title = tr.fileName.split("_WHSHPR_")[1]
|
||||||
} else {
|
} else {
|
||||||
for (const translation of tr.translations) {
|
for (const translation of tr.translations) {
|
||||||
if (translation.targetLanguage == language) {
|
if (translation.targetLanguage == language) {
|
||||||
segments = translation.result.segments;
|
segments = translation.result.segments;
|
||||||
text = translation.result.text;
|
text = translation.result.text;
|
||||||
|
title = tr.fileName.split("_WHSHPR_")[1]
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,13 +34,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (subtitleFormat == "srt") {
|
if (subtitleFormat == "srt") {
|
||||||
downloadSRT(segments);
|
downloadSRT(segments, title);
|
||||||
} else if (subtitleFormat == "vtt") {
|
} else if (subtitleFormat == "vtt") {
|
||||||
downloadVTT(segments);
|
downloadVTT(segments, title);
|
||||||
} else if (subtitleFormat == "json") {
|
} else if (subtitleFormat == "json") {
|
||||||
downloadJSON(tr.result);
|
downloadJSON(tr.result, title);
|
||||||
} else if (subtitleFormat == "txt") {
|
} else if (subtitleFormat == "txt") {
|
||||||
downloadTXT(text);
|
downloadTXT(text, title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export const getRandomSentence = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Expects a segments array with start, end and text properties
|
// Expects a segments array with start, end and text properties
|
||||||
export const downloadSRT = function (jsonData) {
|
export const downloadSRT = function (jsonData, title) {
|
||||||
let srtContent = '';
|
let srtContent = '';
|
||||||
|
|
||||||
jsonData.forEach((segment, index) => {
|
jsonData.forEach((segment, index) => {
|
||||||
@@ -71,32 +71,32 @@ export const downloadSRT = function (jsonData) {
|
|||||||
let url = URL.createObjectURL(srtBlob);
|
let url = URL.createObjectURL(srtBlob);
|
||||||
let link = document.createElement('a');
|
let link = document.createElement('a');
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.download = 'subtitles.srt';
|
link.download = `${title}.srt`;
|
||||||
link.click();
|
link.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Downloads received text as a TXT file
|
// Downloads received text as a TXT file
|
||||||
export const downloadTXT = function (text) {
|
export const downloadTXT = function (text, title) {
|
||||||
let srtBlob = new Blob([text], {type: 'text/plain'});
|
let srtBlob = new Blob([text], {type: 'text/plain'});
|
||||||
let url = URL.createObjectURL(srtBlob);
|
let url = URL.createObjectURL(srtBlob);
|
||||||
let link = document.createElement('a');
|
let link = document.createElement('a');
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.download = 'subtitles.txt';
|
link.download = `${title}.txt`;
|
||||||
link.click();
|
link.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Downloads received JSON data as a JSON file
|
// Downloads received JSON data as a JSON file
|
||||||
export const downloadJSON = function (jsonData) {
|
export const downloadJSON = function (jsonData, title) {
|
||||||
let srtBlob = new Blob([JSON.stringify(jsonData)], {type: 'text/plain'});
|
let srtBlob = new Blob([JSON.stringify(jsonData)], {type: 'text/plain'});
|
||||||
let url = URL.createObjectURL(srtBlob);
|
let url = URL.createObjectURL(srtBlob);
|
||||||
let link = document.createElement('a');
|
let link = document.createElement('a');
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.download = 'subtitles.json';
|
link.download = `${title}.json`;
|
||||||
link.click();
|
link.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expects a segments array with start, end and text properties
|
// Expects a segments array with start, end and text properties
|
||||||
export const downloadVTT = function (jsonData) {
|
export const downloadVTT = function (jsonData, title) {
|
||||||
let vttContent = 'WEBVTT\n\n'; // VTT files start with "WEBVTT" line
|
let vttContent = 'WEBVTT\n\n'; // VTT files start with "WEBVTT" line
|
||||||
|
|
||||||
jsonData.forEach((segment, index) => {
|
jsonData.forEach((segment, index) => {
|
||||||
@@ -115,7 +115,7 @@ export const downloadVTT = function (jsonData) {
|
|||||||
let url = URL.createObjectURL(vttBlob);
|
let url = URL.createObjectURL(vttBlob);
|
||||||
let link = document.createElement('a');
|
let link = document.createElement('a');
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.download = 'subtitles.vtt';
|
link.download = `${title}.vtt`;
|
||||||
link.click();
|
link.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user