api/bilibili: add support for video parts/episodes

different videos share the same id, kind of weird
This commit is contained in:
wukko
2025-08-11 17:58:40 +06:00
parent 1d5db46a79
commit 64a7b1dd62
5 changed files with 32 additions and 8 deletions

View File

@@ -17,8 +17,14 @@ function extractBestQuality(dashData) {
return [ bestVideo, bestAudio ];
}
async function com_download(id) {
const html = await fetch(`https://bilibili.com/video/${id}`, {
async function com_download(id, partId) {
const url = new URL(`https://bilibili.com/video/${id}`);
if (partId) {
url.searchParams.set('p', partId);
}
const html = await fetch(url, {
headers: {
"user-agent": genericUserAgent
}
@@ -47,10 +53,15 @@ async function com_download(id) {
return { error: "fetch.empty" };
}
let filenameBase = `bilibili_${id}`;
if (partId) {
filenameBase += `_${partId}`;
}
return {
urls: [video.baseUrl, audio.baseUrl],
audioFilename: `bilibili_${id}_audio`,
filename: `bilibili_${id}_${video.width}x${video.height}.mp4`,
audioFilename: `${filenameBase}_audio`,
filename: `${filenameBase}_${video.width}x${video.height}.mp4`,
};
}
@@ -89,14 +100,14 @@ async function tv_download(id) {
};
}
export default async function({ comId, tvId, comShortLink }) {
export default async function({ comId, tvId, comShortLink, partId }) {
if (comShortLink) {
const patternMatch = await resolveRedirectingURL(`https://b23.tv/${comShortLink}`);
comId = patternMatch?.comId;
}
if (comId) {
return com_download(comId);
return com_download(comId, partId);
} else if (tvId) {
return tv_download(tvId);
}