From 1f8c5585dc0b9d6356ae5c3eef0085b3be1ba1fc Mon Sep 17 00:00:00 2001 From: supositware Date: Fri, 17 Jun 2022 01:25:43 +0200 Subject: [PATCH] Some utility --- utils/videos.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 utils/videos.js diff --git a/utils/videos.js b/utils/videos.js new file mode 100644 index 00000000..a7bd343a --- /dev/null +++ b/utils/videos.js @@ -0,0 +1,49 @@ +import os from 'node:os'; +import { exec } from 'node:child_process'; + +export default { + downloadVideo, + upload, + ffmpeg +}; +async function downloadVideo(url, output, format = 'bestvideo*+bestaudio/best') { + await new Promise((resolve, reject) => { + exec(`./bin/yt-dlp -f ${format} ${url} -o "${os.tmpdir()}/${output}.%(ext)s" --force-overwrites`, (err, stdout, stderr) => { + if (err) { + reject(stderr); + } + if (stderr) { + console.error(stderr); + } + resolve(stdout); + }); + }); +} + +async function upload(file) { + return await new Promise((resolve, reject) => { + exec(`./bin/upload.sh ${file}`, (err, stdout, stderr) => { + if (err) { + reject(stderr); + } + if (stderr) { + console.error(stderr); + } + resolve(stdout); + }); + }); +} + +async function ffmpeg(command) { + return await new Promise((resolve, reject) => { + exec(`ffmpeg ${command}`, (err, stdout, stderr) => { + if (err) { + reject(stderr); + } + if (stderr) { + console.error(stderr); + } + resolve(stdout); + }); + }); +} \ No newline at end of file