Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download subtitle files #1185

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/i18n/locales/cs-CZ.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
"createSubtitleDropdown-label": "Pick a language",
"backButton": "Back",
"backButton-tooltip": "Return to subtitle selection",
"downloadButton-title": "Download",
"downloadButton-tooltip": "Download subtitle as vtt file",
"editTitle": "Subtitle Editor - {{title}}",
"editTitle-loading": "Loading",
"generic": "Generic",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
"createSubtitleDropdown-label": "Wähle eine Sprache",
"backButton": "Zurück",
"backButton-tooltip": "Zurück zur Untertitelauswahl",
"downloadButton-title": "Herunterladen",
"downloadButton-tooltip": "Untertitel als VTT-Datei herunterladen",
"editTitle": "Untertitel-Editor - {{title}}",
"editTitle-loading": "Lädt",
"generic": "Unspezifiziert",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/el-GR.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
"createSubtitleDropdown-label": "Επιλέξτε μια γλώσσα",
"backButton": "Επιστροφή",
"backButton-tooltip": "Επιστροφή στην επιλογή υποτίτλων",
"downloadButton-title": "Κατεβάστε",
"downloadButton-tooltip": "Download subtitle as vtt file",
"editTitle": "Επεξεργαστής υποτίτλων - {{title}}",
"editTitle-loading": "Φόρτωση",
"generic": "Γενικά",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@
"createSubtitleDropdown-label": "Pick a language",
"backButton": "Back",
"backButton-tooltip": "Return to subtitle selection",
"downloadButton-title": "Download",
"downloadButton-tooltip": "Download subtitle as vtt file",
"editTitle": "Subtitle Editor - {{title}}",
"editTitle-loading": "Loading",
"generic": "Generic",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
"createSubtitleDropdown-label": "Seleccione un idioma",
"backButton": "Atras",
"backButton-tooltip": "Volver a la selección de subtítulos",
"downloadButton-title": "Descargar",
"downloadButton-tooltip": "Download subtitle as vtt file",
"editTitle": "Editor de subtítulos - {{title}}",
"editTitle-loading": "Cargando",
"generic": "Generico",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
"createSubtitleDropdown-label": "Pick a language",
"backButton": "Back",
"backButton-tooltip": "Return to subtitle selection",
"downloadButton-title": "Download",
"downloadButton-tooltip": "Download subtitle as vtt file",
"editTitle": "Subtitle Editor - {{title}}",
"editTitle-loading": "Loading",
"generic": "Generic",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
"createSubtitleDropdown-label": "Pick a language",
"backButton": "Back",
"backButton-tooltip": "Return to subtitle selection",
"downloadButton-title": "Download",
"downloadButton-tooltip": "Download subtitle as vtt file",
"editTitle": "Subtitle Editor - {{title}}",
"editTitle-loading": "Loading",
"generic": "Generic",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
"createSubtitleDropdown-label": "Pick a language",
"backButton": "Back",
"backButton-tooltip": "Return to subtitle selection",
"downloadButton-title": "Download",
"downloadButton-tooltip": "Download subtitle as vtt file",
"editTitle": "Subtitle Editor - {{title}}",
"editTitle-loading": "Loading",
"generic": "Generic",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
"createSubtitleDropdown-label": "Pick a language",
"backButton": "Back",
"backButton-tooltip": "Return to subtitle selection",
"downloadButton-title": "Download",
"downloadButton-tooltip": "Download subtitle as vtt file",
"editTitle": "Subtitle Editor - {{title}}",
"editTitle-loading": "Loading",
"generic": "Generic",
Expand Down
47 changes: 44 additions & 3 deletions src/main/SubtitleEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";
import { css } from "@emotion/react";
import { basicButtonStyle, flexGapReplacementStyle } from "../cssStyles";
import { LuChevronLeft} from "react-icons/lu";
import { LuChevronLeft, LuDownload} from "react-icons/lu";
import {
selectSubtitlesFromOpencastById,
} from '../redux/videoSlice'
Expand All @@ -17,7 +17,7 @@ import SubtitleVideoArea from "./SubtitleVideoArea";
import SubtitleTimeline from "./SubtitleTimeline";
import { useTranslation } from "react-i18next";
import { useTheme } from "../themes";
import { parseSubtitle } from "../util/utilityFunctions";
import { parseSubtitle, serializeSubtitle } from "../util/utilityFunctions";
import { ThemedTooltip } from "./Tooltip";
import { titleStyle, titleStyleBold } from "../cssStyles";
import { generateButtonTitle } from "./SubtitleSelect";
Expand Down Expand Up @@ -109,7 +109,7 @@ const SubtitleEditor : React.FC = () => {
<div css={[titleStyle(theme), titleStyleBold(theme)]}>
{t("subtitles.editTitle", {title: getTitle()})}
</div>
<div css={{width: '50px'}}></div>
<DownloadButton/>
</div>
<div css={subAreaStyle}>
<SubtitleListEditor />
Expand All @@ -128,6 +128,47 @@ const SubtitleEditor : React.FC = () => {
);
}

const DownloadButton: React.FC = () => {

const subtitle = useSelector(selectSelectedSubtitleById);

const downloadSubtitles = () => {

const vttFile = new Blob([serializeSubtitle(subtitle.cues)], {type: 'text/vtt'});

const vttFileLink = window.URL.createObjectURL(vttFile);
const vttHyperLink = document.createElement('a');
vttHyperLink.setAttribute('href', vttFileLink);

const vttFileName = generateButtonTitle(subtitle.tags, t).trimEnd();
vttHyperLink.setAttribute('download', `${vttFileName}.vtt`);
vttHyperLink.click();
}

const { t } = useTranslation();
const theme = useTheme();
const style = css({
fontSize: '16px',
height: '10px',
padding: '16px',
justifyContent: 'space-around',
boxShadow: `${theme.boxShadow}`,
background: `${theme.element_bg}`,
});

return (
<ThemedTooltip title={t("subtitles.downloadButton-tooltip")}>
<div css={[basicButtonStyle(theme), style]}
role="button"
onClick={() => downloadSubtitles()}
>
<LuDownload css={{fontSize: '16px'}}/>
<span>{t("subtitles.downloadButton-title")}</span>
</div>
</ThemedTooltip>
);
}


/**
* Takes you to a different page
Expand Down
Loading