Use Local YT-DLP, remove space from filenames
This commit is contained in:
parent
1c4af0ebbf
commit
ed31ad71ae
2 changed files with 17 additions and 17 deletions
34
index.js
34
index.js
|
@ -23,7 +23,7 @@ app.get("/convert", async (req, res) => {
|
||||||
var filePath = path.join(__dirname, 'downloads', file)
|
var filePath = path.join(__dirname, 'downloads', file)
|
||||||
|
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
var ytdlpProcess = cp.spawnSync('yt-dlp', ['--get-filename', url])
|
var ytdlpProcess = cp.spawnSync('./yt-dlp', ['--get-filename', url])
|
||||||
var name = ytdlpProcess.stdout.toString()
|
var name = ytdlpProcess.stdout.toString()
|
||||||
name = name.substring(0, name.lastIndexOf("[") - 1)
|
name = name.substring(0, name.lastIndexOf("[") - 1)
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(name)}.${format}"`);
|
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(name)}.${format}"`);
|
||||||
|
@ -43,9 +43,9 @@ app.get("/convert", async (req, res) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
ffmpegProcess.stderr.setEncoding('utf-8')
|
ffmpegProcess.stderr.setEncoding('utf-8')
|
||||||
ffmpegProcess.stderr.on('data', (data) => {
|
// ffmpegProcess.stderr.on('data', (data) => {
|
||||||
console.log(data)
|
// console.log(data)
|
||||||
})
|
// })
|
||||||
// These are debugging lines to watch FFMPEG output :3
|
// These are debugging lines to watch FFMPEG output :3
|
||||||
|
|
||||||
ffmpegProcess.stdio[1].pipe(res)
|
ffmpegProcess.stdio[1].pipe(res)
|
||||||
|
@ -63,10 +63,10 @@ app.get("/download", async (req, res) => {
|
||||||
res.setHeader("X-Accel-Buffering", "no")
|
res.setHeader("X-Accel-Buffering", "no")
|
||||||
|
|
||||||
var fileName = Math.ceil(Math.random() * 100_000_000_000).toString()
|
var fileName = Math.ceil(Math.random() * 100_000_000_000).toString()
|
||||||
var videoName = cp.spawnSync('yt-dlp', ['-S', 'res:' + quality, '--get-filename', url]).stdout.toString()
|
var videoName = cp.spawnSync('./yt-dlp', ['-S', 'res:' + quality, '--get-filename', url]).stdout.toString()
|
||||||
|
|
||||||
videoName = videoName.substring(0, videoName.lastIndexOf('.'))
|
videoName = videoName.substring(0, videoName.lastIndexOf('.'))
|
||||||
videoName = videoName.substring(0, videoName.lastIndexOf('['))
|
videoName = videoName.substring(0, videoName.lastIndexOf('[') - 1)
|
||||||
|
|
||||||
if (!["mp3", "wav", "ogx"].includes(format) && Number(quality) > 720) {
|
if (!["mp3", "wav", "ogx"].includes(format) && Number(quality) > 720) {
|
||||||
res.setHeader("Content-Type", "text/html")
|
res.setHeader("Content-Type", "text/html")
|
||||||
|
@ -76,7 +76,7 @@ app.get("/download", async (req, res) => {
|
||||||
res.write(downloadHTML.substring(0, downloadHTML.indexOf("{CONTENT}")))
|
res.write(downloadHTML.substring(0, downloadHTML.indexOf("{CONTENT}")))
|
||||||
|
|
||||||
var filePath = path.join(__dirname, 'downloads', fileName)
|
var filePath = path.join(__dirname, 'downloads', fileName)
|
||||||
var ytdlpProcess = cp.spawn('yt-dlp', [
|
var ytdlpProcess = cp.spawn('./yt-dlp', [
|
||||||
url,
|
url,
|
||||||
'-o', filePath,
|
'-o', filePath,
|
||||||
'--max-filesize', MAX_FILESIZE + 'm',
|
'--max-filesize', MAX_FILESIZE + 'm',
|
||||||
|
@ -88,7 +88,7 @@ app.get("/download", async (req, res) => {
|
||||||
|
|
||||||
ytdlpProcess.stderr.setEncoding('utf-8')
|
ytdlpProcess.stderr.setEncoding('utf-8')
|
||||||
ytdlpProcess.stderr.on('data', (data) => {
|
ytdlpProcess.stderr.on('data', (data) => {
|
||||||
console.log(data)
|
// console.log(data)
|
||||||
res.write(`<div class="error"><p>` + data + `</p></div>`)
|
res.write(`<div class="error"><p>` + data + `</p></div>`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ app.get("/download", async (req, res) => {
|
||||||
var files = fs.readdirSync(path.join(__dirname, 'downloads'))
|
var files = fs.readdirSync(path.join(__dirname, 'downloads'))
|
||||||
for (let index = 0; index < files.length; index++) {
|
for (let index = 0; index < files.length; index++) {
|
||||||
const file = files[index];
|
const file = files[index];
|
||||||
console.log(file)
|
console.log(fileName)
|
||||||
if (file.includes(fileName)) {
|
if (file.includes(fileName)) {
|
||||||
fileName = file
|
fileName = file
|
||||||
filePath = path.join(__dirname, 'downloads', fileName)
|
filePath = path.join(__dirname, 'downloads', fileName)
|
||||||
|
@ -147,7 +147,7 @@ app.get("/download", async (req, res) => {
|
||||||
} else if (["mp3", "wav", "opus"].includes(format)) {
|
} else if (["mp3", "wav", "opus"].includes(format)) {
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(videoName)}.${format}"`);
|
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(videoName)}.${format}"`);
|
||||||
|
|
||||||
var ytdlpProcess = cp.spawn('yt-dlp', [
|
var ytdlpProcess = cp.spawn('./yt-dlp', [
|
||||||
url,
|
url,
|
||||||
'-x',
|
'-x',
|
||||||
'-o', '-',
|
'-o', '-',
|
||||||
|
@ -173,15 +173,15 @@ app.get("/download", async (req, res) => {
|
||||||
ytdlpProcess.stdout.pipe(ffmpegProcess.stdio[3])
|
ytdlpProcess.stdout.pipe(ffmpegProcess.stdio[3])
|
||||||
|
|
||||||
ytdlpProcess.stderr.setEncoding('utf-8')
|
ytdlpProcess.stderr.setEncoding('utf-8')
|
||||||
ytdlpProcess.stderr.on('data', (data) => {
|
// ytdlpProcess.stderr.on('data', (data) => {
|
||||||
console.log(data)
|
// console.log(data)
|
||||||
})
|
// })
|
||||||
|
|
||||||
ffmpegProcess.stdio[1].pipe(res)
|
ffmpegProcess.stdio[1].pipe(res)
|
||||||
} else {
|
} else {
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(videoName)}.${format}"`);
|
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(videoName)}.${format}"`);
|
||||||
|
|
||||||
var ytdlpProcess = cp.spawn('yt-dlp', [
|
var ytdlpProcess = cp.spawn('./yt-dlp', [
|
||||||
url,
|
url,
|
||||||
'-o', '-',
|
'-o', '-',
|
||||||
'--max-filesize', MAX_FILESIZE + 'm',
|
'--max-filesize', MAX_FILESIZE + 'm',
|
||||||
|
@ -207,9 +207,9 @@ app.get("/download", async (req, res) => {
|
||||||
ytdlpProcess.stdout.pipe(ffmpegProcess.stdio[3])
|
ytdlpProcess.stdout.pipe(ffmpegProcess.stdio[3])
|
||||||
|
|
||||||
ytdlpProcess.stderr.setEncoding('utf-8')
|
ytdlpProcess.stderr.setEncoding('utf-8')
|
||||||
ytdlpProcess.stderr.on('data', (data) => {
|
// ytdlpProcess.stderr.on('data', (data) => {
|
||||||
console.log(data)
|
// console.log(data)
|
||||||
})
|
// })
|
||||||
|
|
||||||
ffmpegProcess.stdio[1].pipe(res)
|
ffmpegProcess.stdio[1].pipe(res)
|
||||||
}
|
}
|
||||||
|
|
BIN
yt-dlp
Executable file
BIN
yt-dlp
Executable file
Binary file not shown.
Loading…
Reference in a new issue