Converter update!
This commit is contained in:
parent
0980a2aa8b
commit
a8fa9b9783
7 changed files with 257 additions and 18 deletions
34
index.js
34
index.js
|
@ -2,14 +2,18 @@ const ytdl = require('ytdl-core'),
|
|||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
express = require('express'),
|
||||
multer = require('multer'),
|
||||
bodyParser = require('body-parser'),
|
||||
cp = require("child_process"),
|
||||
ffmpeg = require('ffmpeg-static')
|
||||
ffmpeg = require('ffmpeg-static'),
|
||||
stream = require('stream')
|
||||
|
||||
|
||||
const PORT = process.env.PORT || 8080
|
||||
const app = express()
|
||||
|
||||
var upload = multer({ dest: 'uploads' })
|
||||
|
||||
var formats = {
|
||||
"matroska": "mkv"
|
||||
}
|
||||
|
@ -26,6 +30,34 @@ process.on('uncaughtException', (err, origin) => {
|
|||
|
||||
app.use(bodyParser.urlencoded({ extended: false }))
|
||||
|
||||
app.post("/converter", upload.single("video"), async (req, res) => {
|
||||
var videoInfo = req.file
|
||||
var format = req.body.format
|
||||
|
||||
const ffmpegProcess = cp.spawn(ffmpeg, [
|
||||
'-i', videoInfo.path,
|
||||
'-c:v', 'copy',
|
||||
'-c:a', 'libmp3lame',
|
||||
'-crf','27',
|
||||
'-preset','veryfast',
|
||||
'-movflags','frag_keyframe+empty_moov',
|
||||
'-f', format,
|
||||
'-loglevel','error',
|
||||
'-'
|
||||
], {
|
||||
stdio: [
|
||||
'pipe', 'pipe', 'pipe', 'pipe', 'pipe',
|
||||
],
|
||||
})
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${videoInfo.originalname.substring(0, videoInfo.originalname.lastIndexOf('.') +1)}${format}"`);
|
||||
|
||||
ffmpegProcess.stdio[1]
|
||||
.pipe(res)
|
||||
.on("close", () => {
|
||||
fs.rmSync(videoInfo.path)
|
||||
})
|
||||
})
|
||||
|
||||
app.get("/download", async (req, res) => {
|
||||
const url = req.query.url
|
||||
const format = req.query.format
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue