Play in browser now works with chromium

This commit is contained in:
bingus_violet 2024-11-06 19:34:05 -06:00
parent a949591f99
commit 4f88beab0a
5 changed files with 564 additions and 266 deletions

View file

@ -20,21 +20,33 @@ var audioFormats = [
"mp3"
]
expressManager.app.get("/watch", async (req, res) => {
var html = fs.readFileSync(path.join(__dirname, "resources/playInBrowser.html")).toString()
var finalMetadata = "?"
for (var i in req.query) {
if (i != "playInBrowser") {
finalMetadata += i + "=" + req.query[i] + "&"
}
}
html = html.replaceAll("{DOWNLOAD_URL}", finalMetadata)
res.send(html)
})
expressManager.app.get("/download", async (req, res) => {
var url = req.query.url,
quality = req.query.quality,
format = req.query.format,
trimAudio = req.query.trimAudio && audioFormats.includes(format) || false
if (ytdl.validateURL(url) && qualityLabels.includes(quality)) {
if (req.query.playInBrowser) {
var metadata = req.url.substring(req.url.indexOf("?"))
res.redirect("/watch" + metadata)
} else if (ytdl.validateURL(url) && qualityLabels.includes(quality)) {
var needsVideo = !audioFormats.includes(format)
var info = await ytdl.getInfo(url)
var downloadType = "attachment"
if (req.query.playInBrowser) downloadType = "inline";
res.setHeader("Content-Disposition", `${downloadType}; filename="${info.videoDetails.title.replace(/[^a-z0-9 ]/gi, '')}.${format}"`)
res.setHeader("Content-Disposition", `attachment; filename="${info.videoDetails.title.replace(/[^a-z0-9 ]/gi, '')}.${format}"`)
var audioFormat = ytdl.chooseFormat(info.formats, { filter: (format) => {
return format.hasAudio && !format.hasVideo

772
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -23,7 +23,7 @@
},
"homepage": "https://github.com/Violets-puragtory/YoutubeConverter#readme",
"dependencies": {
"@distube/ytdl-core": "^4.14.4",
"@distube/ytdl-core": "^4.15.1",
"child_process": "^1.0.2",
"express": "^4.18.2",
"ffmpeg-static": "^5.2.0"

View file

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/style.css">
<style>
* {
margin: auto;
padding: 0 !important;
}
body {
width: 100vw;
max-width: 100vw;
padding: 0;
background-color: black;
}
video {
width: 100vw;
max-width: 100%;
max-height: 100%;
}
</style>
<title>Playing video in browser</title>
</head>
<body>
<video controls src="/download{DOWNLOAD_URL}"></video>
</body>
</html>

View file

@ -17,8 +17,10 @@ $(document).ready(() => {
$("#quality").val(Cookies.get("quality") || "720")
$("#trim").prop("checked", Cookies.get("trim") == "true" || false)
$("#playInBrowser").prop("checked", Cookies.get("playInBrowser") == "true" || false)
$("form").submit(() => {
Cookies.set("quality", $("#quality").val())
Cookies.set("trim", $("#trim").prop("checked"))
Cookies.set("playInBrowser", $("#playInBrowser").prop("checked"))
})
})