---
api/captions.js | 19 +++++++++++++++++++
pug/video.pug | 2 ++
2 files changed, 21 insertions(+)
create mode 100644 api/captions.js
diff --git a/api/captions.js b/api/captions.js
new file mode 100644
index 0000000..d23272c
--- /dev/null
+++ b/api/captions.js
@@ -0,0 +1,19 @@
+const fetch = require("node-fetch")
+const {getUser} = require("../utils/getuser")
+const constants = require("../utils/constants")
+
+module.exports = [
+ {
+ route: `/api/v1/captions/(${constants.regex.video_id})`, methods: ["GET"], code: async ({req, fill, url}) => {
+ const instanceOrigin = getUser(req).getSettingsOrDefaults().instance
+ const videoID = fill[0]
+ const lang = url.searchParams.get("lang")
+ return fetch(`${instanceOrigin}/api/v1/captions/${videoID}?lang=${lang}`).then(res => {
+ return {
+ statusCode: 200,
+ stream: res.body
+ }
+ })
+ }
+ }
+]
diff --git a/pug/video.pug b/pug/video.pug
index 2b09e10..eef398e 100644
--- a/pug/video.pug
+++ b/pug/video.pug
@@ -23,6 +23,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 c in video.captions
+ track(label=c.label kind="subtitles" srclang=c.languageCode src=c.url)
else
video(src="")#video.video
.stream-notice The server provided no playback streams.
--
2.20.1
Thanks so much for this! Tomorrow I can properly review it, but taking a
peek at the code now, there's a couple of things that stand out to me:
- kind should be `captions` since it is a transcription of audio, not a
translation; see
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track
- should put the result of `getSettingsOrDefaults` in a variable to make
it easier to extract other settings in the future
- should validate the `lang` query parameter somehow
I can deal with these notes on my own tomorrow, as well as doing my full
review, but if you want make these changes yourself, you're free to
submit an updated patch.