2022-06-17 01:25:43 +02:00
|
|
|
import os from 'node:os';
|
|
|
|
import { exec } from 'node:child_process';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
downloadVideo,
|
|
|
|
upload,
|
2022-06-17 02:14:14 +02:00
|
|
|
ffmpeg,
|
2022-06-20 08:34:18 +02:00
|
|
|
stringIsAValidurl,
|
2022-06-17 01:25:43 +02:00
|
|
|
};
|
2022-06-20 08:34:18 +02:00
|
|
|
async function downloadVideo(urlArg, output, format = 'bestvideo*+bestaudio/best') {
|
2022-06-17 01:25:43 +02:00
|
|
|
await new Promise((resolve, reject) => {
|
2022-07-06 18:52:44 +02:00
|
|
|
exec(`./bin/yt-dlp -f ${format} "${urlArg}" -o "${os.tmpdir()}/${output}.%(ext)s" --force-overwrites --no-playlist`, (err, stdout, stderr) => {
|
2022-06-17 01:25:43 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2022-06-20 08:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function stringIsAValidurl(s) {
|
|
|
|
try {
|
|
|
|
new URL(s);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-07-06 18:52:44 +02:00
|
|
|
}
|