diff --git a/index.js b/index.js index b91fe48..768ef66 100644 --- a/index.js +++ b/index.js @@ -72,6 +72,35 @@ app.get("/watch/*", (req, res) => { 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) => { var download = req.params[0] var downloadPath = path.join(directory, download) diff --git a/resources/watch.html b/resources/watch.html index 6afb6e3..f70262d 100644 --- a/resources/watch.html +++ b/resources/watch.html @@ -27,8 +27,9 @@
{VID_INFO}
Download
+
Compatibility Video player
Please note that the video player is unfinished, most commonly having issues on iOS devices.