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

Add ability to upload hearing-impaired subs #4728

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 26 additions & 2 deletions src/components/subtitleuploader/subtitleuploader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import escapeHtml from 'escape-html';

import { getSubtitleApi } from '@jellyfin/sdk/lib/utils/api/subtitle-api';
import { toApi } from 'utils/jellyfin-apiclient/compat';
import dialogHelper from '../../components/dialogHelper/dialogHelper';
import ServerConnections from '../ServerConnections';
import dom from '../../scripts/dom';
Expand Down Expand Up @@ -75,7 +77,20 @@ function setFiles(page, files) {
reader.readAsDataURL(file);
}

function onSubmit(e) {
function getStringFromFile(file) {
thornbill marked this conversation as resolved.
Show resolved Hide resolved
return new Promise(function (resolve, reject) {
const reader = new FileReader();
reader.onload = (e) => {
// Split by a comma to remove the url: prefix
const data = e.target.result.split(',')[1];
resolve(data);
};
reader.onerror = reject;
reader.readAsDataURL(file);
});
}

async function onSubmit(e) {
const file = currentFile;

if (!isValidSubtitleFile(file)) {
Expand All @@ -89,8 +104,17 @@ function onSubmit(e) {
const dlg = dom.parentWithClass(this, 'dialog');
const language = dlg.querySelector('#selectLanguage').value;
const isForced = dlg.querySelector('#chkIsForced').checked;
const isHearingImpaired = dlg.querySelector('#chkIsHearingImpaired').checked;

const subtitleApi = getSubtitleApi(toApi(ServerConnections.getApiClient(currentServerId)));

const data = await getStringFromFile(file);
const format = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase();

ServerConnections.getApiClient(currentServerId).uploadItemSubtitle(currentItemId, language, isForced, file).then(function () {
subtitleApi.uploadSubtitle({
itemId: currentItemId,
uploadSubtitleDto: { Data: data, Language: language, IsForced: isForced, Format: format, IsHearingImpaired: isHearingImpaired }
}).then(function () {
dlg.querySelector('#uploadSubtitle').value = '';
loading.hide();
hasChanges = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ <h2 style="margin:0;">${HeaderAddUpdateSubtitle}</h2>
<input type="checkbox" is="emby-checkbox" id="chkIsForced" />
<span>${LabelIsForced}</span>
</label>
<label>
<input type="checkbox" is="emby-checkbox" id="chkIsHearingImpaired" />
<span>${LabelIsHearingImpaired}</span>
</label>
</div>
<div class="selectContainer flex-grow">
<select is="emby-select" id="selectLanguage" required="required" label="${LabelLanguage}"></select>
Expand Down
3 changes: 2 additions & 1 deletion src/strings/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1722,5 +1722,6 @@
"AiTranslated": "AI Translated",
"MachineTranslated": "Machine Translated",
"ForeignPartsOnly": "Forced/Foreign parts only",
"HearingImpairedShort": "HI/SDH"
"HearingImpairedShort": "HI/SDH",
"LabelIsHearingImpaired": "For hearing impaired (SDH)"
thornbill marked this conversation as resolved.
Show resolved Hide resolved
}
Loading