@@ -55,10 +55,20 @@ let yt: Innertube;
5555let win : BrowserWindow ;
5656let playingUrl : string ;
5757
58- const isYouTubePremium = ( ) =>
59- win . webContents . executeJavaScript (
60- '!document.querySelector(\'#endpoint[href="/music_premium"]\')' ,
61- ) as Promise < boolean > ;
58+ const isYouTubeMusicPremium = async ( ) => {
59+ const upgradeBtnIconPathData = ( await win . webContents . executeJavaScript (
60+ 'document.querySelector(\'iron-iconset-svg[name="yt-sys-icons"] #youtube_music_monochrome\')?.firstChild?.getAttribute("d")?.substring(0, 15)' ,
61+ ) ) as string | null ;
62+
63+ // Fallback to non-premium if the icon is not found
64+ if ( ! upgradeBtnIconPathData ) return false ;
65+
66+ const selector = `ytmusic-guide-entry-renderer:has(> tp-yt-paper-item > yt-icon path[d^="${ upgradeBtnIconPathData } "])` ;
67+
68+ return ( await win . webContents . executeJavaScript (
69+ `!document.querySelector('${ selector } ')` ,
70+ ) ) as boolean ;
71+ } ;
6272
6373const sendError = ( error : Error , source ?: string ) => {
6474 win . setProgressBar ( - 1 ) ; // Close progress bar
@@ -370,7 +380,7 @@ async function downloadSongUnsafe(
370380 }
371381
372382 const downloadOptions : FormatOptions = {
373- type : ( await isYouTubePremium ( ) ) ? 'audio' : 'video+audio' , // Audio, video or video+audio
383+ type : ( await isYouTubeMusicPremium ( ) ) ? 'audio' : 'video+audio' , // Audio, video or video+audio
374384 quality : 'best' , // Best, bestefficiency, 144p, 240p, 480p, 720p and so on.
375385 format : 'any' , // Media container format
376386 } ;
0 commit comments