backend/utils/ytdlp.js

29 lines
853 B
JavaScript
Raw Normal View History

2023-03-03 16:44:40 +00:00
const child_process = require('child_process')
async function downloadVideo(url, ws) {
return new Promise((resolve, reject) => {
2023-03-11 07:20:20 +00:00
const child = child_process.spawn("../yt-dlp", ["--max-filesize=2G", url], {cwd: 'videos', shell: false})
2023-03-03 16:44:40 +00:00
child.stdout.on("data", data => {
const msg = data.toString().trim()
if (!msg) return
if (ws) ws.send(`DATA - ${msg}`)
2023-03-03 16:44:40 +00:00
})
child.on("close", async (code, signal) => {
if (code == 2) {
reject({
fail: true,
2023-03-11 07:20:20 +00:00
message: 'Video file is above 2GB. Consider selfhosting PreserveTube!'
2023-03-03 16:44:40 +00:00
})
} else {
resolve({
fail: false
})
}
})
})
}
module.exports = { downloadVideo }