diff --git a/src/components/libraryoptionseditor/libraryoptionseditor.js b/src/components/libraryoptionseditor/libraryoptionseditor.js index b282697cb4..66fb2bef52 100644 --- a/src/components/libraryoptionseditor/libraryoptionseditor.js +++ b/src/components/libraryoptionseditor/libraryoptionseditor.js @@ -215,6 +215,39 @@ 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); + if (!plugins.length) return html; + + html += `

${globalize.translate('LabelLyricDownloaders')}

`; + html += '
'; + for (let i = 0; i < plugins.length; i++) { + const plugin = plugins[i]; + html += `
`; + const isChecked = libraryOptions.DisabledLyricFetchers ? !libraryOptions.DisabledLyricFetchers.includes(plugin.Name) : plugin.DefaultEnabled; + const checkedHtml = isChecked ? ' checked="checked"' : ''; + html += ``; + html += '
'; + html += '

'; + html += escapeHtml(plugin.Name); + html += '

'; + html += '
'; + if (i > 0) { + html += ``; + } else if (plugins.length > 1) { + html += ``; + } + html += '
'; + } + html += '
'; + html += `
${globalize.translate('LyricDownloadersHelp')}
`; + elem.innerHTML = html; +} + function getImageFetchersForTypeHtml(availableTypeOptions, libraryOptionsForType) { let html = ''; let plugins = availableTypeOptions.ImageFetchers; @@ -284,6 +317,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(() => { @@ -460,6 +494,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) { @@ -568,6 +614,7 @@ export function getLibraryOptions(parent) { return elem.getAttribute('data-lang'); }); setSubtitleFetchersIntoOptions(parent, options); + setLyricFetchersIntoOptions(parent, options); setMetadataFetchersIntoOptions(parent, options); setImageFetchersIntoOptions(parent, options); setImageOptionsIntoOptions(options); @@ -575,7 +622,7 @@ export function getLibraryOptions(parent) { return options; } -function getOrderedPlugins(plugins, configuredOrder) { +function getOrderedPlugins(plugins = [], configuredOrder = []) { plugins = plugins.slice(0); plugins.sort((a, b) => { a = configuredOrder.indexOf(a.Name); @@ -624,6 +671,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; diff --git a/src/components/libraryoptionseditor/libraryoptionseditor.template.html b/src/components/libraryoptionseditor/libraryoptionseditor.template.html index 6f6cbb918c..a4990c65a9 100644 --- a/src/components/libraryoptionseditor/libraryoptionseditor.template.html +++ b/src/components/libraryoptionseditor/libraryoptionseditor.template.html @@ -205,6 +205,9 @@

${Lyrics}

+
+
+