1
0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2024-11-22 15:47:30 +00:00

Support NewLeaf's auto-captions

This commit is contained in:
Cadence Ember 2021-04-05 01:24:55 +12:00
parent 500aa820bc
commit 431767437d
No known key found for this signature in database
GPG Key ID: BC1C2C61CF521B17

View File

@ -1,13 +1,25 @@
const fetch = require("node-fetch")
const {getUser} = require("../utils/getuser") const {getUser} = require("../utils/getuser")
const constants = require("../utils/constants.js") const constants = require("../utils/constants.js")
const {proxy} = require("pinski/plugins")
module.exports = [ module.exports = [
{ {
route: `/api/v1/captions/(${constants.regex.video_id})`, methods: ["GET"], code: async ({req, fill, url}) => { route: `/api/v1/captions/(${constants.regex.video_id})`, methods: ["GET"], code: async ({req, fill, url}) => {
const instanceOrigin = getUser(req).getSettingsOrDefaults().instance const instanceOrigin = getUser(req).getSettingsOrDefaults().instance
const fetchURL = new URL(`${url.pathname}${url.search}`, instanceOrigin) const fetchURL = new URL(`${url.pathname}${url.search}`, instanceOrigin)
return proxy(fetchURL.toString()) 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
}
})
})
} }
} }
] ]