forked from Supositware/Haha-Yes
Some utility
This commit is contained in:
parent
c8fc925d35
commit
1f8c5585dc
1 changed files with 49 additions and 0 deletions
49
utils/videos.js
Normal file
49
utils/videos.js
Normal file
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue