diff --git a/src/plugins/downloader/renderer.ts b/src/plugins/downloader/renderer.ts index 4eb3d8e0..99e2dde5 100644 --- a/src/plugins/downloader/renderer.ts +++ b/src/plugins/downloader/renderer.ts @@ -32,10 +32,22 @@ const menuObserver = new MutationObserver(() => { return; } - const menuUrl = document.querySelector( + // check for video (or music) + let menuUrl = document.querySelector( 'tp-yt-paper-listbox [tabindex="0"] #navigation-endpoint', )?.href; - if (!menuUrl?.includes('watch?') && doneFirstLoad) { + if (!menuUrl?.includes('watch?')) { + menuUrl = undefined; + // check for podcast + for (const it of document.querySelectorAll('tp-yt-paper-listbox [tabindex="-1"] #navigation-endpoint')) { + if (it.getAttribute('href')?.includes('podcast/')) { + menuUrl = it.getAttribute('href')!; + break; + } + } + } + + if (!menuUrl && doneFirstLoad) { return; } @@ -51,17 +63,32 @@ export const onRendererLoad = ({ ipc, }: RendererContext) => { window.download = () => { - let videoUrl = getSongMenu() + const songMenu = getSongMenu(); + let videoUrl = songMenu // Selector of first button which is always "Start Radio" ?.querySelector( 'ytmusic-menu-navigation-item-renderer[tabindex="0"] #navigation-endpoint', ) ?.getAttribute('href'); + + if (!videoUrl && songMenu) { + for (const it of songMenu.querySelectorAll('ytmusic-menu-navigation-item-renderer[tabindex="-1"] #navigation-endpoint')) { + if (it.getAttribute('href')?.includes('podcast/')) { + videoUrl = it.getAttribute('href'); + break; + } + } + } + if (videoUrl) { if (videoUrl.startsWith('watch?')) { videoUrl = defaultConfig.url + '/' + videoUrl; } + if (videoUrl.startsWith('podcast/')) { + videoUrl = defaultConfig.url + '/watch?' + videoUrl.replace('podcast/', 'v='); + } + if (videoUrl.includes('?playlist=')) { ipc.invoke('download-playlist-request', videoUrl); return; diff --git a/src/plugins/picture-in-picture/renderer.ts b/src/plugins/picture-in-picture/renderer.ts index e82f775c..8fd5897c 100644 --- a/src/plugins/picture-in-picture/renderer.ts +++ b/src/plugins/picture-in-picture/renderer.ts @@ -60,10 +60,23 @@ const observer = new MutationObserver(() => { return; } - const menuUrl = $( + // check for video (or music) + let menuUrl = $( 'tp-yt-paper-listbox [tabindex="0"] #navigation-endpoint', )?.href; - if (!menuUrl?.includes('watch?') && doneFirstLoad) { + + if (!menuUrl?.includes('watch?')) { + menuUrl = undefined; + // check for podcast + for (const it of document.querySelectorAll('tp-yt-paper-listbox [tabindex="-1"] #navigation-endpoint')) { + if (it.getAttribute('href')?.includes('podcast/')) { + menuUrl = it.getAttribute('href')!; + break; + } + } + } + + if (!menuUrl && doneFirstLoad) { return; }