From 431767437dd50be686ef75a790bd7e76c282d932 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Mon, 5 Apr 2021 01:24:55 +1200 Subject: [PATCH] Support NewLeaf's auto-captions --- api/captions.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/api/captions.js b/api/captions.js index 859ced4..29611ef 100644 --- a/api/captions.js +++ b/api/captions.js @@ -1,13 +1,25 @@ +const fetch = require("node-fetch") 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()) + 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 + } + }) + }) } } ]