Fix non ogx formats

This commit is contained in:
Bingus_Violet 2024-02-01 18:54:38 -06:00
parent f236ecb9dd
commit ad1d3996b9
2 changed files with 12 additions and 20 deletions

View file

@ -14,6 +14,8 @@ var formats = {
"mkv": "matroska" "mkv": "matroska"
} }
var fastFormats = ["mp4", "mkv", "mp3", "wav"]
app.get("/convert", async (req, res) => { app.get("/convert", async (req, res) => {
var file = req.query.file || "" var file = req.query.file || ""
var format = req.query.format var format = req.query.format
@ -26,17 +28,6 @@ app.get("/convert", async (req, res) => {
var name = ytdlpProcess.stdout.toString() var name = ytdlpProcess.stdout.toString()
name = name.substring(0, name.lastIndexOf("[") - 1) name = name.substring(0, name.lastIndexOf("[") - 1)
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(name)}.${format}"`); res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(name)}.${format}"`);
const ffmpegProcess = cp.spawn(ffmpeg, [
'-i', filePath,
'-f', formats[format] || format,
'-movflags', 'frag_keyframe+empty_moov',
'-c', 'copy',
'-'
], {
stdio: [
'pipe', 'pipe', 'pipe', 'pipe', 'pipe',
],
})
// ffmpegProcess.stderr.setEncoding('utf-8') // ffmpegProcess.stderr.setEncoding('utf-8')
// ffmpegProcess.stderr.on('data', (data) => { // ffmpegProcess.stderr.on('data', (data) => {
@ -140,7 +131,7 @@ app.get("/download", async (req, res) => {
} }
exited = true exited = true
}) })
} else if (["mp3", "wav", "ogx"].includes(format)) { } else if (["mp3", "wav", "opus"].includes(format)) {
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(videoName)}.${format}"`); res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(videoName)}.${format}"`);
var ytdlpProcess = cp.spawn('yt-dlp', [ var ytdlpProcess = cp.spawn('yt-dlp', [
@ -156,7 +147,6 @@ app.get("/download", async (req, res) => {
'-i', 'pipe:3', '-i', 'pipe:3',
'-f', formats[format] || format, '-f', formats[format] || format,
'-movflags', 'frag_keyframe+empty_moov', '-movflags', 'frag_keyframe+empty_moov',
'-c:a', 'libmp3lame',
'-preset','ultrafast', '-preset','ultrafast',
'-crf', '23', '-crf', '23',
'-loglevel', 'error', '-loglevel', 'error',
@ -213,6 +203,14 @@ app.get("/download", async (req, res) => {
}) })
process.on('uncaughtException', (err, origin) => {
fs.writeSync(
process.stderr.fd,
`Caught exception: ${err}\n` +
`Exception origin: ${origin}`,
);
});
app.use(express.static(path.join(__dirname, 'static'))) app.use(express.static(path.join(__dirname, 'static')))
app.listen(PORT, function () { app.listen(PORT, function () {

View file

@ -46,6 +46,7 @@
<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="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"> -->
@ -56,14 +57,7 @@
</form> </form>
<br> <br>
<p>Univerter was designed for youtube, but if you need something different please consult <a target="_blank" href="https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md">this list</a> to see if your site is there. Be warned, though, they are mostly untested!</p> <p>Univerter was designed for youtube, but if you need something different please consult <a target="_blank" href="https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md">this list</a> to see if your site is there. Be warned, though, they are mostly untested!</p>
<p>Notable supported sites include:</p>
<ul>
<li>Youtube</li>
<li>Twitter</li>
<li>TikTok</li>
</ul>
<p>For a full list of things that have been tested you can find them <a href="./supported">here</a></p> <p>For a full list of things that have been tested you can find them <a href="./supported">here</a></p>
<hr>
<p><a target="_blank" href="https://ko-fi.com/bingus_violet">Please consider donating</a> or host the website yourself! Anything <p><a target="_blank" href="https://ko-fi.com/bingus_violet">Please consider donating</a> or host the website yourself! Anything
helps! (Check <a href="https://codeberg.org/Bingus_Violet/Univerter">Codeberg</a> for more info)</p> helps! (Check <a href="https://codeberg.org/Bingus_Violet/Univerter">Codeberg</a> for more info)</p>
<p> <p>