diff --git a/plugins/downloader/front.js b/plugins/downloader/front.js index c8731935..095d4968 100644 --- a/plugins/downloader/front.js +++ b/plugins/downloader/front.js @@ -45,7 +45,7 @@ global.download = () => { let metadata; let videoUrl = getSongMenu() // selector of first button which is always "Start Radio" - ?.querySelector('ytmusic-menu-navigation-item-renderer.iron-selected[tabindex="0"] #navigation-endpoint') + ?.querySelector('ytmusic-menu-navigation-item-renderer[tabindex="0"] #navigation-endpoint') ?.getAttribute("href"); if (videoUrl) { if (videoUrl.startsWith('watch?')) { diff --git a/plugins/downloader/menu.js b/plugins/downloader/menu.js index 449fa2c3..e519055c 100644 --- a/plugins/downloader/menu.js +++ b/plugins/downloader/menu.js @@ -11,15 +11,24 @@ const { sendError } = require("./back"); const { defaultMenuDownloadLabel, getFolder, presets } = require("./utils"); let downloadLabel = defaultMenuDownloadLabel; -let playingPlaylistId = undefined; +let playingUrl = undefined; let callbackIsRegistered = false; -const INVALID_PLAYLIST_MODIFIER = 'RDAMPLPL'; +// Playlist radio modifier needs to be cut from playlist ID +const INVALID_PLAYLIST_MODIFIER = 'RDAMPL'; + +const getPlaylistID = aURL => { + const result = aURL?.searchParams.get("list") || aURL?.searchParams.get("playlist"); + if (result?.startsWith(INVALID_PLAYLIST_MODIFIER)) { + return result.slice(6) + } + return result; +}; module.exports = (win, options) => { if (!callbackIsRegistered) { ipcMain.on("video-src-changed", async (_, data) => { - playingPlaylistId = JSON.parse(data)?.videoDetails?.playlistId; + playingUrl = JSON.parse(data)?.microformat?.microformatDataRenderer?.urlCanonical; }); ipcMain.on("download-playlist-request", async (_event, url) => downloadPlaylist(url, win, options)); callbackIsRegistered = true; @@ -58,21 +67,17 @@ module.exports = (win, options) => { ]; }; -async function downloadPlaylist(url, win, options) { - const getPlaylistID = aURL => { - const result = aURL?.searchParams.get("list") || aURL?.searchParams.get("playlist"); - return (!result || result.startsWith(INVALID_PLAYLIST_MODIFIER)) ? undefined : result; - }; - if (url) { +async function downloadPlaylist(givenUrl, win, options) { + if (givenUrl) { try { - url = new URL(url); + givenUrl = new URL(givenUrl); } catch { - url = undefined; + givenUrl = undefined; }; } - const playlistId = getPlaylistID(url) + const playlistId = getPlaylistID(givenUrl) || getPlaylistID(new URL(win.webContents.getURL())) - || playingPlaylistId; + || getPlaylistID(new URL(playingUrl)); if (!playlistId) { sendError(win, new Error("No playlist ID found"));