mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
* Added Discord timeout
* Add getOptions in plugin util
* Mutex in ffmpeg conversion (only supports one command at a time)
* Add menu customization in plugin system
* Add ytpl package (playlist info)
* Handle ffmpeg metadata flags when metadata is not present
* Only use artist in file name if present
* Export sendError method
* Handle image not present in metadata util
* Add downloader utils (getFolder and default menu label)
* Pass (optional) existing metadata and subfolder in mp3 converter
* Add listener to download playlist
* Add custom menu in downloader plugin ("download playlist" item)
* nit: fix main CSS style
* Only set the "enable" item in menu if plugin not enabled
* Navigation plugin: inject HTML once CSS is loaded
Co-authored-by: Sem Visscher <semvisscher10@gmail.com>
Co-authored-by: TC <th-ch@users.noreply.github.com>
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
const { existsSync, mkdirSync } = require("fs");
|
|
const { join } = require("path");
|
|
const { URL } = require("url");
|
|
|
|
const { ipcMain } = require("electron");
|
|
const is = require("electron-is");
|
|
const ytpl = require("ytpl");
|
|
|
|
const { sendError } = require("./back");
|
|
const { defaultMenuDownloadLabel, getFolder } = require("./utils");
|
|
|
|
let downloadLabel = defaultMenuDownloadLabel;
|
|
|
|
module.exports = (win, options, refreshMenu) => [
|
|
{
|
|
label: downloadLabel,
|
|
click: async () => {
|
|
const currentURL = win.webContents.getURL();
|
|
const playlistID = new URL(currentURL).searchParams.get("list");
|
|
if (!playlistID) {
|
|
sendError(win, new Error("No playlist ID found"));
|
|
return;
|
|
}
|
|
|
|
const playlist = await ytpl(playlistID);
|
|
const playlistTitle = playlist.title;
|
|
|
|
const folder = getFolder(options.downloadFolder);
|
|
const playlistFolder = join(folder, playlistTitle);
|
|
if (existsSync(playlistFolder)) {
|
|
sendError(
|
|
win,
|
|
new Error(`The folder ${playlistFolder} already exists`)
|
|
);
|
|
return;
|
|
}
|
|
mkdirSync(playlistFolder, { recursive: true });
|
|
|
|
ipcMain.on("downloader-feedback", (_, feedback) => {
|
|
downloadLabel = feedback;
|
|
refreshMenu();
|
|
});
|
|
|
|
downloadLabel = `Downloading "${playlistTitle}"`;
|
|
refreshMenu();
|
|
|
|
if (is.dev()) {
|
|
console.log(
|
|
`Downloading playlist "${playlistTitle}" (${playlist.items.length} songs)`
|
|
);
|
|
}
|
|
|
|
playlist.items.slice(0, options.playlistMaxItems).forEach((song) => {
|
|
win.webContents.send(
|
|
"downloader-download-playlist",
|
|
song,
|
|
playlistTitle,
|
|
options
|
|
);
|
|
});
|
|
},
|
|
},
|
|
];
|