mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 20:52:06 +00:00
Use metadata URL in downloader (fallback to current URL)
This commit is contained in:
@ -35,7 +35,7 @@ const reinit = () => {
|
|||||||
// contextBridge.exposeInMainWorld("downloader", {
|
// contextBridge.exposeInMainWorld("downloader", {
|
||||||
// download: () => {
|
// download: () => {
|
||||||
global.download = () => {
|
global.download = () => {
|
||||||
const videoUrl = window.location.href;
|
const videoUrl = global.songInfo.url || window.location.href;
|
||||||
|
|
||||||
downloadVideoToMP3(
|
downloadVideoToMP3(
|
||||||
videoUrl,
|
videoUrl,
|
||||||
|
|||||||
@ -7,16 +7,28 @@ const is = require("electron-is");
|
|||||||
const ytpl = require("ytpl");
|
const ytpl = require("ytpl");
|
||||||
|
|
||||||
const { setOptions } = require("../../config/plugins");
|
const { setOptions } = require("../../config/plugins");
|
||||||
|
const getSongInfo = require("../../providers/song-info");
|
||||||
const { sendError } = require("./back");
|
const { sendError } = require("./back");
|
||||||
const { defaultMenuDownloadLabel, getFolder } = require("./utils");
|
const { defaultMenuDownloadLabel, getFolder } = require("./utils");
|
||||||
|
|
||||||
let downloadLabel = defaultMenuDownloadLabel;
|
let downloadLabel = defaultMenuDownloadLabel;
|
||||||
|
let metadataURL = undefined;
|
||||||
|
let callbackIsRegistered = false;
|
||||||
|
|
||||||
module.exports = (win, options, refreshMenu) => [
|
module.exports = (win, options, refreshMenu) => {
|
||||||
|
if (!callbackIsRegistered) {
|
||||||
|
const registerCallback = getSongInfo(win);
|
||||||
|
registerCallback((info) => {
|
||||||
|
metadataURL = info.url;
|
||||||
|
});
|
||||||
|
callbackIsRegistered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
{
|
{
|
||||||
label: downloadLabel,
|
label: downloadLabel,
|
||||||
click: async () => {
|
click: async () => {
|
||||||
const currentURL = win.webContents.getURL();
|
const currentURL = metadataURL || win.webContents.getURL();
|
||||||
const playlistID = new URL(currentURL).searchParams.get("list");
|
const playlistID = new URL(currentURL).searchParams.get("list");
|
||||||
if (!playlistID) {
|
if (!playlistID) {
|
||||||
sendError(win, new Error("No playlist ID found"));
|
sendError(win, new Error("No playlist ID found"));
|
||||||
@ -74,4 +86,5 @@ module.exports = (win, options, refreshMenu) => [
|
|||||||
} // else = user pressed cancel
|
} // else = user pressed cancel
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user