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
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2
5 changed files with 32 additions and 8 deletions

View File

@ -7,6 +7,7 @@ export const services = {
bilibili: {
patterns: [
"video/:comId",
"video/:comId?p=:partId",
"_shortLink/:comShortLink",
"_tv/:lang/video/:tvId",
"_tv/video/:tvId"

View File

@ -1,7 +1,9 @@
export const testers = {
"bilibili": pattern =>
pattern.comId?.length <= 12 || pattern.comShortLink?.length <= 16
|| pattern.tvId?.length <= 24,
(pattern.comId?.length <= 12 && pattern.partId?.length <= 3) ||
(pattern.comId?.length <= 12 && !pattern.partId) ||
pattern.comShortLink?.length <= 16 ||
pattern.tvId?.length <= 24,
"dailymotion": pattern => pattern.id?.length <= 32,

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);
}

View File

@ -147,6 +147,7 @@ function cleanURL(url) {
limitQuery('v');
}
break;
case "bilibili":
case "rutube":
if (url.searchParams.get('p')) {
limitQuery('p');

View File

@ -56,5 +56,14 @@
"code": 200,
"status": "tunnel"
}
},
{
"name": "bilibili.com link with part id",
"url": "https://www.bilibili.com/video/BV1uo4y1K72s?spm_id_from=333.788.videopod.episodes&p=6",
"params": {},
"expected": {
"code": 200,
"status": "tunnel"
}
}
]