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>
76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
const { writeFileSync } = require("fs");
|
|
const { join } = require("path");
|
|
|
|
const ID3Writer = require("browser-id3-writer");
|
|
const { dialog, ipcMain } = require("electron");
|
|
|
|
const getSongInfo = require("../../providers/song-info");
|
|
const { injectCSS, listenAction } = require("../utils");
|
|
const { ACTIONS, CHANNEL } = require("./actions.js");
|
|
|
|
const sendError = (win, err) => {
|
|
const dialogOpts = {
|
|
type: "info",
|
|
buttons: ["OK"],
|
|
title: "Error in download!",
|
|
message: "Argh! Apologies, download failed…",
|
|
detail: err.toString(),
|
|
};
|
|
dialog.showMessageBox(dialogOpts);
|
|
};
|
|
|
|
let metadata = {};
|
|
|
|
function handle(win) {
|
|
injectCSS(win.webContents, join(__dirname, "style.css"));
|
|
const registerCallback = getSongInfo(win);
|
|
registerCallback((info) => {
|
|
metadata = info;
|
|
});
|
|
|
|
listenAction(CHANNEL, (event, action, error) => {
|
|
switch (action) {
|
|
case ACTIONS.ERROR:
|
|
sendError(win, error);
|
|
break;
|
|
case ACTIONS.METADATA:
|
|
event.returnValue = JSON.stringify(metadata);
|
|
break;
|
|
default:
|
|
console.log("Unknown action: " + action);
|
|
}
|
|
});
|
|
|
|
ipcMain.on("add-metadata", (event, filePath, songBuffer) => {
|
|
let fileBuffer = songBuffer;
|
|
|
|
try {
|
|
const writer = new ID3Writer(songBuffer);
|
|
if (metadata.image) {
|
|
const coverBuffer = metadata.image.toPNG();
|
|
|
|
// Create the metadata tags
|
|
writer
|
|
.setFrame("TIT2", metadata.title)
|
|
.setFrame("TPE1", [metadata.artist])
|
|
.setFrame("APIC", {
|
|
type: 3,
|
|
data: coverBuffer,
|
|
description: "",
|
|
});
|
|
writer.addTag();
|
|
}
|
|
fileBuffer = Buffer.from(writer.arrayBuffer);
|
|
} catch (error) {
|
|
sendError(win, error);
|
|
}
|
|
|
|
writeFileSync(filePath, fileBuffer);
|
|
// Notify the youtube-dl file
|
|
event.reply("add-metadata-done");
|
|
});
|
|
}
|
|
|
|
module.exports = handle;
|
|
module.exports.sendError = sendError;
|