mirror of
https://github.com/imputnet/cobalt.git
synced 2025-08-13 16:08:27 +00:00
api/bilibili: add support for video parts/episodes
different videos share the same id, kind of weird
This commit is contained in:
parent
1d5db46a79
commit
64a7b1dd62
@ -7,6 +7,7 @@ export const services = {
|
|||||||
bilibili: {
|
bilibili: {
|
||||||
patterns: [
|
patterns: [
|
||||||
"video/:comId",
|
"video/:comId",
|
||||||
|
"video/:comId?p=:partId",
|
||||||
"_shortLink/:comShortLink",
|
"_shortLink/:comShortLink",
|
||||||
"_tv/:lang/video/:tvId",
|
"_tv/:lang/video/:tvId",
|
||||||
"_tv/video/:tvId"
|
"_tv/video/:tvId"
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
export const testers = {
|
export const testers = {
|
||||||
"bilibili": pattern =>
|
"bilibili": pattern =>
|
||||||
pattern.comId?.length <= 12 || pattern.comShortLink?.length <= 16
|
(pattern.comId?.length <= 12 && pattern.partId?.length <= 3) ||
|
||||||
|| pattern.tvId?.length <= 24,
|
(pattern.comId?.length <= 12 && !pattern.partId) ||
|
||||||
|
pattern.comShortLink?.length <= 16 ||
|
||||||
|
pattern.tvId?.length <= 24,
|
||||||
|
|
||||||
"dailymotion": pattern => pattern.id?.length <= 32,
|
"dailymotion": pattern => pattern.id?.length <= 32,
|
||||||
|
|
||||||
|
@ -17,8 +17,14 @@ function extractBestQuality(dashData) {
|
|||||||
return [ bestVideo, bestAudio ];
|
return [ bestVideo, bestAudio ];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function com_download(id) {
|
async function com_download(id, partId) {
|
||||||
const html = await fetch(`https://bilibili.com/video/${id}`, {
|
const url = new URL(`https://bilibili.com/video/${id}`);
|
||||||
|
|
||||||
|
if (partId) {
|
||||||
|
url.searchParams.set('p', partId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const html = await fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
"user-agent": genericUserAgent
|
"user-agent": genericUserAgent
|
||||||
}
|
}
|
||||||
@ -47,10 +53,15 @@ async function com_download(id) {
|
|||||||
return { error: "fetch.empty" };
|
return { error: "fetch.empty" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let filenameBase = `bilibili_${id}`;
|
||||||
|
if (partId) {
|
||||||
|
filenameBase += `_${partId}`;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
urls: [video.baseUrl, audio.baseUrl],
|
urls: [video.baseUrl, audio.baseUrl],
|
||||||
audioFilename: `bilibili_${id}_audio`,
|
audioFilename: `${filenameBase}_audio`,
|
||||||
filename: `bilibili_${id}_${video.width}x${video.height}.mp4`,
|
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) {
|
if (comShortLink) {
|
||||||
const patternMatch = await resolveRedirectingURL(`https://b23.tv/${comShortLink}`);
|
const patternMatch = await resolveRedirectingURL(`https://b23.tv/${comShortLink}`);
|
||||||
comId = patternMatch?.comId;
|
comId = patternMatch?.comId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comId) {
|
if (comId) {
|
||||||
return com_download(comId);
|
return com_download(comId, partId);
|
||||||
} else if (tvId) {
|
} else if (tvId) {
|
||||||
return tv_download(tvId);
|
return tv_download(tvId);
|
||||||
}
|
}
|
||||||
|
@ -147,6 +147,7 @@ function cleanURL(url) {
|
|||||||
limitQuery('v');
|
limitQuery('v');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "bilibili":
|
||||||
case "rutube":
|
case "rutube":
|
||||||
if (url.searchParams.get('p')) {
|
if (url.searchParams.get('p')) {
|
||||||
limitQuery('p');
|
limitQuery('p');
|
||||||
|
@ -56,5 +56,14 @@
|
|||||||
"code": 200,
|
"code": 200,
|
||||||
"status": "tunnel"
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user