Compare commits
No commits in common. "4f2286d122439de9edb94918f223a1f04b4fb535" and "fc44466340a4a0ab06dd93f5355d5c43e42cdadc" have entirely different histories.
4f2286d122
...
fc44466340
2 changed files with 31 additions and 1 deletions
29
index.js
29
index.js
|
@ -72,6 +72,35 @@ app.get("/watch/*", (req, res) => {
|
||||||
res.send(html)
|
res.send(html)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.get("/video/*", (req, res) => {
|
||||||
|
var video = req.params[0]
|
||||||
|
var vidPath = path.join(directory, video)
|
||||||
|
|
||||||
|
if (!fs.existsSync(vidPath)) {
|
||||||
|
vidPath = path.join(pubDir, video)
|
||||||
|
}
|
||||||
|
|
||||||
|
const range = req.headers.range
|
||||||
|
const videoPath = vidPath;
|
||||||
|
const videoSize = fs.statSync(videoPath).size
|
||||||
|
const chunkSize = 1 * 1e6;
|
||||||
|
const start = Number(range.replace(/\D/g, ""))
|
||||||
|
const end = Math.min(start + chunkSize, videoSize - 1)
|
||||||
|
const contentLength = end - start + 1;
|
||||||
|
const headers = {
|
||||||
|
"Content-Range": `bytes ${start}-${end}/${videoSize}`,
|
||||||
|
"Accept-Ranges": "bytes",
|
||||||
|
"Content-Length": contentLength,
|
||||||
|
"Content-Type": "video/mkv"
|
||||||
|
}
|
||||||
|
res.writeHead(206, headers)
|
||||||
|
const stream = fs.createReadStream(videoPath, {
|
||||||
|
start,
|
||||||
|
end
|
||||||
|
})
|
||||||
|
stream.pipe(res)
|
||||||
|
})
|
||||||
|
|
||||||
app.get("/download/*", (req, res) => {
|
app.get("/download/*", (req, res) => {
|
||||||
var download = req.params[0]
|
var download = req.params[0]
|
||||||
var downloadPath = path.join(directory, download)
|
var downloadPath = path.join(directory, download)
|
||||||
|
|
|
@ -27,8 +27,9 @@
|
||||||
<p><a href="{BACK}">Back</a></p>
|
<p><a href="{BACK}">Back</a></p>
|
||||||
<p>{VID_INFO}</p>
|
<p>{VID_INFO}</p>
|
||||||
<p><a href="/download/{VID_PATH}">Download</a>
|
<p><a href="/download/{VID_PATH}">Download</a>
|
||||||
|
<br><a href="/{VID_PATH}">Compatibility Video player</a></p>
|
||||||
<div class="fadediv">
|
<div class="fadediv">
|
||||||
<video src="/{VID_PATH}" width="100%" controls></video>
|
<video src="/video/{VID_PATH}" width="100%" controls></video>
|
||||||
</div>
|
</div>
|
||||||
<p class="note">Please note that the video player is unfinished, most commonly having issues on iOS devices.</p>
|
<p class="note">Please note that the video player is unfinished, most commonly having issues on iOS devices.</p>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue