This commit is contained in:
Bingus_Violet 2023-11-28 04:39:06 +00:00
parent 540d02af2f
commit 91eea373ea
3 changed files with 40 additions and 17 deletions

View file

@ -227,7 +227,8 @@ async function cacher(id, quality, ready) {
start(et)
}
videoCache[id + quality]["download%"] = Math.round(ct / et * 100)
videoCache[id + quality]["download%"] = Math.round(fs.statSync(vidpath).size / (et) * 100)
// console.log(Math.round(fs.statSync(vidpath).size / (et * 2) * 100))
})
video.pipe(ffmpegProcess.stdio[3])
@ -250,6 +251,20 @@ async function cacher(id, quality, ready) {
}
app.get("/", async (req, res) => {
var html = fs.readFileSync('resources/mainPage.html').toString()
res.send(html.substring(0, html.indexOf("{RESULTS}")))
youtube.search(" ", { type: "videos" })
.then((results) => {
addedHTML += "<h2><br>Videos:</h2>"
for (let index = 0; index < videos.length; index++) {
const result = videos[index];
addedHTML += resultHTML(result)
}
})
})
app.get("/search", async (req, res) => {
var search = req.query.q || "How to search on SimpleTube"
res.setHeader("Content-Type", "text/html")
@ -399,10 +414,8 @@ app.get("/video", async (req, res) => {
if (range) {
function ready(vidpath) {
if (fs.existsSync(vidpath)) {
// const fileSize = videoCache[id].size
if (fs.existsSync(vidpath) && fs.statSync(vidpath).size > 1) {
const fileSize = fs.statSync(vidpath).size
console.log(fileSize, vidpath)
const parts = range.replace(/bytes=/, "").split("-")
const start = parseInt(parts[0], 10)
const end = parts[1]
@ -424,7 +437,11 @@ app.get("/video", async (req, res) => {
res.writeHead(206, head)
fs.createReadStream(vidpath, { start: start, end: end }).pipe(res)
if (end == -1) {
fs.createReadStream(vidpath, { start: start }).pipe(res)
} else {
fs.createReadStream(vidpath, { start: start, end: end }).pipe(res)
}
}
}
@ -538,10 +555,10 @@ app.get("/watch", async (req, res) => {
res.send(html)
})
// process.on('uncaughtException', (err, origin) => {
// fs.writeSync(
// process.stderr.fd,
// `Caught exception: ${err}\n` +
// `Exception origin: ${origin}`,
// );
// });
process.on('uncaughtException', (err, origin) => {
fs.writeSync(
process.stderr.fd,
`Caught exception: ${err}\n` +
`Exception origin: ${origin}`,
);
});

5
meta.txt Normal file
View file

@ -0,0 +1,5 @@
;FFMETADATA1
major_brand=isom
minor_version=512
compatible_brands=isomiso6iso2avc1mp41
encoder=Lavf58.45.100

View file

@ -25,11 +25,12 @@
</div>
<main>
<h1>Welcome to SimpleTube</h1>
<p>SimpleTube is a Youtube client that aims to be free and fast. (and have no ads!)
<br>
Currently SimpleTube does not have a trending tab or anything, so please use the search function at the top!
<br>
(Sorry!)</p>
<p>SimpleTube is a Youtube client that aims to be free, fast, and javascript free. (and has no ads!) </p>
<div class="row container-fluid">
{RESULTS}
</div>
<h2>More about the project: <br></h2>
<p>
<a href="https://codeberg.org/Bingus_Violet/SimpleTube">Find this project on codeberg!</a>