mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-17 05:02:06 +00:00
Mutex in ffmpeg conversion (only supports one command at a time)
This commit is contained in:
@ -66,6 +66,7 @@
|
|||||||
"@ffmpeg/core": "^0.8.5",
|
"@ffmpeg/core": "^0.8.5",
|
||||||
"@ffmpeg/ffmpeg": "^0.9.7",
|
"@ffmpeg/ffmpeg": "^0.9.7",
|
||||||
"YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.8.1",
|
"YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.8.1",
|
||||||
|
"async-mutex": "^0.3.1",
|
||||||
"browser-id3-writer": "^4.4.0",
|
"browser-id3-writer": "^4.4.0",
|
||||||
"discord-rpc": "^3.2.0",
|
"discord-rpc": "^3.2.0",
|
||||||
"downloads-folder": "^3.0.1",
|
"downloads-folder": "^3.0.1",
|
||||||
|
|||||||
@ -2,6 +2,7 @@ const { randomBytes } = require("crypto");
|
|||||||
const { join } = require("path");
|
const { join } = require("path");
|
||||||
|
|
||||||
const downloadsFolder = require("downloads-folder");
|
const downloadsFolder = require("downloads-folder");
|
||||||
|
const Mutex = require("async-mutex").Mutex;
|
||||||
const { ipcRenderer } = require("electron");
|
const { ipcRenderer } = require("electron");
|
||||||
const is = require("electron-is");
|
const is = require("electron-is");
|
||||||
const filenamify = require("filenamify");
|
const filenamify = require("filenamify");
|
||||||
@ -21,6 +22,7 @@ const ffmpeg = createFFmpeg({
|
|||||||
logger: () => {}, // console.log,
|
logger: () => {}, // console.log,
|
||||||
progress: () => {}, // console.log,
|
progress: () => {}, // console.log,
|
||||||
});
|
});
|
||||||
|
const ffmpegMutex = new Mutex();
|
||||||
|
|
||||||
const downloadVideoToMP3 = (
|
const downloadVideoToMP3 = (
|
||||||
videoUrl,
|
videoUrl,
|
||||||
@ -66,9 +68,9 @@ const downloadVideoToMP3 = (
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on("error", sendError)
|
.on("error", sendError)
|
||||||
.on("end", () => {
|
.on("end", async () => {
|
||||||
const buffer = Buffer.concat(chunks);
|
const buffer = Buffer.concat(chunks);
|
||||||
toMP3(videoName, buffer, sendFeedback, sendError, reinit, options);
|
await toMP3(videoName, buffer, sendFeedback, sendError, reinit, options);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,6 +84,7 @@ const toMP3 = async (
|
|||||||
) => {
|
) => {
|
||||||
const safeVideoName = randomBytes(32).toString("hex");
|
const safeVideoName = randomBytes(32).toString("hex");
|
||||||
const extension = options.extension || "mp3";
|
const extension = options.extension || "mp3";
|
||||||
|
const releaseFFmpegMutex = await ffmpegMutex.acquire();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!ffmpeg.isLoaded()) {
|
if (!ffmpeg.isLoaded()) {
|
||||||
@ -120,6 +123,8 @@ const toMP3 = async (
|
|||||||
ipcRenderer.once("add-metadata-done", reinit);
|
ipcRenderer.once("add-metadata-done", reinit);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
sendError(e);
|
sendError(e);
|
||||||
|
} finally {
|
||||||
|
releaseFFmpegMutex();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
12
yarn.lock
12
yarn.lock
@ -1661,6 +1661,13 @@ async-exit-hook@^2.0.1:
|
|||||||
resolved "https://registry.yarnpkg.com/async-exit-hook/-/async-exit-hook-2.0.1.tgz#8bd8b024b0ec9b1c01cccb9af9db29bd717dfaf3"
|
resolved "https://registry.yarnpkg.com/async-exit-hook/-/async-exit-hook-2.0.1.tgz#8bd8b024b0ec9b1c01cccb9af9db29bd717dfaf3"
|
||||||
integrity sha512-NW2cX8m1Q7KPA7a5M2ULQeZ2wR5qI5PAbw5L0UOMxdioVk9PMZ0h1TmyZEkPYrCvYjDlFICusOu1dlEKAAeXBw==
|
integrity sha512-NW2cX8m1Q7KPA7a5M2ULQeZ2wR5qI5PAbw5L0UOMxdioVk9PMZ0h1TmyZEkPYrCvYjDlFICusOu1dlEKAAeXBw==
|
||||||
|
|
||||||
|
async-mutex@^0.3.1:
|
||||||
|
version "0.3.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.3.1.tgz#7033af665f1c7cebed8b878267a43ba9e77c5f67"
|
||||||
|
integrity sha512-vRfQwcqBnJTLzVQo72Sf7KIUbcSUP5hNchx6udI1U6LuPQpfePgdjJzlCe76yFZ8pxlLjn9lwcl/Ya0TSOv0Tw==
|
||||||
|
dependencies:
|
||||||
|
tslib "^2.1.0"
|
||||||
|
|
||||||
async@0.9.x:
|
async@0.9.x:
|
||||||
version "0.9.2"
|
version "0.9.2"
|
||||||
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"
|
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"
|
||||||
@ -8362,6 +8369,11 @@ tslib@^1.8.1:
|
|||||||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
|
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
|
||||||
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
|
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
|
||||||
|
|
||||||
|
tslib@^2.1.0:
|
||||||
|
version "2.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
|
||||||
|
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==
|
||||||
|
|
||||||
tsutils@^3.17.1:
|
tsutils@^3.17.1:
|
||||||
version "3.20.0"
|
version "3.20.0"
|
||||||
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.20.0.tgz#ea03ea45462e146b53d70ce0893de453ff24f698"
|
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.20.0.tgz#ea03ea45462e146b53d70ce0893de453ff24f698"
|
||||||
|
|||||||
Reference in New Issue
Block a user