mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-09 17:51:46 +00:00
fix(downloader): use the upgrade button to check for premium status (#2987)
This commit is contained in:
@ -55,10 +55,20 @@ let yt: Innertube;
|
||||
let win: BrowserWindow;
|
||||
let playingUrl: string;
|
||||
|
||||
const isYouTubePremium = () =>
|
||||
win.webContents.executeJavaScript(
|
||||
'!document.querySelector(\'#endpoint[href="/music_premium"]\')',
|
||||
) as Promise<boolean>;
|
||||
const isYouTubeMusicPremium = async () => {
|
||||
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;
|
||||
|
||||
// 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}"])`;
|
||||
|
||||
return (await win.webContents.executeJavaScript(
|
||||
`!document.querySelector('${selector}')`,
|
||||
)) as boolean;
|
||||
};
|
||||
|
||||
const sendError = (error: Error, source?: string) => {
|
||||
win.setProgressBar(-1); // Close progress bar
|
||||
@ -370,7 +380,7 @@ async function downloadSongUnsafe(
|
||||
}
|
||||
|
||||
const downloadOptions: FormatOptions = {
|
||||
type: (await isYouTubePremium()) ? 'audio' : 'video+audio', // Audio, video or video+audio
|
||||
type: (await isYouTubeMusicPremium()) ? 'audio' : 'video+audio', // Audio, video or video+audio
|
||||
quality: 'best', // Best, bestefficiency, 144p, 240p, 480p, 720p and so on.
|
||||
format: 'any', // Media container format
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user