Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/src/processing/service-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const services = {
bilibili: {
patterns: [
"video/:comId",
"video/:comId?p=:partId",
"_shortLink/:comShortLink",
"_tv/:lang/video/:tvId",
"_tv/video/:tvId"
Expand Down
87 changes: 46 additions & 41 deletions api/src/processing/service-patterns.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,72 @@
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,

"bsky": pattern =>
pattern.user?.length <= 128 && pattern.post?.length <= 128,

"dailymotion": pattern => pattern.id?.length <= 32,

"facebook": pattern =>
pattern.shortLink?.length <= 11 ||
pattern.username?.length <= 30 ||
pattern.caption?.length <= 255 ||
pattern.id?.length <= 20 && !pattern.shareType ||
pattern.id?.length <= 20 && pattern.shareType?.length === 1,

"instagram": pattern =>
pattern.postId?.length <= 48
|| pattern.shareId?.length <= 16
|| (pattern.username?.length <= 30 && pattern.storyId?.length <= 24),
pattern.postId?.length <= 48 ||
pattern.shareId?.length <= 16 ||
(pattern.username?.length <= 30 && pattern.storyId?.length <= 24),

"loom": pattern =>
pattern.id?.length <= 32,

"newgrounds": pattern =>
pattern.id?.length <= 12 ||
pattern.audioId?.length <= 12,

"ok": pattern =>
pattern.id?.length <= 16,

"pinterest": pattern =>
pattern.id?.length <= 128 || pattern.shortLink?.length <= 32,
pattern.id?.length <= 128 ||
pattern.shortLink?.length <= 32,

"reddit": pattern =>
pattern.id?.length <= 16 && !pattern.sub && !pattern.user
|| (pattern.sub?.length <= 22 && pattern.id?.length <= 16)
|| (pattern.user?.length <= 22 && pattern.id?.length <= 16)
|| (pattern.sub?.length <= 22 && pattern.shareId?.length <= 16)
|| (pattern.shortId?.length <= 16),
pattern.id?.length <= 16 && !pattern.sub && !pattern.user ||
(pattern.sub?.length <= 22 && pattern.id?.length <= 16) ||
(pattern.user?.length <= 22 && pattern.id?.length <= 16) ||
(pattern.sub?.length <= 22 && pattern.shareId?.length <= 16) ||
(pattern.shortId?.length <= 16),

"rutube": pattern =>
(pattern.id?.length === 32 && pattern.key?.length <= 32) ||
pattern.id?.length === 32 || pattern.yappyId?.length === 32,

"soundcloud": pattern =>
(pattern.author?.length <= 255 && pattern.song?.length <= 255)
|| pattern.shortLink?.length <= 32,
pattern.id?.length === 32 ||
pattern.yappyId?.length === 32,

"snapchat": pattern =>
(pattern.username?.length <= 32 && (!pattern.storyId || pattern.storyId?.length <= 255))
|| pattern.spotlightId?.length <= 255
|| pattern.shortLink?.length <= 16,
(pattern.username?.length <= 32 && (!pattern.storyId || pattern.storyId?.length <= 255)) ||
pattern.spotlightId?.length <= 255 ||
pattern.shortLink?.length <= 16,

"soundcloud": pattern =>
(pattern.author?.length <= 255 && pattern.song?.length <= 255) ||
pattern.shortLink?.length <= 32,

"streamable": pattern =>
pattern.id?.length <= 6,

"tiktok": pattern =>
pattern.postId?.length <= 21 || pattern.shortLink?.length <= 21,
pattern.postId?.length <= 21 ||
pattern.shortLink?.length <= 21,

"tumblr": pattern =>
pattern.id?.length < 21
|| (pattern.id?.length < 21 && pattern.user?.length <= 32),
pattern.id?.length < 21 ||
(pattern.id?.length < 21 && pattern.user?.length <= 32),

"twitch": pattern =>
pattern.channel && pattern.clip?.length <= 100,
Expand All @@ -56,30 +75,16 @@ export const testers = {
pattern.id?.length < 20,

"vimeo": pattern =>
pattern.id?.length <= 11
&& (!pattern.password || pattern.password.length < 16),
pattern.id?.length <= 11 && (!pattern.password || pattern.password.length < 16),

"vk": pattern =>
(pattern.ownerId?.length <= 10 && pattern.videoId?.length <= 10) ||
(pattern.ownerId?.length <= 10 && pattern.videoId?.length <= 10 && pattern.videoId?.accessKey <= 18),

"youtube": pattern =>
pattern.id?.length <= 11,

"facebook": pattern =>
pattern.shortLink?.length <= 11
|| pattern.username?.length <= 30
|| pattern.caption?.length <= 255
|| pattern.id?.length <= 20 && !pattern.shareType
|| pattern.id?.length <= 20 && pattern.shareType?.length === 1,

"bsky": pattern =>
pattern.user?.length <= 128 && pattern.post?.length <= 128,

"xiaohongshu": pattern =>
pattern.id?.length <= 24 && pattern.token?.length <= 64
|| pattern.shareId?.length <= 24 && pattern.shareType?.length === 1,
pattern.id?.length <= 24 && pattern.token?.length <= 64 ||
pattern.shareId?.length <= 24 && pattern.shareType?.length === 1,

"newgrounds": pattern =>
pattern.id?.length <= 12 || pattern.audioId?.length <= 12,
"youtube": pattern =>
pattern.id?.length <= 11,
}
23 changes: 17 additions & 6 deletions api/src/processing/services/bilibili.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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`,
};
}

Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions api/src/processing/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function cleanURL(url) {
limitQuery('v');
}
break;
case "bilibili":
case "rutube":
if (url.searchParams.get('p')) {
limitQuery('p');
Expand Down
9 changes: 9 additions & 0 deletions api/src/util/tests/bilibili.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
Loading