From 6d18dff5ccbf0d4789e8343d2768eb939178abc2 Mon Sep 17 00:00:00 2001 From: jj Date: Sat, 8 Feb 2025 16:27:33 +0000 Subject: [PATCH] api/bilibili: use shortlink resolver --- api/src/processing/services/bilibili.js | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/api/src/processing/services/bilibili.js b/api/src/processing/services/bilibili.js index b47b0bc2..4ee148db 100644 --- a/api/src/processing/services/bilibili.js +++ b/api/src/processing/services/bilibili.js @@ -1,19 +1,8 @@ import { genericUserAgent, env } from "../../config.js"; +import { resolveRedirectingURL } from "../url.js"; // TO-DO: higher quality downloads (currently requires an account) -function com_resolveShortlink(shortId) { - return fetch(`https://b23.tv/${shortId}`, { redirect: 'manual' }) - .then(r => r.status > 300 && r.status < 400 && r.headers.get('location')) - .then(url => { - if (!url) return; - const path = new URL(url).pathname; - if (path.startsWith('/video/')) - return path.split('/')[2]; - }) - .catch(() => {}) -} - function getBest(content) { return content?.filter(v => v.baseUrl || v.url) .map(v => (v.baseUrl = v.baseUrl || v.url, v)) @@ -99,7 +88,8 @@ async function tv_download(id) { export default async function({ comId, tvId, comShortLink }) { if (comShortLink) { - comId = await com_resolveShortlink(comShortLink); + const patternMatch = await resolveRedirectingURL(`https://b23.tv/${comShortLink}`); + comId = patternMatch?.comId; } if (comId) {