fmt
This commit is contained in:
parent
77c0edb15a
commit
56936cda9f
5 changed files with 26 additions and 69 deletions
|
@ -1,15 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="default-src 'self'; script-src 'self'"
|
||||
/>
|
||||
<meta
|
||||
http-equiv="X-Content-Security-Policy"
|
||||
content="default-src 'self'; script-src 'self'"
|
||||
/>
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'" />
|
||||
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'" />
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="../css/style.css" />
|
||||
|
||||
|
|
24
src/main.ts
24
src/main.ts
|
@ -101,7 +101,7 @@ app.whenReady().then(() => {
|
|||
-i "${file}" \
|
||||
-filter_complex "[0:a]amerge=inputs=2[a]" -ac 2 -map 0:v -map "[a]" \
|
||||
-c:v copy \
|
||||
"${tmpFile}"`
|
||||
"${tmpFile}"`,
|
||||
);
|
||||
|
||||
outFile = getNewFilename(file, "(merged audio) ");
|
||||
|
@ -115,7 +115,7 @@ app.whenReady().then(() => {
|
|||
-map 0 -map 1:a -c:v copy \
|
||||
-disposition:a 0 -disposition:a:0 default \
|
||||
${metadataAudio} \
|
||||
"${outFile}"`
|
||||
"${outFile}"`,
|
||||
).catch((e) => registerError(win, e));
|
||||
|
||||
// Delete the temporary video file
|
||||
|
@ -147,13 +147,9 @@ app.whenReady().then(() => {
|
|||
/** Reduce size of a file
|
||||
* Returns an empty string in case of failing
|
||||
*/
|
||||
const reduceSize = async (
|
||||
file: string,
|
||||
bitrate: number,
|
||||
audioTracks: number[]
|
||||
) => {
|
||||
const reduceSize = async (file: string, bitrate: number, audioTracks: number[]) => {
|
||||
const audioBitrate = Math.ceil(
|
||||
audioTracks.reduce((sum, current) => current + sum, 50) // initial value > 0 for extra room
|
||||
audioTracks.reduce((sum, current) => current + sum, 50), // initial value > 0 for extra room
|
||||
);
|
||||
const videoBitrate = bitrate - audioBitrate;
|
||||
let finalFile;
|
||||
|
@ -220,7 +216,7 @@ app.whenReady().then(() => {
|
|||
-profile:v main \
|
||||
${audioTracks.length === metadataAudioSize ? metadataAudio : ""} \
|
||||
${shareOpt} \
|
||||
"${finalFile}"`
|
||||
"${finalFile}"`,
|
||||
).catch((e) => registerError(win, e));
|
||||
|
||||
// Delete the 2 pass temporary files
|
||||
|
@ -246,7 +242,7 @@ app.whenReady().then(() => {
|
|||
-map 0 -codec copy \
|
||||
${shareOpt} \
|
||||
${nbTracks === metadataAudioSize ? metadataAudio : ""} \
|
||||
"${finalFile}"`
|
||||
"${finalFile}"`,
|
||||
).catch((e) => registerError(win, e));
|
||||
|
||||
// Delete the old video file
|
||||
|
@ -261,13 +257,11 @@ app.whenReady().then(() => {
|
|||
ipcMain.handle("getFilename", (_, filepath: string) => getFilename(filepath));
|
||||
ipcMain.handle("askFiles", () => askFiles());
|
||||
ipcMain.handle("mergeAudio", (_, file: string) => mergeAudio(file));
|
||||
ipcMain.handle(
|
||||
"reduceSize",
|
||||
(_, file: string, bitrate: number, audioTracks: number[]) =>
|
||||
reduceSize(file, bitrate, audioTracks)
|
||||
ipcMain.handle("reduceSize", (_, file: string, bitrate: number, audioTracks: number[]) =>
|
||||
reduceSize(file, bitrate, audioTracks),
|
||||
);
|
||||
ipcMain.handle("moveMetadata", (_, file: string, nbTracks: number) =>
|
||||
moveMetadata(file, nbTracks)
|
||||
moveMetadata(file, nbTracks),
|
||||
);
|
||||
ipcMain.handle("exit", () => (error ? {} : app.quit()));
|
||||
ipcMain.handle("confirmation", (_, text: string) => confirmation(text));
|
||||
|
|
|
@ -9,8 +9,7 @@ ipcRenderer.on("error", (_, err) => {
|
|||
contextBridge.exposeInMainWorld("internals", {
|
||||
argv: () => ipcRenderer.invoke("argv"),
|
||||
allowedExtensions: () => ipcRenderer.invoke("allowedExtensions"),
|
||||
getFilename: (filepath: string) =>
|
||||
ipcRenderer.invoke("getFilename", filepath),
|
||||
getFilename: (filepath: string) => ipcRenderer.invoke("getFilename", filepath),
|
||||
askFiles: () => ipcRenderer.invoke("askFiles"),
|
||||
mergeAudio: (file: string) => ipcRenderer.invoke("mergeAudio", file),
|
||||
reduceSize: (file: string, bitrate: number, audioTracks: number[]) =>
|
||||
|
|
|
@ -13,11 +13,7 @@ let internals: {
|
|||
size: number;
|
||||
audioTracks: number[];
|
||||
}>;
|
||||
reduceSize: (
|
||||
file: string,
|
||||
bitrate: number,
|
||||
audioTracks: number[]
|
||||
) => Promise<string>;
|
||||
reduceSize: (file: string, bitrate: number, audioTracks: number[]) => Promise<string>;
|
||||
moveMetadata: (file: string, nbTracks: number) => Promise<string>;
|
||||
confirmation: (text: string) => Promise<void>;
|
||||
};
|
||||
|
@ -25,9 +21,7 @@ let internals: {
|
|||
/** Search for files */
|
||||
const getFiles = async () => {
|
||||
const allowedExtensions = (await internals.allowedExtensions()).extensions;
|
||||
const argvFiles = (await internals.argv())
|
||||
.slice(1)
|
||||
.filter((element) => !element.startsWith("/"));
|
||||
const argvFiles = (await internals.argv()).slice(1).filter((element) => !element.startsWith("/"));
|
||||
|
||||
if (argvFiles.length > 0) {
|
||||
const files = argvFiles;
|
||||
|
@ -35,9 +29,7 @@ const getFiles = async () => {
|
|||
// Exit if a file isn't supported in the list
|
||||
if (
|
||||
files.filter((file) =>
|
||||
allowedExtensions.some((ext) =>
|
||||
file.toLowerCase().endsWith(ext.toLowerCase())
|
||||
)
|
||||
allowedExtensions.some((ext) => file.toLowerCase().endsWith(ext.toLowerCase())),
|
||||
).length !== files.length
|
||||
) {
|
||||
await internals.exit();
|
||||
|
@ -75,11 +67,7 @@ enum Mode {
|
|||
}
|
||||
|
||||
/** Update the message to the user */
|
||||
const updateMessage = (
|
||||
message: string,
|
||||
load: boolean = false,
|
||||
mode: Mode = Mode.Write
|
||||
) => {
|
||||
const updateMessage = (message: string, load: boolean = false, mode: Mode = Mode.Write) => {
|
||||
switch (mode) {
|
||||
case Mode.Write:
|
||||
document.getElementById("message").innerText = message;
|
||||
|
@ -92,9 +80,7 @@ const updateMessage = (
|
|||
default:
|
||||
break;
|
||||
}
|
||||
document.getElementById("load").style.visibility = load
|
||||
? "visible"
|
||||
: "hidden";
|
||||
document.getElementById("load").style.visibility = load ? "visible" : "hidden";
|
||||
};
|
||||
|
||||
/** Main function */
|
||||
|
@ -109,15 +95,10 @@ const main = async () => {
|
|||
for (const [idx, file] of files.entries()) {
|
||||
const counter = `${idx + 1}/${files.length}`;
|
||||
const filename = await internals.getFilename(file);
|
||||
updateMessage(
|
||||
`${counter} - Mélange des pistes audios de ${filename}...`,
|
||||
true
|
||||
);
|
||||
updateMessage(`${counter} - Mélange des pistes audios de ${filename}...`, true);
|
||||
const newFile = await internals.mergeAudio(file);
|
||||
let finalTitle = newFile.title;
|
||||
updateMessage(
|
||||
`${counter} - Taille calculée : ~${Math.round(newFile.size)}Mio`
|
||||
);
|
||||
updateMessage(`${counter} - Taille calculée : ~${Math.round(newFile.size)}Mio`);
|
||||
|
||||
// Compress video if needed
|
||||
if (newFile.size > maxSizeDiscord) {
|
||||
|
@ -129,23 +110,16 @@ const main = async () => {
|
|||
updateMessage(
|
||||
`\nFichier trop lourd, compression en cours... (bitrate total = ${bitrate}kbps)`,
|
||||
true,
|
||||
Mode.Append
|
||||
Mode.Append,
|
||||
);
|
||||
|
||||
// Compress the video and change the title to the new one
|
||||
finalTitle = await internals.reduceSize(
|
||||
newFile.title,
|
||||
bitrate,
|
||||
newFile.audioTracks
|
||||
);
|
||||
finalTitle = await internals.reduceSize(newFile.title, bitrate, newFile.audioTracks);
|
||||
} else {
|
||||
updateMessage(`\nPréparation pour le partage...`, true, Mode.Append);
|
||||
|
||||
// Move the metadata to make it playable before everything is downloaded
|
||||
finalTitle = await internals.moveMetadata(
|
||||
newFile.title,
|
||||
newFile.audioTracks.length
|
||||
);
|
||||
finalTitle = await internals.moveMetadata(newFile.title, newFile.audioTracks.length);
|
||||
}
|
||||
|
||||
// Append title to the list of processed files
|
||||
|
@ -166,7 +140,7 @@ const main = async () => {
|
|||
|
||||
// Send confirmation to the user that we're done
|
||||
await internals.confirmation(
|
||||
`${files.length} fichiers traités : ${processedFiles}` + errorMessage
|
||||
`${files.length} fichiers traités : ${processedFiles}` + errorMessage,
|
||||
);
|
||||
|
||||
await internals.exit();
|
||||
|
|
|
@ -25,9 +25,7 @@ export const getVideoDuration = (file: string) => {
|
|||
export const getNumberOfAudioTracks = (file: string): number[] => {
|
||||
const command = `"${ffprobePath}" -v error -show_entries stream=bit_rate -select_streams a -of json "${file}"`;
|
||||
const result = child_process.execSync(command, { encoding: "utf8" });
|
||||
return JSON.parse(result).streams.map(
|
||||
(v: { bit_rate: string }) => Number(v.bit_rate) / 1000
|
||||
);
|
||||
return JSON.parse(result).streams.map((v: { bit_rate: string }) => Number(v.bit_rate) / 1000);
|
||||
};
|
||||
|
||||
/** Print an error to the console and open the dev tool panel */
|
||||
|
@ -37,9 +35,7 @@ export const printAndDevTool = (win: BrowserWindow, err: string) => {
|
|||
};
|
||||
|
||||
/** Run a command asynchronously */
|
||||
export const execute = (
|
||||
command: string
|
||||
): Promise<{ stdout: string; stderr: string }> => {
|
||||
export const execute = (command: string): Promise<{ stdout: string; stderr: string }> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const process = child_process.exec(command, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue