Update Drafting.ts
c# dont fry my brain challenge
This commit is contained in:
parent
bb1bb3db16
commit
7a95c7a537
|
@ -201,35 +201,34 @@ App.post("/upload/audio",
|
||||||
|
|
||||||
const AudioPath = `${SAVED_DATA_PATH}/Songs/${req.body.TargetSong}`;
|
const AudioPath = `${SAVED_DATA_PATH}/Songs/${req.body.TargetSong}`;
|
||||||
|
|
||||||
await writeFileSync(AudioPath + `/Audio.${ext}`, Decoded);
|
await writeFileSync(`${AudioPath}/Audio.${ext}`, Decoded);
|
||||||
ffmpeg()
|
ffmpeg()
|
||||||
.input(AudioPath + `/Audio.${ext}`)
|
.input(`${AudioPath}/Audio.${ext}`)
|
||||||
.audioCodec("libopus")
|
.audioCodec("libopus")
|
||||||
.outputOptions([
|
.outputOptions([
|
||||||
"-use_timeline 1",
|
"-use_timeline 1",
|
||||||
"-f dash",
|
"-f dash",
|
||||||
"-mapping_family 255"
|
"-mapping_family 255"
|
||||||
])
|
])
|
||||||
.output(AudioPath + `/Chunks/Manifest.mpd`)
|
.output(`${AudioPath}/Chunks/Manifest.mpd`)
|
||||||
.on("start", cl => Debug(`ffmpeg running with ${magenta(cl)}`))
|
.on("start", cl => Debug(`ffmpeg running with ${magenta(cl)}`))
|
||||||
.on("end", async () => {
|
.on("end", async () => {
|
||||||
Debug("Ffmpeg finished running");
|
Debug("Ffmpeg finished running");
|
||||||
|
|
||||||
// Check channels
|
// Check channels
|
||||||
ffmpeg.ffprobe(AudioPath + `/Audio.${ext}`, async (err, metadata) => {
|
ffmpeg.ffprobe(`${AudioPath}/Audio.${ext}`, async (err, metadata) => {
|
||||||
if (err) // FUCK
|
if (err) // FUCK
|
||||||
{
|
return console.log(err);
|
||||||
console.log(err);
|
|
||||||
}
|
if (metadata && metadata.streams && metadata.streams[0].codec_type == 'audio' && metadata.streams[0].channels && metadata.streams[0].channels > 2) // jfc ts
|
||||||
else if (metadata && metadata.streams && metadata.streams[0].codec_type == 'audio' && metadata.streams[0].channels && metadata.streams[0].channels > 2) // jfc ts
|
|
||||||
{
|
{
|
||||||
Debug(`Creating preview stream as it's needed...`);
|
Debug(`Creating preview stream as it's needed...`);
|
||||||
|
|
||||||
// Oh shit!! we need a preview stream!! so let's make one.
|
// Oh shit!! we need a preview stream!! so let's make one.
|
||||||
|
|
||||||
// Make a dir for it first
|
// Make a dir for it first
|
||||||
if (!existsSync(AudioPath + "/PreviewChunks"))
|
if (!existsSync(`${AudioPath}/PreviewChunks`))
|
||||||
mkdirSync(AudioPath + "/PreviewChunks", { recursive: true });
|
mkdirSync(`${AudioPath}/PreviewChunks`, { recursive: true });
|
||||||
|
|
||||||
// Then, figure out which channels from the original file to put into each channel on the output file.
|
// Then, figure out which channels from the original file to put into each channel on the output file.
|
||||||
// We already ran ffprobe earlier so we can just reuse that lol
|
// We already ran ffprobe earlier so we can just reuse that lol
|
||||||
|
@ -246,7 +245,7 @@ App.post("/upload/audio",
|
||||||
// Need to wait for this before removing the source file, but since it won't ALWAYS get called we don't put the rmSync in here
|
// Need to wait for this before removing the source file, but since it won't ALWAYS get called we don't put the rmSync in here
|
||||||
await new Promise<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
ffmpeg()
|
ffmpeg()
|
||||||
.input(AudioPath + `/Audio.${ext}`)
|
.input(`${AudioPath}/Audio.${ext}`)
|
||||||
.audioCodec("libopus")
|
.audioCodec("libopus")
|
||||||
.audioFilter(FilterLeft + FilterRight)
|
.audioFilter(FilterLeft + FilterRight)
|
||||||
.outputOptions([
|
.outputOptions([
|
||||||
|
@ -254,13 +253,13 @@ App.post("/upload/audio",
|
||||||
"-f dash",
|
"-f dash",
|
||||||
"-ac 2", // downmix
|
"-ac 2", // downmix
|
||||||
])
|
])
|
||||||
.output(AudioPath + `/PreviewChunks/PreviewManifest.mpd`)
|
.output(`${AudioPath}/PreviewChunks/PreviewManifest.mpd`)
|
||||||
.on("start", cl => Debug(`Creating preview stream with ${magenta(cl)}`))
|
.on("start", cl => Debug(`Creating preview stream with ${magenta(cl)}`))
|
||||||
.on("end", async () => {
|
.on("end", async () => {
|
||||||
Debug(`Preview stream created`);
|
Debug(`Preview stream created`);
|
||||||
// Move the mpd out
|
// Move the mpd out
|
||||||
renameSync(AudioPath + `/PreviewChunks/PreviewManifest.mpd`, AudioPath + `/PreviewManifest.mpd`);
|
renameSync(`${AudioPath}/PreviewChunks/PreviewManifest.mpd`, `${AudioPath}/PreviewManifest.mpd`);
|
||||||
writeFileSync(AudioPath + `/PreviewManifest.mpd`, readFileSync(AudioPath + `/PreviewManifest.mpd`).toString().replace(/<ProgramInformation>[\w\d\r\n\t]*<\/ProgramInformation>/i, "<BaseURL>{BASEURL}</BaseURL>"));
|
writeFileSync(`${AudioPath}/PreviewManifest.mpd`, readFileSync(`${AudioPath}/PreviewManifest.mpd`).toString().replace(/<ProgramInformation>[\w\d\r\n\t]*<\/ProgramInformation>/i, "<BaseURL>{BASEURL}</BaseURL>"));
|
||||||
SongData.PID = v4();
|
SongData.PID = v4();
|
||||||
await SongData.save();
|
await SongData.save();
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -274,11 +273,11 @@ App.post("/upload/audio",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
rmSync(AudioPath + `/Audio.${ext}`);
|
rmSync(`${AudioPath}/Audio.${ext}`);
|
||||||
|
|
||||||
renameSync(AudioPath + `/Chunks/Manifest.mpd`, AudioPath + `/Manifest.mpd`);
|
renameSync(`${AudioPath}/Chunks/Manifest.mpd`, `${AudioPath}/Manifest.mpd`);
|
||||||
// i love creating thread-safe code that always works! (never gonna error trust me)
|
// i love creating thread-safe code that always works! (never gonna error trust me)
|
||||||
writeFileSync(AudioPath + `/Manifest.mpd`, readFileSync(AudioPath + `/Manifest.mpd`).toString().replace(/<ProgramInformation>[\w\d\r\n\t]*<\/ProgramInformation>/i, "<BaseURL>{BASEURL}</BaseURL>"));
|
writeFileSync(`${AudioPath}/Manifest.mpd`, readFileSync(`${AudioPath}/Manifest.mpd`).toString().replace(/<ProgramInformation>[\w\d\r\n\t]*<\/ProgramInformation>/i, "<BaseURL>{BASEURL}</BaseURL>"));
|
||||||
|
|
||||||
await SongData.reload();
|
await SongData.reload();
|
||||||
SongData.HasAudio = true;
|
SongData.HasAudio = true;
|
||||||
|
@ -289,7 +288,7 @@ App.post("/upload/audio",
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
console.error(stderr);
|
console.error(stderr);
|
||||||
rmSync(AudioPath + `/Audio.${ext}`);
|
rmSync(`${AudioPath}/Audio.${ext}`);
|
||||||
|
|
||||||
await SongData.reload();
|
await SongData.reload();
|
||||||
SongData.Status = SongStatus.BROKEN;
|
SongData.Status = SongStatus.BROKEN;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user