Converter is a huge W.I.P !!!! expect bugs!!!
This commit is contained in:
parent
94ebbfba18
commit
72d25bf5e1
8 changed files with 318 additions and 31 deletions
51
index.js
51
index.js
|
@ -2,11 +2,27 @@ const ytdl = require('ytdl-core'),
|
|||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
express = require('express'),
|
||||
ffmpeg = require('fluent-ffmpeg')
|
||||
ffmpeg = require('fluent-ffmpeg'),
|
||||
bodyParser = require('body-parser'),
|
||||
multer = require('multer')
|
||||
|
||||
const PORT = process.env.PORT || 8080
|
||||
const app = express()
|
||||
|
||||
const storage = multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
cb(null, 'uploads/')
|
||||
},
|
||||
filename: function (req, file, cb) {
|
||||
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
|
||||
cb(null, file.fieldname + '-' + uniqueSuffix + '-' + file.originalname)
|
||||
}
|
||||
})
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: false }))
|
||||
|
||||
var jsonParser = bodyParser.json()
|
||||
|
||||
app.get("/download", (req, res) => {
|
||||
const filename = req.query.filename
|
||||
const url = req.query.url
|
||||
|
@ -14,19 +30,38 @@ app.get("/download", (req, res) => {
|
|||
const quality = req.query.quality
|
||||
|
||||
if (format != "mp4" && format != "webm") {
|
||||
var proc = new ffmpeg({ source: ytdl(url, { 'quality': quality })})
|
||||
.format(format)
|
||||
.pipe(res)
|
||||
res.header('Content-Disposition', `attachment; filename="${filename}.${format};"`);
|
||||
|
||||
var proc = new ffmpeg({ source: ytdl(url, { 'quality': quality }) })
|
||||
.format(format)
|
||||
.pipe(res)
|
||||
|
||||
res.header('Content-Disposition', `attachment; filename="${filename}.${format}"`);
|
||||
|
||||
} else {
|
||||
res.header('Content-Disposition', `attachment; filename="${filename}.${format}"`);
|
||||
ytdl(url, { 'format': format, 'quality': quality }).pipe(res);
|
||||
res.header('Content-Disposition', `attachment; filename="${filename}.${format}"`);
|
||||
ytdl(url, { 'format': format, 'quality': quality }).pipe(res);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
const upload = multer({ limits: { fieldSize: 100_000_000 }, storage: storage })
|
||||
|
||||
app.post("/convert", upload.single('video'), (req, res) => {
|
||||
console.log(req.file.path)
|
||||
const filename = req.body.filename
|
||||
const vid = req.file.path
|
||||
const format = req.body.format
|
||||
|
||||
var proc = new ffmpeg({ source: vid })
|
||||
.format(format)
|
||||
.pipe(res)
|
||||
.on("end", () => {
|
||||
console.log("AAAA")
|
||||
fs.unlinkSync(req.file.path)
|
||||
})
|
||||
|
||||
res.header('Content-Disposition', `attachment; filename="${filename}.${format}"`);
|
||||
});
|
||||
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'static')))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue