From 500aa820bce5d3439c57391e93e2fcfa29e318c1 Mon Sep 17 00:00:00 2001 From: Lomanic Date: Mon, 29 Mar 2021 00:11:49 +0200 Subject: [PATCH] Implement video captions Proxy requests to NewLeaf/Invidious backend so captions are served on the same domain --- api/captions.js | 13 +++++++++++++ pug/video.pug | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 api/captions.js diff --git a/api/captions.js b/api/captions.js new file mode 100644 index 0000000..859ced4 --- /dev/null +++ b/api/captions.js @@ -0,0 +1,13 @@ +const {getUser} = require("../utils/getuser") +const constants = require("../utils/constants.js") +const {proxy} = require("pinski/plugins") + +module.exports = [ + { + route: `/api/v1/captions/(${constants.regex.video_id})`, methods: ["GET"], code: async ({req, fill, url}) => { + const instanceOrigin = getUser(req).getSettingsOrDefaults().instance + const fetchURL = new URL(`${url.pathname}${url.search}`, instanceOrigin) + return proxy(fetchURL.toString()) + } + } +] diff --git a/pug/video.pug b/pug/video.pug index 7eb8ed0..abb4a8e 100644 --- a/pug/video.pug +++ b/pug/video.pug @@ -20,6 +20,8 @@ block content if format video(controls preload="auto" width=format.second__width height=format.second__height data-itag=format.itag)#video.video source(src=format.url+mediaFragment type=format.type) + each t in video.captions + track(label=t.label kind="subtitles" srclang=t.languageCode src=t.url) else video(src="")#video.video .stream-notice The server provided no playback streams.