From edad53e989670ff35d7b94c2f2ba114c287f9c98 Mon Sep 17 00:00:00 2001 From: Franz DC Date: Mon, 31 Mar 2025 21:48:14 +0800 Subject: [PATCH] fix(downloader): allow downloads for signed out users (#3145) * fix(downloader): allow downloads for signed out users * refactor(downloader): use yt.config_.LOGGED_IN for checking sign in status * Apply suggestions from code review --------- Co-authored-by: JellyBrick --- src/plugins/downloader/main/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/plugins/downloader/main/index.ts b/src/plugins/downloader/main/index.ts index 484f233a..ad76b96f 100644 --- a/src/plugins/downloader/main/index.ts +++ b/src/plugins/downloader/main/index.ts @@ -56,6 +56,14 @@ let win: BrowserWindow; let playingUrl: string; const isYouTubeMusicPremium = async () => { + // If signed out, it is understood as non-premium + const isSignedIn = (await win.webContents.executeJavaScript( + '!!yt.config_.LOGGED_IN', + )) as boolean; + + if (!isSignedIn) return false; + + // If signed in, check if the upgrade button is present const upgradeBtnIconPathData = (await win.webContents.executeJavaScript( 'document.querySelector(\'iron-iconset-svg[name="yt-sys-icons"] #youtube_music_monochrome\')?.firstChild?.getAttribute("d")?.substring(0, 15)', )) as string | null; @@ -63,10 +71,10 @@ const isYouTubeMusicPremium = async () => { // Fallback to non-premium if the icon is not found if (!upgradeBtnIconPathData) return false; - const selector = `ytmusic-guide-entry-renderer:has(> tp-yt-paper-item > yt-icon path[d^="${upgradeBtnIconPathData}"])`; + const upgradeButton = `ytmusic-guide-entry-renderer:has(> tp-yt-paper-item > yt-icon path[d^="${upgradeBtnIconPathData}"])`; return (await win.webContents.executeJavaScript( - `!document.querySelector('${selector}')`, + `!document.querySelector('${upgradeButton}')`, )) as boolean; };