2021-04-04 13:24:55 +00:00
|
|
|
const fetch = require("node-fetch")
|
2021-03-28 22:11:49 +00:00
|
|
|
const {getUser} = require("../utils/getuser")
|
|
|
|
const constants = require("../utils/constants.js")
|
|
|
|
|
|
|
|
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)
|
2021-04-04 13:24:55 +00:00
|
|
|
return fetch(fetchURL.toString()).then(res => {
|
|
|
|
return res.text().then(text => {
|
|
|
|
if (res.status === 200) {
|
|
|
|
// Remove the position annotations that youtube unhelpfully provides
|
|
|
|
text = text.replace(/(--> \S+).*/g, "$1")
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
statusCode: res.status,
|
|
|
|
contentType: res.headers.get("content-type"),
|
|
|
|
content: text
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2021-03-28 22:11:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|