mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
Set title/artist metadata in downloader
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
const CHANNEL = "downloader";
|
||||
const ACTIONS = {
|
||||
ERROR: "error",
|
||||
METADATA: "metadata",
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
@ -2,6 +2,7 @@ const { join } = require("path");
|
||||
|
||||
const { dialog } = require("electron");
|
||||
|
||||
const getSongInfo = require("../../providers/song-info");
|
||||
const { injectCSS, listenAction } = require("../utils");
|
||||
const { ACTIONS, CHANNEL } = require("./actions.js");
|
||||
|
||||
@ -16,14 +17,26 @@ const sendError = (win, err) => {
|
||||
dialog.showMessageBox(dialogOpts);
|
||||
};
|
||||
|
||||
let metadata = {};
|
||||
|
||||
function handle(win) {
|
||||
injectCSS(win.webContents, join(__dirname, "style.css"));
|
||||
const registerCallback = getSongInfo(win);
|
||||
registerCallback((info) => {
|
||||
metadata = {
|
||||
...info,
|
||||
image: info.image ? info.image.toDataURL() : undefined,
|
||||
};
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -12,6 +12,9 @@ const filenamify = require("filenamify");
|
||||
const FFmpeg = require("@ffmpeg/ffmpeg/dist/ffmpeg.min");
|
||||
const ytdl = require("ytdl-core");
|
||||
|
||||
const { triggerActionSync } = require("../utils");
|
||||
const { ACTIONS, CHANNEL } = require("./actions.js");
|
||||
|
||||
const { createFFmpeg } = FFmpeg;
|
||||
const ffmpeg = createFFmpeg({
|
||||
log: false,
|
||||
@ -93,6 +96,7 @@ const toMP3 = async (
|
||||
await ffmpeg.run(
|
||||
"-i",
|
||||
safeVideoName,
|
||||
...getFFmpegMetadataArgs(),
|
||||
...(options.ffmpegArgs || []),
|
||||
safeVideoName + "." + extension
|
||||
);
|
||||
@ -112,6 +116,20 @@ const toMP3 = async (
|
||||
}
|
||||
};
|
||||
|
||||
const getFFmpegMetadataArgs = () => {
|
||||
const metadata = JSON.parse(triggerActionSync(CHANNEL, ACTIONS.METADATA));
|
||||
if (!metadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
return [
|
||||
"-metadata",
|
||||
`title=${metadata.title}`,
|
||||
"-metadata",
|
||||
`artist=${metadata.artist}`,
|
||||
];
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
downloadVideoToMP3,
|
||||
};
|
||||
|
||||
@ -24,6 +24,10 @@ module.exports.triggerAction = (channel, action, ...args) => {
|
||||
return ipcRenderer.send(channel, action, ...args);
|
||||
};
|
||||
|
||||
module.exports.triggerActionSync = (channel, action, ...args) => {
|
||||
return ipcRenderer.sendSync(channel, action, ...args);
|
||||
};
|
||||
|
||||
module.exports.listenAction = (channel, callback) => {
|
||||
return ipcMain.on(channel, callback);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user