Fixed bug, more audio format
This commit is contained in:
parent
7ecff6e95d
commit
ac4e2ad160
2 changed files with 35 additions and 19 deletions
32
index.js
32
index.js
|
@ -31,10 +31,10 @@ 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)
|
||||||
|
@ -58,14 +58,15 @@ app.get("/download", async (req, res) => {
|
||||||
|
|
||||||
res.write(downloadHTML.substring(0, downloadHTML.indexOf("{CONTENT}")))
|
res.write(downloadHTML.substring(0, downloadHTML.indexOf("{CONTENT}")))
|
||||||
|
|
||||||
|
console.log(format)
|
||||||
if (!format in ["mp3"]) {
|
if (!["mp3"].includes(format)) {
|
||||||
var fileName = Math.round(Math.random() * 100_000_000_000_000).toString() + '.webm'
|
var fileName = Math.round(Math.random() * 100_000_000_000_000).toString() + '.webm'
|
||||||
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',
|
||||||
|
'-S', 'res:' + quality
|
||||||
])
|
])
|
||||||
} else {
|
} else {
|
||||||
var fileName = Math.round(Math.random() * 100_000_000_000_000).toString()
|
var fileName = Math.round(Math.random() * 100_000_000_000_000).toString()
|
||||||
|
@ -75,7 +76,6 @@ app.get("/download", async (req, res) => {
|
||||||
'-x',
|
'-x',
|
||||||
'-o', filePath,
|
'-o', filePath,
|
||||||
'--max-filesize', MAX_FILESIZE + 'm',
|
'--max-filesize', MAX_FILESIZE + 'm',
|
||||||
|
|
||||||
])
|
])
|
||||||
fileName += '.opus'
|
fileName += '.opus'
|
||||||
filePath = path.join(__dirname, 'downloads', fileName)
|
filePath = path.join(__dirname, 'downloads', fileName)
|
||||||
|
@ -108,8 +108,15 @@ app.get("/download", async (req, res) => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var exited = false
|
||||||
|
|
||||||
ytdlpProcess.on('close', () => {
|
ytdlpProcess.on('close', () => {
|
||||||
if (fs.existsSync(filePath)) {
|
if (exited) {
|
||||||
|
if (fs.existsSync(filePath)) {
|
||||||
|
fs.rmSync(filePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (fs.existsSync(filePath)) {
|
||||||
res.write(`<iframe src="/convert?file=${fileName}&format=${format}"></iframe>"`)
|
res.write(`<iframe src="/convert?file=${fileName}&format=${format}"></iframe>"`)
|
||||||
res.write(downloadHTML.substring(downloadHTML.indexOf("{CONTENT}") + 9), () => {res.end()})
|
res.write(downloadHTML.substring(downloadHTML.indexOf("{CONTENT}") + 9), () => {res.end()})
|
||||||
} else {
|
} else {
|
||||||
|
@ -118,6 +125,13 @@ app.get("/download", async (req, res) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
res.on("error", () => {
|
||||||
|
if (fs.existsSync(filePath)) {
|
||||||
|
fs.rmSync(filePath)
|
||||||
|
}
|
||||||
|
exited = true
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.use(express.static(path.join(__dirname, 'static')))
|
app.use(express.static(path.join(__dirname, 'static')))
|
||||||
|
|
|
@ -22,17 +22,17 @@
|
||||||
<input required type="url" id="url" placeholder="Enter url" name="url" style="width: 80vw; max-width: 550px">
|
<input required type="url" id="url" placeholder="Enter url" name="url" style="width: 80vw; max-width: 550px">
|
||||||
|
|
||||||
<p>Quality:</p>
|
<p>Quality:</p>
|
||||||
<!-- <select required id="quality" name="quality">
|
<select required id="quality" name="quality">
|
||||||
<option value="highest">Highest</option>
|
<option value="144">144p</option>
|
||||||
<option value="lowest">Lowest</option>
|
<option value="240">240p</option>
|
||||||
</select> -->
|
<option value="360">360p</option>
|
||||||
|
<option value="480">480p</option>
|
||||||
<select required id="definition" name="definition">
|
<option value="720" selected>720p</option>
|
||||||
<option value="hd">HD (High Definition)</option>
|
<option value="1080">1080p</option>
|
||||||
<option value="sd">SD (Standard Definition)</option>
|
<option value="1440">1440p</option>
|
||||||
|
<option value="2160">2160p (4k)</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<p>Format:</p>
|
<p>Format:</p>
|
||||||
<select required id="format" name="format">
|
<select required id="format" name="format">
|
||||||
<option disabled>Video Formats</option>
|
<option disabled>Video Formats</option>
|
||||||
|
@ -42,8 +42,10 @@
|
||||||
<option value="avi">.avi</option>
|
<option value="avi">.avi</option>
|
||||||
<option disabled>Audio Formats</option>
|
<option disabled>Audio Formats</option>
|
||||||
<option value="mp3" selected>.mp3</option>
|
<option value="mp3" selected>.mp3</option>
|
||||||
|
<option value="wav">.wav</option>
|
||||||
|
<option value="opus">.ogx</option>
|
||||||
</select>
|
</select>
|
||||||
<br>
|
<!-- <br> -->
|
||||||
<!-- <input style="display: inline-block" type="checkbox" id="adv"> -->
|
<!-- <input style="display: inline-block" type="checkbox" id="adv"> -->
|
||||||
<!-- <p style="display: inline-block" for="adv">Enable Advanced options? (Beta)</p> -->
|
<!-- <p style="display: inline-block" for="adv">Enable Advanced options? (Beta)</p> -->
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue