Play in browser now works with chromium
This commit is contained in:
parent
a949591f99
commit
4f88beab0a
5 changed files with 564 additions and 266 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue