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 lyric fetcher settings to library options #5881

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
51 changes: 50 additions & 1 deletion src/components/libraryoptionseditor/libraryoptionseditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,40 @@ function renderSubtitleFetchers(page, availableOptions, libraryOptions) {
elem.innerHTML = html;
}

function renderLyricFetchers(page, availableOptions, libraryOptions) {
let html = '';
const elem = page.querySelector('.lyricFetchers');

let plugins = availableOptions.LyricFetchers;
plugins = getOrderedPlugins(plugins, libraryOptions.LyricFetcherOrder || []);
crobibero marked this conversation as resolved.
Show resolved Hide resolved
crobibero marked this conversation as resolved.
Show resolved Hide resolved
if (!plugins.length) return html;

html += `<h3 class="checkboxListLabel">${globalize.translate('LabelLyricDownloaders')}</h3>`;
html += '<div class="checkboxList paperList checkboxList-paperList">';
console.log(libraryOptions);
crobibero marked this conversation as resolved.
Show resolved Hide resolved
for (let i = 0; i < plugins.length; i++) {
const plugin = plugins[i];
html += `<div class="listItem lyricFetcherItem sortableOption" data-pluginname="${escapeHtml(plugin.Name)}">`;
const isChecked = libraryOptions.DisabledLyricFetchers ? !libraryOptions.DisabledLyricFetchers.includes(plugin.Name) : plugin.DefaultEnabled;
const checkedHtml = isChecked ? ' checked="checked"' : '';
html += `<label class="listItemCheckboxContainer"><input type="checkbox" is="emby-checkbox" class="chkLyricFetcher" data-pluginname="${escapeHtml(plugin.Name)}" ${checkedHtml}><span></span></label>`;
html += '<div class="listItemBody">';
html += '<h3 class="listItemBodyText">';
html += escapeHtml(plugin.Name);
html += '</h3>';
html += '</div>';
if (i > 0) {
html += `<button type="button" is="paper-icon-button-light" title="${globalize.translate('Up')}" class="btnSortableMoveUp btnSortable" data-pluginindex="${i}"><span class="material-icons keyboard_arrow_up" aria-hidden="true"></span></button>`;
} else if (plugins.length > 1) {
html += `<button type="button" is="paper-icon-button-light" title="${globalize.translate('Down')}" class="btnSortableMoveDown btnSortable" data-pluginindex="${i}"><span class="material-icons keyboard_arrow_down" aria-hidden="true"></span></button>`;
}
html += '</div>';
}
html += '</div>';
html += `<div class="fieldDescription">${globalize.translate('LyricDownloadersHelp')}</div>`;
elem.innerHTML = html;
}

function getImageFetchersForTypeHtml(availableTypeOptions, libraryOptionsForType) {
let html = '';
let plugins = availableTypeOptions.ImageFetchers;
Expand Down Expand Up @@ -284,6 +318,7 @@ function populateMetadataSettings(parent, contentType) {
renderMetadataReaders(parent, availableOptions.MetadataReaders);
renderMetadataFetchers(parent, availableOptions, {});
renderSubtitleFetchers(parent, availableOptions, {});
renderLyricFetchers(parent, availableOptions, {});
renderImageFetchers(parent, availableOptions, {});
availableOptions.SubtitleFetchers.length ? parent.querySelector('.subtitleDownloadSettings').classList.remove('hide') : parent.querySelector('.subtitleDownloadSettings').classList.add('hide');
}).catch(() => {
Expand Down Expand Up @@ -460,6 +495,18 @@ function setSubtitleFetchersIntoOptions(parent, options) {
});
}

function setLyricFetchersIntoOptions(parent, options) {
options.DisabledLyricFetchers = Array.prototype.map.call(Array.prototype.filter.call(parent.querySelectorAll('.chkLyricFetcher'), elem => {
return !elem.checked;
}), elem => {
return elem.getAttribute('data-pluginname');
});

options.LyricFetcherOrder = Array.prototype.map.call(parent.querySelectorAll('.lyricFetcherItem'), elem => {
return elem.getAttribute('data-pluginname');
});
}

function setMetadataFetchersIntoOptions(parent, options) {
const sections = parent.querySelectorAll('.metadataFetcher');
for (const section of sections) {
Expand Down Expand Up @@ -567,14 +614,15 @@ export function getLibraryOptions(parent) {
return elem.getAttribute('data-lang');
});
setSubtitleFetchersIntoOptions(parent, options);
setLyricFetchersIntoOptions(parent, options);
setMetadataFetchersIntoOptions(parent, options);
setImageFetchersIntoOptions(parent, options);
setImageOptionsIntoOptions(options);

return options;
}

function getOrderedPlugins(plugins, configuredOrder) {
function getOrderedPlugins(plugins = [], configuredOrder = []) {
plugins = plugins.slice(0);
plugins.sort((a, b) => {
a = configuredOrder.indexOf(a.Name);
Expand Down Expand Up @@ -622,6 +670,7 @@ export function setLibraryOptions(parent, options) {
renderMetadataFetchers(parent, parent.availableOptions, options);
renderImageFetchers(parent, parent.availableOptions, options);
renderSubtitleFetchers(parent, parent.availableOptions, options);
renderLyricFetchers(parent, parent.availableOptions, options);
}

let currentLibraryOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ <h3 class="checkboxListLabel">${LabelDownloadLanguages}</h3>
<div class="lyricSettingsSection hide">
<h2>${Lyrics}</h2>

<div class="lyricFetchers advanced" style="margin-bottom: 2em;">
</div>

<div class="checkboxContainer checkboxContainer-withDescription advanced">
<label>
<input type="checkbox" is="emby-checkbox" id="chkSaveLyricsLocally" />
Expand Down
2 changes: 2 additions & 0 deletions src/strings/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@
"LabelLoginDisclaimer": "Login disclaimer",
"LabelLoginDisclaimerHelp": "A message that will be displayed at the bottom of the login page.",
"LabelLogs": "Logs",
"LabelLyricDownloaders": "Lyric downloaders",
"LabelMaxAudiobookResume": "Audiobook remaining minutes to resume",
"LabelMaxAudiobookResumeHelp": "Titles are assumed fully played if stopped when the remaining duration is less than this value.",
"LabelMaxBackdropsPerItem": "Maximum number of backdrops per item",
Expand Down Expand Up @@ -999,6 +1000,7 @@
"Lyric": "Lyric",
"Lyricist": "Lyricist",
"Lyrics": "Lyrics",
"LyricDownloadersHelp": "Enable and rank your preferred subtitle downloaders in order of priority.",
"ManageLibrary": "Manage library",
"ManageRecording": "Manage recording",
"MapChannels": "Map Channels",
Expand Down
Loading