Bettered
This commit is contained in:
parent
b6de202102
commit
94824f020a
5 changed files with 35 additions and 9 deletions
36
index.js
36
index.js
|
@ -23,7 +23,22 @@ const playerPath = path.join(resources, 'player.html')
|
||||||
const searchPath = path.join(resources, 'searchPage.html')
|
const searchPath = path.join(resources, 'searchPage.html')
|
||||||
const channelPath = path.join(resources, 'channelPage.html')
|
const channelPath = path.join(resources, 'channelPage.html')
|
||||||
|
|
||||||
const cssHeader = `<link rel="stylesheet" href="/mainStyle.css">`
|
const cssHeader = `<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"
|
||||||
|
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
|
||||||
|
<link rel="stylesheet" href="/mainStyle.css">`
|
||||||
|
|
||||||
|
const topBar = `
|
||||||
|
<div id="titleBar" class="row container-fluid">
|
||||||
|
<div class="col-6">
|
||||||
|
<h1><a href="/">SimpleTube</a></h1>
|
||||||
|
</div>
|
||||||
|
<div class="col-6">
|
||||||
|
<form action="/search">
|
||||||
|
<input type="text" placeholder="Search" name="q">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
|
||||||
|
|
||||||
if (fs.existsSync(cachePath)) {
|
if (fs.existsSync(cachePath)) {
|
||||||
|
@ -88,7 +103,7 @@ async function cacher(id, quality, ready) {
|
||||||
var video = ytdl(id, { filter: 'videoandaudio', quality: "highest", format: 'mp4' })
|
var video = ytdl(id, { filter: 'videoandaudio', quality: "highest", format: 'mp4' })
|
||||||
.on("progress", (chunk, ct, et) => {
|
.on("progress", (chunk, ct, et) => {
|
||||||
|
|
||||||
if (debounce && (ct / et) > 0.015) {
|
if (debounce && (ct / et) > 0.1) {
|
||||||
debounce = false
|
debounce = false
|
||||||
videoCache[id + quality] = {
|
videoCache[id + quality] = {
|
||||||
"path": vidpath,
|
"path": vidpath,
|
||||||
|
@ -450,13 +465,24 @@ app.get("/watch", async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ytdl.validateID(id)) {
|
if (!ytdl.validateID(id)) {
|
||||||
res.setHeader("Content-Type", "text/html")
|
res.write(cssHeader)
|
||||||
res.write("Not a valid video id or url!")
|
res.write(topBar)
|
||||||
|
res.write("<h2>Not a valid video id or url!</h2>")
|
||||||
res.end()
|
res.end()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
var vidInfo = (await ytdl.getBasicInfo(id)).videoDetails
|
||||||
|
} catch (error) {
|
||||||
|
res.write(cssHeader)
|
||||||
|
res.write(topBar)
|
||||||
|
res.write("<h2>Failed to get video info! This likely means the video is age restricted, or deleted.</h2>", () => {res.end()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var vidInfo = (await ytdl.getBasicInfo(id)).videoDetails
|
|
||||||
|
|
||||||
var html = fs.readFileSync(playerPath).toString()
|
var html = fs.readFileSync(playerPath).toString()
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="titleBar" class="row container-fluid">
|
<div id="titleBar" class="row container-fluid">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<h1><a href="/">Simpletube</a></h1>
|
<h1><a href="/">SimpleTube</a></h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<form action="/search">
|
<form action="/search">
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="titleBar" class="row container-fluid">
|
<div id="titleBar" class="row container-fluid">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<h1><a href="/">Simpletube</a></h1>
|
<h1><a href="/">SimpleTube</a></h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<form action="/search">
|
<form action="/search">
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="titleBar" class="row container-fluid">
|
<div id="titleBar" class="row container-fluid">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<h1><a href="/">Simpletube</a></h1>
|
<h1><a href="/">SimpleTube</a></h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<form action="/search">
|
<form action="/search">
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="titleBar" class="row container-fluid">
|
<div id="titleBar" class="row container-fluid">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<h1><a href="/">Simpletube</a></h1>
|
<h1><a href="/">SimpleTube</a></h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<form action="/search">
|
<form action="/search">
|
||||||
|
|
Loading…
Reference in a new issue