Fixed bug, more audio format

This commit is contained in:
Bingus_Violet 2024-01-17 20:39:08 -06:00
parent 7ecff6e95d
commit ac4e2ad160
2 changed files with 35 additions and 19 deletions

View file

@ -31,10 +31,10 @@ app.get("/convert", async (req, res) => {
],
})
// ffmpegProcess.stderr.setEncoding('utf-8')
// ffmpegProcess.stderr.on('data', (data) => {
// console.log(data)
// })
ffmpegProcess.stderr.setEncoding('utf-8')
ffmpegProcess.stderr.on('data', (data) => {
console.log(data)
})
// These are debugging lines to watch FFMPEG output :3
ffmpegProcess.stdio[1].pipe(res)
@ -58,14 +58,15 @@ app.get("/download", async (req, res) => {
res.write(downloadHTML.substring(0, downloadHTML.indexOf("{CONTENT}")))
if (!format in ["mp3"]) {
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)
var ytdlpProcess = cp.spawn('yt-dlp', [
url,
'-o', filePath,
'--max-filesize', MAX_FILESIZE + 'm'
'--max-filesize', MAX_FILESIZE + 'm',
'-S', 'res:' + quality
])
} else {
var fileName = Math.round(Math.random() * 100_000_000_000_000).toString()
@ -75,7 +76,6 @@ app.get("/download", async (req, res) => {
'-x',
'-o', filePath,
'--max-filesize', MAX_FILESIZE + 'm',
])
fileName += '.opus'
filePath = path.join(__dirname, 'downloads', fileName)
@ -108,8 +108,15 @@ app.get("/download", async (req, res) => {
})
var exited = false
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(downloadHTML.substring(downloadHTML.indexOf("{CONTENT}") + 9), () => {res.end()})
} 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')))

View file

@ -22,17 +22,17 @@
<input required type="url" id="url" placeholder="Enter url" name="url" style="width: 80vw; max-width: 550px">
<p>Quality:</p>
<!-- <select required id="quality" name="quality">
<option value="highest">Highest</option>
<option value="lowest">Lowest</option>
</select> -->
<select required id="definition" name="definition">
<option value="hd">HD (High Definition)</option>
<option value="sd">SD (Standard Definition)</option>
<select required id="quality" name="quality">
<option value="144">144p</option>
<option value="240">240p</option>
<option value="360">360p</option>
<option value="480">480p</option>
<option value="720" selected>720p</option>
<option value="1080">1080p</option>
<option value="1440">1440p</option>
<option value="2160">2160p (4k)</option>
</select>
<p>Format:</p>
<select required id="format" name="format">
<option disabled>Video Formats</option>
@ -42,8 +42,10 @@
<option value="avi">.avi</option>
<option disabled>Audio Formats</option>
<option value="mp3" selected>.mp3</option>
<option value="wav">.wav</option>
<option value="opus">.ogx</option>
</select>
<br>
<!-- <br> -->
<!-- <input style="display: inline-block" type="checkbox" id="adv"> -->
<!-- <p style="display: inline-block" for="adv">Enable Advanced options? (Beta)</p> -->