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