Add video title

This commit is contained in:
Bingus_Violet 2024-01-17 22:17:27 -06:00
parent c064ddd0c9
commit 83e901520c

View file

@ -16,9 +16,15 @@ var formats = {
app.get("/convert", async (req, res) => {
var file = req.query.file || ""
var format = req.query.format
var url = req.query.url
var filePath = path.join(__dirname, 'downloads', file)
if (fs.existsSync(filePath)) {
res.setHeader('Content-Disposition', `attachment; filename="test.${format}"`);
var ytdlpProcess = cp.spawnSync('yt-dlp', ['--get-filename', url])
var name = ytdlpProcess.stdout.toString()
name = name.substring(0, name.lastIndexOf("[") - 1)
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(name)}.${format}"`);
const ffmpegProcess = cp.spawn(ffmpeg, [
'-i', filePath,
'-f', formats[format] || format,
@ -48,8 +54,6 @@ app.get("/download", async (req, res) => {
const url = req.query.url
const format = req.query.format || 'mp4'
const quality = req.query.quality || 'highest'
const defin = req.query.definition || 'hd'
const preset = 'medium'
res.setHeader("X-Accel-Buffering", "no")
res.setHeader("Content-Type", "text/html")
@ -58,7 +62,6 @@ app.get("/download", async (req, res) => {
res.write(downloadHTML.substring(0, downloadHTML.indexOf("{CONTENT}")))
console.log(format)
if (!["mp3"].includes(format)) {
var fileName = Math.round(Math.random() * 100_000_000_000_000).toString() + '.webm'
var filePath = path.join(__dirname, 'downloads', fileName)
@ -117,7 +120,7 @@ app.get("/download", async (req, res) => {
}
}
else if (fs.existsSync(filePath)) {
res.write(`<iframe src="/convert?file=${fileName}&format=${format}"></iframe>"`)
res.write(`<iframe src="/convert?file=${fileName}&format=${format}&url=${url}"></iframe>"`)
res.write(downloadHTML.substring(downloadHTML.indexOf("{CONTENT}") + 9), () => {res.end()})
} else {
res.write("<p>An error has occured!!! We're not exactly sure what the error is, but we cant seem to find the download file. Double check the URL, and if the URL is fine, then file an issue on codeberg. </p>")