[repo] desacoplamento e maior coesão
This commit is contained in:
synt-xerror
2026-03-13 11:30:34 -03:00
parent a48b747b8e
commit b2fecab660
19 changed files with 439 additions and 393 deletions

24
src/download/audio.js Normal file
View File

@@ -0,0 +1,24 @@
import { get_video } from "./video.js";
import { spawn } from "child_process";
import os from "os";
const so = os.platform();
export async function get_audio(url, id) {
const video = await get_video(url, id);
const output = `downloads/${id}.mp3`;
const cmd = so === "win32" ? ".\\bin\\ffmpeg.exe" : "./bin/ffmpeg";
const args = ['-i', video, '-vn', '-acodec', 'libmp3lame', '-q:a', '2', output];
await runCmd(cmd, args);
return output;
}
async function runCmd(cmd, args) {
return new Promise((resolve, reject) => {
const proc = spawn(cmd, args);
proc.stdout.on("data", data => console.log("[cmd]", data.toString()));
proc.stderr.on("data", data => console.error("[cmd ERR]", data.toString()));
proc.on("close", code => code === 0 ? resolve() : reject(new Error("Processo saiu com código "+code)));
});
}