From babc50099c75956f84061eb156031fc36cdd18cf Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 29 Jan 2022 11:13:53 +0200 Subject: [PATCH 1/9] fix lyrics css styling --- plugins/lyrics-genius/style.css | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/lyrics-genius/style.css b/plugins/lyrics-genius/style.css index 1966b67b25..9c5f74de0a 100644 --- a/plugins/lyrics-genius/style.css +++ b/plugins/lyrics-genius/style.css @@ -6,7 +6,10 @@ text-decoration: none; } -#contents.genius-lyrics { - font-size: 1vw; - opacity: 0.9; +#contents.genius-lyrics, .description { + font-size: 1.1vw !important; + text-align: center !important; + line-height: 1.4; + font-family: Roboto,Noto Naskh Arabic UI,Arial,sans-serif; + font-weight: 400; } From 900c44d9c0f2dd251e4369667ab8bae67b46935b Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 29 Jan 2022 11:14:03 +0200 Subject: [PATCH 2/9] fix disabled lyrics tab --- plugins/lyrics-genius/front.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/plugins/lyrics-genius/front.js b/plugins/lyrics-genius/front.js index 48227e1d7b..14813c7c04 100644 --- a/plugins/lyrics-genius/front.js +++ b/plugins/lyrics-genius/front.js @@ -3,10 +3,15 @@ const is = require("electron-is"); module.exports = () => { ipcRenderer.on("update-song-info", (_, extractedSongInfo) => { - const lyricsTab = document.querySelector('tp-yt-paper-tab[tabindex="-1"]'); + const tabList = document.querySelectorAll("tp-yt-paper-tab"); + const tabs = { + upNext: tabList[0], + lyrics: tabList[1], + discover: tabList[2], + } // Check if disabled - if (!lyricsTab || !lyricsTab.hasAttribute("disabled")) { + if (!tabs.lyrics || !tabs.lyrics.hasAttribute("disabled")) { return; } @@ -35,26 +40,31 @@ module.exports = () => { return; } - lyricsTab.removeAttribute("disabled"); - lyricsTab.removeAttribute("aria-disabled"); - document.querySelector("tp-yt-paper-tab").onclick = () => { - lyricsTab.removeAttribute("disabled"); - lyricsTab.removeAttribute("aria-disabled"); - }; + tabs.lyrics.removeAttribute("disabled"); + tabs.lyrics.removeAttribute("aria-disabled"); + + for (tab of [tabs.upNext, tabs.discover]){ + tab.onclick = () => { + tabs.lyrics.removeAttribute("disabled"); + tabs.lyrics.removeAttribute("aria-disabled"); + }; + } - lyricsTab.onclick = () => { + tabs.lyrics.onclick = () => { const tabContainer = document.querySelector("ytmusic-tab-renderer"); const observer = new MutationObserver((_, observer) => { const lyricsContainer = document.querySelector( '[page-type="MUSIC_PAGE_TYPE_TRACK_LYRICS"] > ytmusic-message-renderer' ); if (lyricsContainer) { + observer.disconnect(); lyricsContainer.innerHTML = `
${lyrics} Source : Genius
`; - observer.disconnect(); + tabs.lyrics.removeAttribute("disabled"); + tabs.lyrics.removeAttribute("aria-disabled"); } }); observer.observe(tabContainer, { From 60bb5b861dc5b248be31120e03b0a091bee0b0d7 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 29 Jan 2022 11:35:18 +0200 Subject: [PATCH 3/9] change to new lyrics even if lyrics tab was already selected --- plugins/lyrics-genius/front.js | 36 +++++++++++++++++++++------------ plugins/lyrics-genius/style.css | 3 --- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/plugins/lyrics-genius/front.js b/plugins/lyrics-genius/front.js index 14813c7c04..9e9d9216e5 100644 --- a/plugins/lyrics-genius/front.js +++ b/plugins/lyrics-genius/front.js @@ -50,22 +50,12 @@ module.exports = () => { }; } + checkLyricsContainer(); + tabs.lyrics.onclick = () => { const tabContainer = document.querySelector("ytmusic-tab-renderer"); const observer = new MutationObserver((_, observer) => { - const lyricsContainer = document.querySelector( - '[page-type="MUSIC_PAGE_TYPE_TRACK_LYRICS"] > ytmusic-message-renderer' - ); - if (lyricsContainer) { - observer.disconnect(); - lyricsContainer.innerHTML = `
- ${lyrics} - - Source : Genius -
`; - tabs.lyrics.removeAttribute("disabled"); - tabs.lyrics.removeAttribute("aria-disabled"); - } + checkLyricsContainer(() => observer.disconnect()); }); observer.observe(tabContainer, { attributes: true, @@ -73,5 +63,25 @@ module.exports = () => { subtree: true, }); }; + + function checkLyricsContainer(callback = () => {}) { + const lyricsContainer = document.querySelector( + '[page-type="MUSIC_PAGE_TYPE_TRACK_LYRICS"] > ytmusic-message-renderer' + ); + if (lyricsContainer) { + callback(); + setLyrics(lyricsContainer) + } + } + + function setLyrics(lyricsContainer){ + lyricsContainer.innerHTML = `
+ ${lyrics} + + Source : Genius +
`; + tabs.lyrics.removeAttribute("disabled"); + tabs.lyrics.removeAttribute("aria-disabled"); + } }); }; diff --git a/plugins/lyrics-genius/style.css b/plugins/lyrics-genius/style.css index 9c5f74de0a..2712807259 100644 --- a/plugins/lyrics-genius/style.css +++ b/plugins/lyrics-genius/style.css @@ -9,7 +9,4 @@ #contents.genius-lyrics, .description { font-size: 1.1vw !important; text-align: center !important; - line-height: 1.4; - font-family: Roboto,Noto Naskh Arabic UI,Arial,sans-serif; - font-weight: 400; } From 41b9ab48158fbb91145e7fa820749db837cfccfc Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 29 Jan 2022 11:46:34 +0200 Subject: [PATCH 4/9] lint --- plugins/lyrics-genius/front.js | 20 +++++++++++--------- plugins/lyrics-genius/style.css | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/plugins/lyrics-genius/front.js b/plugins/lyrics-genius/front.js index 9e9d9216e5..e708964aa9 100644 --- a/plugins/lyrics-genius/front.js +++ b/plugins/lyrics-genius/front.js @@ -11,7 +11,7 @@ module.exports = () => { } // Check if disabled - if (!tabs.lyrics || !tabs.lyrics.hasAttribute("disabled")) { + if (!tabs.lyrics?.hasAttribute("disabled")) { return; } @@ -40,14 +40,12 @@ module.exports = () => { return; } - tabs.lyrics.removeAttribute("disabled"); - tabs.lyrics.removeAttribute("aria-disabled"); + enableLyricsTab(); - for (tab of [tabs.upNext, tabs.discover]){ - tab.onclick = () => { - tabs.lyrics.removeAttribute("disabled"); - tabs.lyrics.removeAttribute("aria-disabled"); - }; + for (tab of [tabs.upNext, tabs.discover]) { + if (tab) { + tab.onclick = enableLyricsTab; + } } checkLyricsContainer(); @@ -74,12 +72,16 @@ module.exports = () => { } } - function setLyrics(lyricsContainer){ + function setLyrics(lyricsContainer) { lyricsContainer.innerHTML = `
${lyrics} Source : Genius
`; + enableLyricsTab() + } + + function enableLyricsTab() { tabs.lyrics.removeAttribute("disabled"); tabs.lyrics.removeAttribute("aria-disabled"); } diff --git a/plugins/lyrics-genius/style.css b/plugins/lyrics-genius/style.css index 2712807259..26100bab0f 100644 --- a/plugins/lyrics-genius/style.css +++ b/plugins/lyrics-genius/style.css @@ -6,7 +6,7 @@ text-decoration: none; } -#contents.genius-lyrics, .description { - font-size: 1.1vw !important; +.description { + font-size: 1.1vw !important; text-align: center !important; } From 909036108f5039b6d1a3269e2f3c58091bf9006f Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 29 Jan 2022 16:56:55 +0200 Subject: [PATCH 5/9] reenable lyrics footer --- plugins/lyrics-genius/front.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/lyrics-genius/front.js b/plugins/lyrics-genius/front.js index e708964aa9..8a1802e4e3 100644 --- a/plugins/lyrics-genius/front.js +++ b/plugins/lyrics-genius/front.js @@ -76,9 +76,10 @@ module.exports = () => { lyricsContainer.innerHTML = `
${lyrics} - Source : Genius +
`; - enableLyricsTab() + lyricsContainer.querySelector('.footer').textContent = 'Source: Genius'; + enableLyricsTab(); } function enableLyricsTab() { From 366c90f71d194d4d0b82ccd1de08f070147fbb2b Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 29 Jan 2022 17:10:47 +0200 Subject: [PATCH 6/9] fix showing old lyrics if new lyrics couldn't be resolved --- plugins/lyrics-genius/front.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/plugins/lyrics-genius/front.js b/plugins/lyrics-genius/front.js index 8a1802e4e3..e7d288e036 100644 --- a/plugins/lyrics-genius/front.js +++ b/plugins/lyrics-genius/front.js @@ -15,13 +15,22 @@ module.exports = () => { return; } + let hasLyrics = true; + const html = ipcRenderer.sendSync( "search-genius-lyrics", extractedSongInfo ); if (!html) { + // Delete previous lyrics if tab is open and couldn't get new lyrics + checkLyricsContainer(() => { + hasLyrics = false; + setTabsOnclick(undefined); + }); return; - } else if (is.dev()) { + } + + if (is.dev()) { console.log("Fetched lyrics from Genius"); } @@ -42,11 +51,7 @@ module.exports = () => { enableLyricsTab(); - for (tab of [tabs.upNext, tabs.discover]) { - if (tab) { - tab.onclick = enableLyricsTab; - } - } + setTabsOnclick(enableLyricsTab); checkLyricsContainer(); @@ -74,12 +79,22 @@ module.exports = () => { function setLyrics(lyricsContainer) { lyricsContainer.innerHTML = `
- ${lyrics} + ${hasLyrics ? lyrics : 'Subtitles could not be retrieved'}
`; - lyricsContainer.querySelector('.footer').textContent = 'Source: Genius'; - enableLyricsTab(); + if (hasLyrics) { + lyricsContainer.querySelector('.footer').textContent = 'Source: Genius'; + enableLyricsTab(); + } + } + + function setTabsOnclick(callback) { + for (tab of [tabs.upNext, tabs.discover]) { + if (tab) { + tab.onclick = callback; + } + } } function enableLyricsTab() { From eff0995d7891cee7a8c27353ad99a2a88a0ab17c Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 29 Jan 2022 17:10:47 +0200 Subject: [PATCH 7/9] fix showing old lyrics if new lyrics couldn't be resolved --- plugins/lyrics-genius/front.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/plugins/lyrics-genius/front.js b/plugins/lyrics-genius/front.js index 8a1802e4e3..3a2572651e 100644 --- a/plugins/lyrics-genius/front.js +++ b/plugins/lyrics-genius/front.js @@ -15,13 +15,22 @@ module.exports = () => { return; } + let hasLyrics = true; + const html = ipcRenderer.sendSync( "search-genius-lyrics", extractedSongInfo ); if (!html) { + // Delete previous lyrics if tab is open and couldn't get new lyrics + checkLyricsContainer(() => { + hasLyrics = false; + setTabsOnclick(undefined); + }); return; - } else if (is.dev()) { + } + + if (is.dev()) { console.log("Fetched lyrics from Genius"); } @@ -42,11 +51,7 @@ module.exports = () => { enableLyricsTab(); - for (tab of [tabs.upNext, tabs.discover]) { - if (tab) { - tab.onclick = enableLyricsTab; - } - } + setTabsOnclick(enableLyricsTab); checkLyricsContainer(); @@ -74,12 +79,22 @@ module.exports = () => { function setLyrics(lyricsContainer) { lyricsContainer.innerHTML = `
- ${lyrics} + ${hasLyrics ? lyrics : 'Could not retrieve lyrics from genius'}
`; - lyricsContainer.querySelector('.footer').textContent = 'Source: Genius'; - enableLyricsTab(); + if (hasLyrics) { + lyricsContainer.querySelector('.footer').textContent = 'Source: Genius'; + enableLyricsTab(); + } + } + + function setTabsOnclick(callback) { + for (tab of [tabs.upNext, tabs.discover]) { + if (tab) { + tab.onclick = callback; + } + } } function enableLyricsTab() { From b042d0a8ca412717e35e03a6589908738fbc1787 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 29 Jan 2022 17:57:39 +0200 Subject: [PATCH 8/9] use regex on cleanupName() --- providers/song-info.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/providers/song-info.js b/providers/song-info.js index c402835525..88f757a373 100644 --- a/providers/song-info.js +++ b/providers/song-info.js @@ -112,13 +112,12 @@ const suffixesToRemove = [ " - topic", "vevo", " (performance video)", - " (official music video)", - " (official video)", " (clip officiel)", ]; function cleanupName(name) { if (!name) return name; + name = name.replace(/\((?:official)?[ ]?(?:music)?[ ]?(?:lyric[s]?)?[ ]?(?:video)?\)$/i, '') const lowCaseName = name.toLowerCase(); for (const suffix of suffixesToRemove) { if (lowCaseName.endsWith(suffix)) { From fc111e251364b320b8b11adffe3e765827324c4c Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 29 Jan 2022 18:05:55 +0200 Subject: [PATCH 9/9] keep footer out of contents div --- plugins/lyrics-genius/front.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/lyrics-genius/front.js b/plugins/lyrics-genius/front.js index f3ac4487e5..b8e78c1c87 100644 --- a/plugins/lyrics-genius/front.js +++ b/plugins/lyrics-genius/front.js @@ -82,8 +82,8 @@ module.exports = () => { `
${hasLyrics ? lyrics : 'Could not retrieve lyrics from genius'} - -
`; + + `; if (hasLyrics) { lyricsContainer.querySelector('.footer').textContent = 'Source: Genius'; enableLyricsTab();