Should work with all sites now. tiktok mp3s dont work for some reason.
This commit is contained in:
parent
7df6225669
commit
c211cfcc0b
1 changed files with 80 additions and 62 deletions
142
downloader.js
142
downloader.js
|
@ -62,7 +62,7 @@ expressManager.app.get("/download", async (req, res) => {
|
||||||
|
|
||||||
var downloadMode = "audio"
|
var downloadMode = "audio"
|
||||||
if (needsVideo) downloadMode = "auto"
|
if (needsVideo) downloadMode = "auto"
|
||||||
|
|
||||||
var info = await axios.post("https://cobalt.univerter.dev/", {
|
var info = await axios.post("https://cobalt.univerter.dev/", {
|
||||||
url,
|
url,
|
||||||
downloadMode,
|
downloadMode,
|
||||||
|
@ -75,74 +75,92 @@ expressManager.app.get("/download", async (req, res) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(info)
|
|
||||||
|
|
||||||
var downloadType = "attachment"
|
|
||||||
if (req.query.playInBrowser) downloadType = "inline";
|
|
||||||
|
|
||||||
var filename = info.data.filename || info.data.output.filename
|
var filename = info.data.filename || info.data.output.filename
|
||||||
|
|
||||||
res.setHeader("Content-Disposition", `${downloadType}; filename="${filename.replace(/[^a-z0-9 ]/gi, '')}.${format}"`)
|
res.setHeader("Content-Disposition", `${downloadType}; filename="${filename.replace(/[^a-z0-9 ]/gi, '')}.${format}"`)
|
||||||
var baseArgs = [
|
|
||||||
// Remove ffmpeg's console spamming
|
|
||||||
'-loglevel', 'error',
|
|
||||||
// // Set inputs
|
|
||||||
// '-i', 'pipe:4',
|
|
||||||
// '-i', 'pipe:5',
|
|
||||||
// Map audio & video from streams
|
|
||||||
// '-map', '0:a',
|
|
||||||
// '-map', '1:v',
|
|
||||||
// Keep encoding
|
|
||||||
'-c:v', 'copy',
|
|
||||||
'-movflags','frag_keyframe+empty_moov',
|
|
||||||
'-f', format,
|
|
||||||
// Define output file
|
|
||||||
'-',
|
|
||||||
]
|
|
||||||
|
|
||||||
var inputArgs = [
|
|
||||||
'-i', 'pipe:4'
|
|
||||||
]
|
|
||||||
|
|
||||||
var mapArgs = [
|
if (info.data.service == "youtube") {
|
||||||
'-map', '0:a'
|
|
||||||
]
|
|
||||||
|
|
||||||
var bonusArgs = []
|
var downloadType = "attachment"
|
||||||
|
if (req.query.playInBrowser) downloadType = "inline";
|
||||||
|
|
||||||
|
var baseArgs = [
|
||||||
|
// Remove ffmpeg's console spamming
|
||||||
|
'-loglevel', 'error',
|
||||||
|
// // Set inputs
|
||||||
|
// '-i', 'pipe:4',
|
||||||
|
// '-i', 'pipe:5',
|
||||||
|
// Map audio & video from streams
|
||||||
|
// '-map', '0:a',
|
||||||
|
// '-map', '1:v',
|
||||||
|
// Keep encoding
|
||||||
|
'-c:v', 'copy',
|
||||||
|
'-movflags','frag_keyframe+empty_moov',
|
||||||
|
'-f', format,
|
||||||
|
// Define output file
|
||||||
|
'-',
|
||||||
|
]
|
||||||
|
|
||||||
|
var inputArgs = [
|
||||||
|
'-i', 'pipe:4'
|
||||||
|
]
|
||||||
|
|
||||||
if (needsVideo) {
|
var mapArgs = [
|
||||||
inputArgs = inputArgs.concat(['-i', 'pipe:5'])
|
'-map', '0:a'
|
||||||
mapArgs = mapArgs.concat(['-map', '1:v'])
|
]
|
||||||
|
|
||||||
|
var bonusArgs = []
|
||||||
|
|
||||||
|
if (needsVideo) {
|
||||||
|
inputArgs = inputArgs.concat(['-i', 'pipe:5'])
|
||||||
|
mapArgs = mapArgs.concat(['-map', '1:v'])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trimAudio) {
|
||||||
|
bonusArgs = bonusArgs.concat(['-af', 'silenceremove=1:0:-50dB'])
|
||||||
|
}
|
||||||
|
|
||||||
|
var args = inputArgs.concat(mapArgs).concat(bonusArgs).concat(baseArgs)
|
||||||
|
|
||||||
|
const ffmpegProcess = cp.spawn(ffmpeg, args, {
|
||||||
|
windowsHide: true,
|
||||||
|
stdio: [
|
||||||
|
/* Standard: stdin, stdout, stderr */
|
||||||
|
'pipe', 'pipe', 'pipe',
|
||||||
|
/* Custom: pipe:3, pipe:4, pipe:5 */
|
||||||
|
'pipe', 'pipe', 'pipe',
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
ffmpegProcess.stdio[1].pipe(res)
|
||||||
|
|
||||||
|
var audio = await fetch(info.data.tunnel[1] || info.data.tunnel[0])
|
||||||
|
|
||||||
|
Readable.fromWeb(audio.body).pipe(ffmpegProcess.stdio[4])
|
||||||
|
|
||||||
|
if (needsVideo) {
|
||||||
|
var video = await fetch(info.data.tunnel[0])
|
||||||
|
|
||||||
|
Readable.fromWeb(video.body).pipe(ffmpegProcess.stdio[5])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var info = await axios.post("https://cobalt.univerter.dev/", {
|
||||||
|
url,
|
||||||
|
downloadMode,
|
||||||
|
videoQuality: quality,
|
||||||
|
localProcessing: false,
|
||||||
|
}, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(info)
|
||||||
|
var video = await fetch(info.data.url)
|
||||||
|
|
||||||
|
Readable.fromWeb(video.body).pipe(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trimAudio) {
|
|
||||||
bonusArgs = bonusArgs.concat(['-af', 'silenceremove=1:0:-50dB'])
|
|
||||||
}
|
|
||||||
|
|
||||||
var args = inputArgs.concat(mapArgs).concat(bonusArgs).concat(baseArgs)
|
|
||||||
|
|
||||||
const ffmpegProcess = cp.spawn(ffmpeg, args, {
|
|
||||||
windowsHide: true,
|
|
||||||
stdio: [
|
|
||||||
/* Standard: stdin, stdout, stderr */
|
|
||||||
'pipe', 'pipe', 'pipe',
|
|
||||||
/* Custom: pipe:3, pipe:4, pipe:5 */
|
|
||||||
'pipe', 'pipe', 'pipe',
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
ffmpegProcess.stdio[1].pipe(res)
|
|
||||||
|
|
||||||
var audio = await fetch(info.data.url || info.data.tunnel[1] || info.data.tunnel[0])
|
|
||||||
|
|
||||||
Readable.fromWeb(audio.body).pipe(ffmpegProcess.stdio[4])
|
|
||||||
|
|
||||||
if (needsVideo) {
|
|
||||||
var video = await fetch(info.data.url || info.data.tunnel[0])
|
|
||||||
|
|
||||||
Readable.fromWeb(video.body).pipe(ffmpegProcess.stdio[5])
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
res.send("Invalid URL!")
|
res.send("Invalid URL!")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue