HD & search fixes! Improved Chromium experience.
This commit is contained in:
parent
94824f020a
commit
540d02af2f
1 changed files with 73 additions and 64 deletions
137
index.js
137
index.js
|
@ -61,6 +61,53 @@ app.listen(PORT, () => {
|
||||||
console.log("Simpletube is now listening on port: " + PORT)
|
console.log("Simpletube is now listening on port: " + PORT)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function resultHTML(result) {
|
||||||
|
|
||||||
|
console.log(result)
|
||||||
|
|
||||||
|
function thumbnailCheck() {
|
||||||
|
if (result.thumbnails) {
|
||||||
|
return result.thumbnails[0].url
|
||||||
|
} else {
|
||||||
|
return result.thumbnail
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function publishCheck() {
|
||||||
|
if (result.published) {
|
||||||
|
return result.published.text
|
||||||
|
} else {
|
||||||
|
return result.uploaded
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div class="col-xxl-4 col-sm-6 resultContainer">
|
||||||
|
<div class="videoResult container-fluid row">
|
||||||
|
<div class="col-lg-6 thumbparent">
|
||||||
|
<a class="videoLink" href="/watch?v=${result.id}">
|
||||||
|
<img class="thumbnail" src="${thumbnailCheck()}">
|
||||||
|
<p style="display: block; text-align: left;">${result.duration.pretty || result.durationString}</p>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<a class="videoLink" href="/watch?v=${result.id}">
|
||||||
|
<p style="font-size: 1.25rem;">${result.title || "No Title Found"}</p>
|
||||||
|
<p class="resultDescription">${(result.description || result.views.text).substring(0, 125) || "No Description"}</p>
|
||||||
|
<p style="display: block;">${publishCheck()}</p>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div style="display: inline-block; width: 100%;">
|
||||||
|
<a style="color: white; margin: 10px; display: inline-block;" href="/channel?q=${result.channel.id}">
|
||||||
|
<img src="${result.channel.thumbnail}" class="minipfp">
|
||||||
|
${result.channel.name}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
function msth(ms) {
|
function msth(ms) {
|
||||||
var x = ms / 1000
|
var x = ms / 1000
|
||||||
var seconds = Math.floor(x % 60)
|
var seconds = Math.floor(x % 60)
|
||||||
|
@ -117,13 +164,16 @@ async function cacher(id, quality, ready) {
|
||||||
ready(vidpath, fs.readFileSync(vidpath))
|
ready(vidpath, fs.readFileSync(vidpath))
|
||||||
}
|
}
|
||||||
var percent = Math.round(ct / et * 100)
|
var percent = Math.round(ct / et * 100)
|
||||||
|
if (!debounce) {
|
||||||
|
videoCache[id + quality]["download%"] = percent
|
||||||
|
}
|
||||||
if (!debounce && percent > dp && id in videoCache && "path" in videoCache[id]) {
|
if (!debounce && percent > dp && id in videoCache && "path" in videoCache[id]) {
|
||||||
dp = percent
|
dp = percent
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on("finish", () => {
|
.on("finish", () => {
|
||||||
if (id in videoCache) {
|
if ((id + quality) in videoCache) {
|
||||||
videoCache[id]["downloaded"] = true
|
videoCache[id + quality]["downloaded"] = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
video.pipe(fs.createWriteStream(vidpath))
|
video.pipe(fs.createWriteStream(vidpath))
|
||||||
|
@ -176,6 +226,8 @@ async function cacher(id, quality, ready) {
|
||||||
debounce = true
|
debounce = true
|
||||||
start(et)
|
start(et)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
videoCache[id + quality]["download%"] = Math.round(ct / et * 100)
|
||||||
})
|
})
|
||||||
|
|
||||||
video.pipe(ffmpegProcess.stdio[3])
|
video.pipe(ffmpegProcess.stdio[3])
|
||||||
|
@ -243,31 +295,7 @@ app.get("/search", async (req, res) => {
|
||||||
|
|
||||||
for (let index = 0; index < videos.length; index++) {
|
for (let index = 0; index < videos.length; index++) {
|
||||||
const result = videos[index];
|
const result = videos[index];
|
||||||
addedHTML += `
|
addedHTML += resultHTML(result)
|
||||||
<div class="col-xxl-4 col-sm-6 resultContainer">
|
|
||||||
<div class="videoResult container-fluid row">
|
|
||||||
<div class="col-lg-6 thumbparent">
|
|
||||||
<a class="videoLink" href="/watch?v=${result.id}">
|
|
||||||
<img class="thumbnail" src="${result.thumbnail}">
|
|
||||||
<p style="display: block; text-align: left;">${result.durationString}</p>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-6">
|
|
||||||
<a class="videoLink" href="/watch?v=${result.id}">
|
|
||||||
<p style="font-size: 1.25rem;">${result.title || "No Title Found"}</p>
|
|
||||||
<p class="resultDescription">${result.description.substring(0, 125) + "..." || "No Description"}</p>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style="display: inline-block; width: 100%;">
|
|
||||||
<a style="color: white; margin: 10px; display: inline-block;" href="/channel?q=${result.channel.id}">
|
|
||||||
<img src="${result.channel.thumbnail}" class="minipfp">
|
|
||||||
${result.channel.name}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (addedHTML == "") {
|
if (addedHTML == "") {
|
||||||
|
@ -314,24 +342,7 @@ app.get("/channel", async (req, res) => {
|
||||||
for (let index = 0; index < videos.length; index++) {
|
for (let index = 0; index < videos.length; index++) {
|
||||||
const result = videos[index];
|
const result = videos[index];
|
||||||
if (result.title != undefined) {
|
if (result.title != undefined) {
|
||||||
addedHTML += `
|
addedHTML += resultHTML(result)
|
||||||
<div class="col-xxl-4 col-sm-6 resultContainer">
|
|
||||||
<div class="videoResult container-fluid row">
|
|
||||||
<div class="col-lg-6 thumbparent">
|
|
||||||
<a class="videoLink" href="/watch?v=${result.id}">
|
|
||||||
<img class="thumbnail" src="${result.thumbnails[0].url}">
|
|
||||||
<p style="display: block; text-align: left;">${result.duration.pretty}</p>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-6">
|
|
||||||
<a class="videoLink" href="/watch?v=${result.id}">
|
|
||||||
<p style="font-size: 1.25rem;">${result.title || "No Title Found"}</p>
|
|
||||||
<p style="display: block;">${result.published.text}</p>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
} else {
|
} else {
|
||||||
addedHTML = "<p>Failed to load.</p>"
|
addedHTML = "<p>Failed to load.</p>"
|
||||||
}
|
}
|
||||||
|
@ -389,7 +400,9 @@ app.get("/video", async (req, res) => {
|
||||||
if (range) {
|
if (range) {
|
||||||
function ready(vidpath) {
|
function ready(vidpath) {
|
||||||
if (fs.existsSync(vidpath)) {
|
if (fs.existsSync(vidpath)) {
|
||||||
const fileSize = videoCache[id].size
|
// const fileSize = videoCache[id].size
|
||||||
|
const fileSize = fs.statSync(vidpath).size
|
||||||
|
console.log(fileSize, vidpath)
|
||||||
const parts = range.replace(/bytes=/, "").split("-")
|
const parts = range.replace(/bytes=/, "").split("-")
|
||||||
const start = parseInt(parts[0], 10)
|
const start = parseInt(parts[0], 10)
|
||||||
const end = parts[1]
|
const end = parts[1]
|
||||||
|
@ -411,9 +424,7 @@ app.get("/video", async (req, res) => {
|
||||||
|
|
||||||
res.writeHead(206, head)
|
res.writeHead(206, head)
|
||||||
|
|
||||||
if (fs.existsSync(vidpath)) {
|
fs.createReadStream(vidpath, { start: start, end: end }).pipe(res)
|
||||||
fs.createReadStream(vidpath, { start: start }).pipe(res)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,7 +435,7 @@ app.get("/video", async (req, res) => {
|
||||||
videoCache[id].lastUsed = Date.now()
|
videoCache[id].lastUsed = Date.now()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
videoCache[id] = []
|
videoCache[id + quality] = []
|
||||||
cacher(id, quality, ready)
|
cacher(id, quality, ready)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,7 +467,7 @@ app.get("/video", async (req, res) => {
|
||||||
|
|
||||||
app.get("/watch", async (req, res) => {
|
app.get("/watch", async (req, res) => {
|
||||||
var id = req.query.q || req.query.v || "ubFq-wV3Eic"
|
var id = req.query.q || req.query.v || "ubFq-wV3Eic"
|
||||||
var quality = req.query.quality || "sd"
|
var quality = req.query.quality || "hd"
|
||||||
|
|
||||||
res.setHeader("Content-Type", "text/html")
|
res.setHeader("Content-Type", "text/html")
|
||||||
|
|
||||||
|
@ -482,8 +493,6 @@ app.get("/watch", async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var html = fs.readFileSync(playerPath).toString()
|
var html = fs.readFileSync(playerPath).toString()
|
||||||
|
|
||||||
if (quality == "sd") {
|
if (quality == "sd") {
|
||||||
|
@ -508,14 +517,14 @@ app.get("/watch", async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
html = html.replace("{VIDEO_DESCRIPTION}", vidInfo.description || "No Description.")
|
html = html.replace("{VIDEO_DESCRIPTION}", vidInfo.description || "No Description.")
|
||||||
|
console.log(videoCache)
|
||||||
if (!(id in videoCache && videoCache[id]["downloaded"] == true)) {
|
if (!((id + quality) in videoCache && videoCache[id + quality].downloaded == true)) {
|
||||||
html = html.replace("{CACHE_WARNING}", `
|
html = html.replace("{CACHE_WARNING}", `
|
||||||
<p style="color: lightgray">Please note that this video has not been fully cached, and may have trouble loading!
|
<p style="color: lightgray">Please note that this video has not been fully cached, and may have trouble loading!
|
||||||
<br>{DOWNLOAD_PERCENT}% cached as of page load. If content fails to load after a minute, reload the page!</p>
|
<br>{DOWNLOAD_PERCENT}% cached as of page load. If content fails to load after a minute, reload the page!</p>
|
||||||
`)
|
`)
|
||||||
if (id in videoCache && "download%" in videoCache[id]) {
|
if ((id + quality) in videoCache && "download%" in videoCache[id + quality]) {
|
||||||
html = html.replace("{DOWNLOAD_PERCENT}", videoCache[id]["download%"])
|
html = html.replace("{DOWNLOAD_PERCENT}", videoCache[id + quality]["download%"])
|
||||||
} else {
|
} else {
|
||||||
html = html.replace("{DOWNLOAD_PERCENT}", "0")
|
html = html.replace("{DOWNLOAD_PERCENT}", "0")
|
||||||
}
|
}
|
||||||
|
@ -529,10 +538,10 @@ app.get("/watch", async (req, res) => {
|
||||||
res.send(html)
|
res.send(html)
|
||||||
})
|
})
|
||||||
|
|
||||||
process.on('uncaughtException', (err, origin) => {
|
// process.on('uncaughtException', (err, origin) => {
|
||||||
fs.writeSync(
|
// fs.writeSync(
|
||||||
process.stderr.fd,
|
// process.stderr.fd,
|
||||||
`Caught exception: ${err}\n` +
|
// `Caught exception: ${err}\n` +
|
||||||
`Exception origin: ${origin}`,
|
// `Exception origin: ${origin}`,
|
||||||
);
|
// );
|
||||||
});
|
// });
|
Loading…
Reference in a new issue