feat(route/bilibili): refactor description with art-template (#16956)
* feat(route/bilibili): refactor bangumi with ofetch and art-template * feat(route/bilibili): refactor bilibili-recommend with art-template * feat(route/bilibili): refactor coin with art-template * feat(route/bilibili): refactor fav with art-template * feat(route/bilibili): refactor like with art-template * feat(route/bilibili): refactor page with art-template * feat(route/bilibili): refactor partion-ranking with art-template * feat(route/bilibili): refactor partion with art-template * feat(route/bilibili): refactor popular with art-template * feat(route/bilibili): refactor ranking with art-template * feat(route/bilibili): refactor user-channel with art-template * feat(route/bilibili): refactor user-collection with art-template * feat(route/bilibili): refactor user-fav with art-template * feat(route/bilibili): refactor weekly-recommend with art-template * feat(route/bilibili): refactor dynamic with art-template * feat(route/bilibili): refactor followings-dynamic with art-template * feat(route/bilibili): refactor followings-video with art-template * feat(route/bilibili): refactor video-all with art-template * feat(route/bilibili): refactor video with art-template * feat(route/bilibili): refactor vsearch with art-template * feat(route/bilibili): refactor watchlater with art-template * feat(route/bilibili): remove iframe * fix(route/bilibili): __dirname * docs(route/bilibili): add documents. * feat(route/bilibili): use https cover * style(bilibili): camelCase * style(bilibili): keep ordering * fix(bilibili): use html5mobileplayer.html ---------
This commit is contained in:
@@ -1,66 +1,68 @@
|
||||
import { Route, ViewType } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { Data, DataItem, Route, ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import { EpisodeResult } from './types';
|
||||
import utils from './utils';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/bangumi/media/:mediaid',
|
||||
path: '/bangumi/media/:mediaid/:embed?',
|
||||
name: '番剧',
|
||||
parameters: {
|
||||
mediaid: '番剧媒体 id, 番剧主页 URL 中获取',
|
||||
embed: '默认为开启内嵌视频, 任意值为关闭',
|
||||
},
|
||||
example: '/bilibili/bangumi/media/9192',
|
||||
categories: ['social-media', 'popular'],
|
||||
view: ViewType.Videos,
|
||||
maintainers: ['DIYgod'],
|
||||
maintainers: ['DIYgod', 'nuomi1'],
|
||||
handler,
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: true,
|
||||
supportRadar: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
let seasonid = ctx.req.param('seasonid');
|
||||
const mediaid = ctx.req.param('mediaid');
|
||||
const mediaId = ctx.req.param('mediaid');
|
||||
const embed = !ctx.req.param('embed');
|
||||
|
||||
let mediaData;
|
||||
if (mediaid) {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://www.bilibili.com/bangumi/media/md${mediaid}`,
|
||||
});
|
||||
mediaData = JSON.parse(response.data.match(/window\.__INITIAL_STATE__=([\S\s]+);\(function\(\)/)[1]) || {};
|
||||
seasonid = mediaData.mediaInfo.season_id;
|
||||
}
|
||||
const { data } = await got.get(`https://api.bilibili.com/pgc/web/season/section?season_id=${seasonid}`);
|
||||
const mediaData = await utils.getBangumi(mediaId, cache);
|
||||
const seasonId = String(mediaData.season_id);
|
||||
const seasonData = await utils.getBangumiItems(seasonId, cache);
|
||||
|
||||
let episodes = [];
|
||||
if (data.result.main_section && data.result.main_section.episodes) {
|
||||
episodes = [
|
||||
...episodes,
|
||||
...data.result.main_section.episodes.map((item) => ({
|
||||
title: `第${item.title}话 ${item.long_title}`,
|
||||
description: `<img src="${item.cover}">`,
|
||||
link: `https://www.bilibili.com/bangumi/play/ep${item.id}`,
|
||||
})),
|
||||
];
|
||||
const episodes: DataItem[] = [];
|
||||
|
||||
const getEpisode = (item: EpisodeResult, title: string) =>
|
||||
({
|
||||
title,
|
||||
description: utils.renderOGVDescription(embed, item.cover, item.long_title, seasonId, String(item.id)),
|
||||
link: item.share_url,
|
||||
image: item.cover.replace('http://', 'https://'),
|
||||
language: 'zh-cn',
|
||||
}) as DataItem;
|
||||
|
||||
for (const item of seasonData.main_section.episodes) {
|
||||
const episode = getEpisode(item, `第${item.title}话 ${item.long_title}`);
|
||||
episodes.push(episode);
|
||||
}
|
||||
|
||||
if (data.result.section) {
|
||||
for (const section of data.result.section) {
|
||||
if (section.episodes) {
|
||||
episodes = [
|
||||
...episodes,
|
||||
...section.episodes.map((item) => ({
|
||||
title: `${item.title} ${item.long_title}`,
|
||||
description: `<img src="${item.cover}">`,
|
||||
link: `https://www.bilibili.com/bangumi/play/ep${item.id}`,
|
||||
})),
|
||||
];
|
||||
}
|
||||
for (const section of seasonData.section) {
|
||||
for (const item of section.episodes) {
|
||||
const episode = getEpisode(item, `${item.title} ${item.long_title}`);
|
||||
episodes.push(episode);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
title: mediaData?.mediaInfo.title,
|
||||
link: `https://www.bilibili.com/bangumi/media/md${mediaData?.mediaInfo.media_id}/`,
|
||||
image: mediaData?.mediaInfo.cover,
|
||||
description: mediaData?.mediaInfo.evaluate,
|
||||
title: mediaData.title,
|
||||
description: mediaData.evaluate,
|
||||
link: mediaData.share_url,
|
||||
item: episodes,
|
||||
};
|
||||
image: mediaData.cover.replace('http://', 'https://'),
|
||||
language: 'zh-cn',
|
||||
} as Data;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ import got from '@/utils/got';
|
||||
import utils from './utils';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/precious/:disableEmbed?',
|
||||
path: '/precious/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/precious',
|
||||
parameters: { disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -21,7 +21,7 @@ export const route: Route = {
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: 'https://api.bilibili.com/x/web-interface/popular/precious',
|
||||
@@ -35,7 +35,7 @@ async function handler(ctx) {
|
||||
link: 'https://www.bilibili.com/v/popular/history',
|
||||
item: data.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.desc || item.title}${disableEmbed ? '' : `<br><br>${utils.iframe(item.aid, null, item.bvid)}`}<br><img src="${item.pic}">`,
|
||||
description: utils.renderUGCDescription(embed, item.pic, item.desc || item.title, item.aid, undefined, item.bvid),
|
||||
link: item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
})),
|
||||
};
|
||||
|
||||
@@ -5,10 +5,10 @@ import utils from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/user/coin/:uid/:disableEmbed?',
|
||||
path: '/user/coin/:uid/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/user/coin/208259',
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -30,7 +30,7 @@ export const route: Route = {
|
||||
|
||||
async function handler(ctx) {
|
||||
const uid = ctx.req.param('uid');
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
|
||||
const name = await cache.getUsernameFromUID(uid);
|
||||
|
||||
@@ -51,7 +51,7 @@ async function handler(ctx) {
|
||||
description: `${name} 的 bilibili 投币视频`,
|
||||
item: data.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.desc}${disableEmbed ? '' : `<br><br>${utils.iframe(item.aid)}`}<br><img src='${item.pic}'>`,
|
||||
description: utils.renderUGCDescription(embed, item.pic, item.desc, item.aid, undefined, item.bvid),
|
||||
pubDate: parseDate(item.time * 1000),
|
||||
link: item.time > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: item.owner.name,
|
||||
|
||||
@@ -16,15 +16,15 @@ export const route: Route = {
|
||||
parameters: {
|
||||
uid: '用户 id, 可在 UP 主主页中找到',
|
||||
routeParams: `
|
||||
| 键 | 含义 | 接受的值 | 默认值 |
|
||||
| ------------ | --------------------------------- | -------------- | ------ |
|
||||
| showEmoji | 显示或隐藏表情图片 | 0/1/true/false | false |
|
||||
| disableEmbed | 关闭内嵌视频 | 0/1/true/false | false |
|
||||
| useAvid | 视频链接使用 AV 号 (默认为 BV 号) | 0/1/true/false | false |
|
||||
| directLink | 使用内容直链 | 0/1/true/false | false |
|
||||
| hideGoods | 隐藏带货动态 | 0/1/true/false | false |
|
||||
| 键 | 含义 | 接受的值 | 默认值 |
|
||||
| ---------- | --------------------------------- | -------------- | ------ |
|
||||
| showEmoji | 显示或隐藏表情图片 | 0/1/true/false | false |
|
||||
| embed | 默认开启内嵌视频 | 任意值 | |
|
||||
| useAvid | 视频链接使用 AV 号 (默认为 BV 号) | 0/1/true/false | false |
|
||||
| directLink | 使用内容直链 | 0/1/true/false | false |
|
||||
| hideGoods | 隐藏带货动态 | 0/1/true/false | false |
|
||||
|
||||
用例:\`/bilibili/user/dynamic/2267573/showEmoji=1&disableEmbed=1&useAvid=1\``,
|
||||
用例:\`/bilibili/user/dynamic/2267573/showEmoji=1&embed=0&useAvid=1\``,
|
||||
},
|
||||
features: {
|
||||
requireConfig: [
|
||||
@@ -108,16 +108,16 @@ const getDes = (data: Modules): string => {
|
||||
const getOriginTitle = (data?: Modules) => data && getTitle(data);
|
||||
const getOriginDes = (data?: Modules) => data && getDes(data);
|
||||
const getOriginName = (data?: Modules) => data?.module_author?.name;
|
||||
const getIframe = (data?: Modules, disableEmbed: boolean = false) => {
|
||||
if (disableEmbed) {
|
||||
const getIframe = (data?: Modules, embed: boolean = true) => {
|
||||
if (!embed) {
|
||||
return '';
|
||||
}
|
||||
const aid = data?.module_dynamic?.major?.archive?.aid;
|
||||
const bvid = data?.module_dynamic?.major?.archive?.bvid;
|
||||
if (!aid) {
|
||||
if (aid === undefined && bvid === undefined) {
|
||||
return '';
|
||||
}
|
||||
return utils.iframe(aid, null, bvid);
|
||||
return utils.renderUGCDescription(embed, '', '', aid, undefined, bvid);
|
||||
};
|
||||
|
||||
const getImgs = (data?: Modules) => {
|
||||
@@ -226,7 +226,7 @@ async function handler(ctx) {
|
||||
const uid = ctx.req.param('uid');
|
||||
const routeParams = Object.fromEntries(new URLSearchParams(ctx.req.param('routeParams')));
|
||||
const showEmoji = fallback(undefined, queryToBoolean(routeParams.showEmoji), false);
|
||||
const disableEmbed = fallback(undefined, queryToBoolean(routeParams.disableEmbed), false);
|
||||
const embed = !ctx.req.param('embed');
|
||||
const displayArticle = ctx.req.query('mode') === 'fulltext';
|
||||
const useAvid = fallback(undefined, queryToBoolean(routeParams.useAvid), false);
|
||||
const directLink = fallback(undefined, queryToBoolean(routeParams.directLink), false);
|
||||
@@ -356,7 +356,7 @@ async function handler(ctx) {
|
||||
description = description.replaceAll('\r\n', '<br>').replaceAll('\n', '<br>');
|
||||
originDescription = originDescription.replaceAll('\r\n', '<br>').replaceAll('\n', '<br>');
|
||||
|
||||
const descriptions = [description, originDescription, urlText, originUrlText, getIframe(data, disableEmbed), getIframe(origin, disableEmbed), getImgs(data), getImgs(origin)]
|
||||
const descriptions = [description, originDescription, urlText, originUrlText, getIframe(data, embed), getIframe(origin, embed), getImgs(data), getImgs(origin)]
|
||||
.filter(Boolean)
|
||||
.map((e) => e?.trim())
|
||||
.join('<br>');
|
||||
|
||||
@@ -5,10 +5,10 @@ import { parseDate } from '@/utils/parse-date';
|
||||
import { config } from '@/config';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/fav/:uid/:fid/:disableEmbed?',
|
||||
path: '/fav/:uid/:fid/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/fav/756508/50948568',
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', fid: '收藏夹 ID, 可在收藏夹的 URL 中找到, 默认收藏夹建议使用 UP 主默认收藏夹功能', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', fid: '收藏夹 ID, 可在收藏夹的 URL 中找到, 默认收藏夹建议使用 UP 主默认收藏夹功能', embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -25,7 +25,7 @@ export const route: Route = {
|
||||
async function handler(ctx) {
|
||||
const fid = ctx.req.param('fid');
|
||||
const uid = ctx.req.param('uid');
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
|
||||
const response = await got({
|
||||
url: `https://api.bilibili.com/x/v3/fav/resource/list?media_id=${fid}&ps=20`,
|
||||
@@ -51,7 +51,7 @@ async function handler(ctx) {
|
||||
data.medias &&
|
||||
data.medias.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.intro}${disableEmbed ? '' : `<br><br>${utils.iframe(item.id)}`}<br><img src='${item.cover}'>`,
|
||||
description: utils.renderUGCDescription(embed, item.cover, item.intro, item.id, undefined, item.bvid),
|
||||
pubDate: parseDate(item.fav_time * 1000),
|
||||
link: item.fav_time > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.id}`,
|
||||
author: item.upper.name,
|
||||
|
||||
@@ -12,7 +12,19 @@ export const route: Route = {
|
||||
path: '/followings/dynamic/:uid/:routeParams?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/followings/dynamic/109937383',
|
||||
parameters: { uid: '用户 id', routeParams: '额外参数;请参阅 [#UP 主动态](#bilibili-up-zhu-dong-tai) 的说明和表格' },
|
||||
parameters: {
|
||||
uid: '用户 id, 可在 UP 主主页中找到',
|
||||
routeParams: `
|
||||
| 键 | 含义 | 接受的值 | 默认值 |
|
||||
| ---------- | --------------------------------- | -------------- | ------ |
|
||||
| showEmoji | 显示或隐藏表情图片 | 0/1/true/false | false |
|
||||
| embed | 默认开启内嵌视频 | 任意值 | |
|
||||
| useAvid | 视频链接使用 AV 号 (默认为 BV 号) | 0/1/true/false | false |
|
||||
| directLink | 使用内容直链 | 0/1/true/false | false |
|
||||
| hideGoods | 隐藏带货动态 | 0/1/true/false | false |
|
||||
|
||||
用例:\`/bilibili/followings/dynamic/2267573/showEmoji=1&embed=0&useAvid=1\``,
|
||||
},
|
||||
features: {
|
||||
requireConfig: [
|
||||
{
|
||||
@@ -43,7 +55,7 @@ async function handler(ctx) {
|
||||
const routeParams = querystring.parse(ctx.req.param('routeParams'));
|
||||
|
||||
const showEmoji = fallback(undefined, queryToBoolean(routeParams.showEmoji), false);
|
||||
const disableEmbed = fallback(undefined, queryToBoolean(routeParams.disableEmbed), false);
|
||||
const embed = !ctx.req.param('embed');
|
||||
const displayArticle = fallback(undefined, queryToBoolean(routeParams.displayArticle), false);
|
||||
|
||||
const name = await cache.getUsernameFromUID(uid);
|
||||
@@ -74,7 +86,17 @@ async function handler(ctx) {
|
||||
const getOriginDes = (data) => (data && (data.apiSeasonInfo && data.apiSeasonInfo.title && `//转发自: ${data.apiSeasonInfo.title}`) + (data.index_title && `<br>${data.index_title}`)) || '';
|
||||
const getOriginName = (data) => data.uname || (data.author && data.author.name) || (data.upper && data.upper.name) || (data.user && (data.user.uname || data.user.name)) || (data.owner && data.owner.name) || '';
|
||||
const getOriginTitle = (data) => (data.title ? `${data.title}<br>` : '');
|
||||
const getIframe = (data) => (!disableEmbed && data && data.aid ? `<br><br>${utils.iframe(data.aid)}<br>` : '');
|
||||
const getIframe = (data) => {
|
||||
if (!embed) {
|
||||
return '';
|
||||
}
|
||||
const aid = data?.aid;
|
||||
const bvid = data?.bvid;
|
||||
if (aid === undefined && bvid === undefined) {
|
||||
return '';
|
||||
}
|
||||
return utils.renderUGCDescription(embed, '', '', aid, undefined, bvid);
|
||||
};
|
||||
const getImgs = (data) => {
|
||||
let imgs = '';
|
||||
// 动态图片
|
||||
|
||||
@@ -7,10 +7,10 @@ import ConfigNotFoundError from '@/errors/types/config-not-found';
|
||||
import logger from '@/utils/logger';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/followings/video/:uid/:disableEmbed?',
|
||||
path: '/followings/video/:uid/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/followings/video/2267573',
|
||||
parameters: { uid: '用户 id', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { uid: '用户 id', embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: [
|
||||
{
|
||||
@@ -38,7 +38,7 @@ export const route: Route = {
|
||||
|
||||
async function handler(ctx) {
|
||||
const uid = String(ctx.req.param('uid'));
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
const name = await cache.getUsernameFromUID(uid);
|
||||
|
||||
const cookie = config.bilibili.cookies[uid];
|
||||
@@ -69,7 +69,7 @@ async function handler(ctx) {
|
||||
|
||||
return {
|
||||
title: card_data.title,
|
||||
description: `${card_data.desc}${disableEmbed ? '' : `<br><br>${utils.iframe(card_data.aid)}`}<br><img src="${card_data.pic}">`,
|
||||
description: utils.renderUGCDescription(embed, card_data.pic, card_data.desc, card_data.aid, undefined, card_data.bvid),
|
||||
pubDate: new Date(card_data.pubdate * 1000).toUTCString(),
|
||||
link: card_data.pubdate > utils.bvidTime && card_data.bvid ? `https://www.bilibili.com/video/${card_data.bvid}` : `https://www.bilibili.com/video/av${card_data.aid}`,
|
||||
author: card.desc.user_profile.info.uname,
|
||||
|
||||
@@ -5,10 +5,10 @@ import utils from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/user/like/:uid/:disableEmbed?',
|
||||
path: '/user/like/:uid/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/user/like/208259',
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -30,7 +30,7 @@ export const route: Route = {
|
||||
|
||||
async function handler(ctx) {
|
||||
const uid = ctx.req.param('uid');
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
|
||||
const name = await cache.getUsernameFromUID(uid);
|
||||
|
||||
@@ -51,7 +51,7 @@ async function handler(ctx) {
|
||||
description: `${name} 的 bilibili 点赞视频`,
|
||||
item: data.list.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.desc}${disableEmbed ? '' : `<br><br>${utils.iframe(item.aid)}`}<br><img src='${item.pic}'>`,
|
||||
description: utils.renderUGCDescription(embed, item.pic, item.desc, item.aid, undefined, item.bvid),
|
||||
pubDate: parseDate(item.pubdate * 1000),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: item.owner.name,
|
||||
|
||||
@@ -3,10 +3,10 @@ import got from '@/utils/got';
|
||||
import utils from './utils';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/video/page/:bvid/:disableEmbed?',
|
||||
path: '/video/page/:bvid/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/video/page/BV1i7411M7N9',
|
||||
parameters: { bvid: '可在视频页 URL 中找到', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { bvid: '可在视频页 URL 中找到', embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -27,7 +27,7 @@ async function handler(ctx) {
|
||||
aid = bvid;
|
||||
bvid = null;
|
||||
}
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
const link = `https://www.bilibili.com/video/${bvid || `av${aid}`}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
@@ -37,6 +37,7 @@ async function handler(ctx) {
|
||||
},
|
||||
});
|
||||
|
||||
const respdata = response.data.data;
|
||||
const { title: name, pages: data } = response.data.data;
|
||||
|
||||
return {
|
||||
@@ -48,7 +49,7 @@ async function handler(ctx) {
|
||||
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10)
|
||||
.map((item) => ({
|
||||
title: item.part,
|
||||
description: `${item.part} - ${name}${disableEmbed ? '' : `<br><br>${utils.iframe(aid, item.page, bvid)}`}`,
|
||||
description: utils.renderUGCDescription(embed, respdata.pic, `${item.part} - ${name}`, respdata.aid, item.cid, respdata.bvid),
|
||||
link: `${link}?p=${item.page}`,
|
||||
})),
|
||||
};
|
||||
|
||||
@@ -16,10 +16,10 @@ function formatDate(now) {
|
||||
}
|
||||
|
||||
export const route: Route = {
|
||||
path: '/partion/ranking/:tid/:days?/:disableEmbed?',
|
||||
path: '/partion/ranking/:tid/:days?/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/partion/ranking/171/3',
|
||||
parameters: { tid: '分区 id, 见上方表格', days: '缺省为 7, 指最近多少天内的热度排序', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { tid: '分区 id, 见上方表格', days: '缺省为 7, 指最近多少天内的热度排序', embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -36,7 +36,7 @@ export const route: Route = {
|
||||
async function handler(ctx) {
|
||||
const tid = ctx.req.param('tid');
|
||||
const days = ctx.req.param('days') ?? 7;
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
|
||||
const responseApi = `https://api.bilibili.com/x/web-interface/newlist?ps=15&rid=${tid}&_=${Date.now()}`;
|
||||
|
||||
@@ -59,7 +59,7 @@ async function handler(ctx) {
|
||||
for (let item of hotlist) {
|
||||
item = {
|
||||
title: item.title,
|
||||
description: `${item.description}${disableEmbed ? '' : `<br><br>${utils.iframe(item.id)}`}<br><img src="https:${item.pic}"><br/>Tags:${item.tag}`,
|
||||
description: utils.renderUGCDescription(embed, item.pic, `${item.description} - ${item.tag}`, item.id, undefined, item.bvid),
|
||||
pubDate: new Date(item.pubdate).toUTCString(),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.id}`,
|
||||
author: item.author,
|
||||
|
||||
@@ -3,10 +3,10 @@ import got from '@/utils/got';
|
||||
import utils from './utils';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/partion/:tid/:disableEmbed?',
|
||||
path: '/partion/:tid/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/partion/33',
|
||||
parameters: { tid: '分区 id', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { tid: '分区 id', embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -135,7 +135,7 @@ export const route: Route = {
|
||||
|
||||
async function handler(ctx) {
|
||||
const tid = ctx.req.param('tid');
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
@@ -159,7 +159,7 @@ async function handler(ctx) {
|
||||
list &&
|
||||
list.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.desc}${disableEmbed ? '' : `<br><br>${utils.iframe(item.aid)}`}<br><img src="${item.pic}">`,
|
||||
description: utils.renderUGCDescription(embed, item.pic, item.desc, item.aid, undefined, item.bvid),
|
||||
pubDate: new Date(item.pubdate * 1000).toUTCString(),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: item.owner.name,
|
||||
|
||||
@@ -3,10 +3,12 @@ import got from '@/utils/got';
|
||||
import utils from './utils';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/popular/all',
|
||||
path: '/popular/all/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/popular/all',
|
||||
parameters: {},
|
||||
parameters: {
|
||||
embed: '默认为开启内嵌视频, 任意值为关闭',
|
||||
},
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -21,7 +23,7 @@ export const route: Route = {
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://api.bilibili.com/x/web-interface/popular`,
|
||||
@@ -39,7 +41,7 @@ async function handler(ctx) {
|
||||
list &&
|
||||
list.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.desc}${disableEmbed ? '' : `<br><br>${utils.iframe(item.aid)}`}<br><img src="${item.pic}">`,
|
||||
description: utils.renderUGCDescription(embed, item.pic, item.desc, item.aid, undefined, item.bvid),
|
||||
pubDate: new Date(item.pubdate * 1000).toUTCString(),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: item.owner.name,
|
||||
|
||||
@@ -3,7 +3,7 @@ import got from '@/utils/got';
|
||||
import utils from './utils';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/ranking/:rid?/:day?/:arc_type?/:disableEmbed?',
|
||||
path: '/ranking/:rid?/:day?/:arc_type?/:embed?',
|
||||
name: '排行榜',
|
||||
maintainers: ['DIYgod'],
|
||||
categories: ['social-media', 'popular'],
|
||||
@@ -104,9 +104,7 @@ export const route: Route = {
|
||||
},
|
||||
],
|
||||
},
|
||||
disableEmbed: {
|
||||
description: '默认为开启内嵌视频, 任意值为关闭',
|
||||
},
|
||||
embed: '默认为开启内嵌视频, 任意值为关闭',
|
||||
},
|
||||
handler,
|
||||
};
|
||||
@@ -115,7 +113,7 @@ async function handler(ctx) {
|
||||
const rid = ctx.req.param('rid') || '0';
|
||||
const day = ctx.req.param('day') || '3';
|
||||
const arc_type = ctx.req.param('arc_type') || '1';
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
const arc_type1 = arc_type === '0' ? '全部投稿' : '近期投稿';
|
||||
const rid_1 = ['0', '1', '168', '3', '129', '4', '36', '188', '160', '119', '155', '5', '181'];
|
||||
const rid_2 = ['全站', '动画', '国创相关', '音乐', '舞蹈', '游戏', '科技', '数码', '生活', '鬼畜', '时尚', '娱乐', '影视'];
|
||||
@@ -144,7 +142,7 @@ async function handler(ctx) {
|
||||
link: `https://www.bilibili.com/ranking/all/${rid}/0/${day}`,
|
||||
item: list.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.description || item.title}${disableEmbed ? '' : `<br><br>${utils.iframe(item.aid, null, item.bvid)}`}<br><img src="${item.pic}">`,
|
||||
description: utils.renderUGCDescription(embed, item.pic, item.description || item.title, item.aid, undefined, item.bvid),
|
||||
pubDate: item.create && new Date(item.create).toUTCString(),
|
||||
author: item.author,
|
||||
link: !item.create || (new Date(item.create) / 1000 > utils.bvidTime && item.bvid) ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{{ if embed }}
|
||||
{{ if ugc }}
|
||||
<iframe width="640" height="360" src="https://www.bilibili.com/blackboard/html5mobileplayer.html?aid={{ aid }}&cid={{ cid }}&bvid={{ bvid }}" frameborder="0" allowfullscreen></iframe>
|
||||
{{ /if }}
|
||||
{{ if ogv }}
|
||||
<iframe width="640" height="360" src="https://www.bilibili.com/blackboard/html5mobileplayer.html?seasonId={{ seasonId }}&episodeId={{ episodeId }}" frameborder="0" allowfullscreen></iframe>
|
||||
{{ /if }}
|
||||
<br>
|
||||
{{ /if }}
|
||||
<img src="{{ img }}">
|
||||
<br>
|
||||
{{@ description }}
|
||||
@@ -0,0 +1,52 @@
|
||||
export interface ResultResponse<Result> {
|
||||
result: Result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 番剧信息
|
||||
*
|
||||
* @interface MediaResult
|
||||
*
|
||||
* @property {string} cover - 封面。
|
||||
* @property {string} evaluate - 摘要。
|
||||
* @property {number} media_id - 媒体 ID。
|
||||
* @property {number} season_id - 季度 ID。
|
||||
* @property {string} share_url - 分享 URL。此属性是注入的。
|
||||
* @property {string} title - 标题。
|
||||
*/
|
||||
export interface MediaResult {
|
||||
cover: string;
|
||||
evaluate: string;
|
||||
media_id: number;
|
||||
season_id: number;
|
||||
share_url: string; // injected
|
||||
title: string;
|
||||
}
|
||||
|
||||
export interface SeasonResult {
|
||||
main_section: SectionResult;
|
||||
section: SectionResult[];
|
||||
}
|
||||
|
||||
export interface SectionResult {
|
||||
episodes: EpisodeResult[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 番剧剧集信息
|
||||
*
|
||||
* @interface EpisodeResult
|
||||
*
|
||||
* @property {string} cover - 封面。
|
||||
* @property {number} id - 剧集 ID。
|
||||
* @property {string} long_title - 完整标题。
|
||||
* @property {string} share_url - 分享 URL。
|
||||
* @property {string} title - 短标题。
|
||||
*/
|
||||
export interface EpisodeResult {
|
||||
cover: string;
|
||||
id: number;
|
||||
long_title: string;
|
||||
share_url: string;
|
||||
title: string;
|
||||
}
|
||||
@@ -10,10 +10,10 @@ const notFoundData = {
|
||||
};
|
||||
|
||||
export const route: Route = {
|
||||
path: '/user/channel/:uid/:sid/:disableEmbed?',
|
||||
path: '/user/channel/:uid/:sid/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/user/channel/2267573/396050',
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', sid: '频道 id, 可在频道的 URL 中找到', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', sid: '频道 id, 可在频道的 URL 中找到', embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -30,7 +30,7 @@ export const route: Route = {
|
||||
async function handler(ctx) {
|
||||
const uid = Number.parseInt(ctx.req.param('uid'));
|
||||
const sid = Number.parseInt(ctx.req.param('sid'));
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
const limit = ctx.req.query('limit') ?? 25;
|
||||
|
||||
const link = `https://space.bilibili.com/${uid}/channel/seriesdetail?sid=${sid}`;
|
||||
@@ -70,19 +70,12 @@ async function handler(ctx) {
|
||||
description: `${userName} 的 bilibili 频道`,
|
||||
logo: face,
|
||||
icon: face,
|
||||
item: data.archives.map((item) => {
|
||||
const descList = [];
|
||||
if (!disableEmbed) {
|
||||
descList.push(utils.iframe(item.aid));
|
||||
}
|
||||
descList.push(`<img src="${item.pic}">`);
|
||||
return {
|
||||
title: item.title,
|
||||
description: descList.join('<br>'),
|
||||
pubDate: parseDate(item.pubdate, 'X'),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: userName,
|
||||
};
|
||||
}),
|
||||
item: data.archives.map((item) => ({
|
||||
title: item.title,
|
||||
description: utils.renderUGCDescription(embed, item.pic, '', item.aid, undefined, item.bvid),
|
||||
pubDate: parseDate(item.pubdate, 'X'),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: userName,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,20 +3,19 @@ import got from '@/utils/got';
|
||||
import cache from './cache';
|
||||
import utils from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { queryToBoolean } from '@/utils/readable-social';
|
||||
|
||||
const notFoundData = {
|
||||
title: '此 bilibili 频道不存在',
|
||||
};
|
||||
|
||||
export const route: Route = {
|
||||
path: '/user/collection/:uid/:sid/:disableEmbed?/:sortReverse?/:page?',
|
||||
path: '/user/collection/:uid/:sid/:embed?/:sortReverse?/:page?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/user/collection/245645656/529166',
|
||||
parameters: {
|
||||
uid: '用户 id, 可在 UP 主主页中找到',
|
||||
sid: '合集 id, 可在合集页面的 URL 中找到',
|
||||
disableEmbed: '空,0与false为开启内嵌视频, 其他任意值为关闭',
|
||||
embed: '默认为开启内嵌视频, 任意值为关闭',
|
||||
sortReverse: '默认:默认排序 1:升序排序',
|
||||
page: '页码, 默认1',
|
||||
},
|
||||
@@ -36,7 +35,7 @@ export const route: Route = {
|
||||
async function handler(ctx) {
|
||||
const uid = Number.parseInt(ctx.req.param('uid'));
|
||||
const sid = Number.parseInt(ctx.req.param('sid'));
|
||||
const disableEmbed = queryToBoolean(ctx.req.param('disableEmbed'));
|
||||
const embed = !ctx.req.param('embed');
|
||||
const sortReverse = Number.parseInt(ctx.req.param('sortReverse')) === 1;
|
||||
const page = ctx.req.param('page') ? Number.parseInt(ctx.req.param('page')) : 1;
|
||||
const limit = ctx.req.query('limit') ?? 25;
|
||||
@@ -62,19 +61,12 @@ async function handler(ctx) {
|
||||
description: `${userName} 的 bilibili 合集`,
|
||||
logo: face,
|
||||
icon: face,
|
||||
item: data.archives.map((item) => {
|
||||
const descList = [];
|
||||
if (!disableEmbed) {
|
||||
descList.push(utils.iframe(item.aid));
|
||||
}
|
||||
descList.push(`<img src="${item.pic}">`);
|
||||
return {
|
||||
title: item.title,
|
||||
description: descList.join('<br>'),
|
||||
pubDate: parseDate(item.pubdate, 'X'),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: userName,
|
||||
};
|
||||
}),
|
||||
item: data.archives.map((item) => ({
|
||||
title: item.title,
|
||||
description: utils.renderUGCDescription(embed, item.pic, '', item.aid, undefined, item.bvid),
|
||||
pubDate: parseDate(item.pubdate, 'X'),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: userName,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ import utils from './utils';
|
||||
import { config } from '@/config';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/user/fav/:uid/:disableEmbed?',
|
||||
path: '/user/fav/:uid/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/user/fav/2267573',
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -30,7 +30,7 @@ export const route: Route = {
|
||||
|
||||
async function handler(ctx) {
|
||||
const uid = ctx.req.param('uid');
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
const name = await cache.getUsernameFromUID(uid);
|
||||
|
||||
const response = await got({
|
||||
@@ -53,7 +53,7 @@ async function handler(ctx) {
|
||||
data.data.archives &&
|
||||
data.data.archives.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.desc}${disableEmbed ? '' : `<br><br>${utils.iframe(item.aid)}`}<br><img src="${item.pic}">`,
|
||||
description: utils.renderUGCDescription(embed, item.pic, item.desc, item.aid, undefined, item.bvid),
|
||||
pubDate: new Date(item.fav_at * 1000).toUTCString(),
|
||||
link: item.fav_at > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: item.owner.name,
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { getCurrentPath } from '@/utils/helpers';
|
||||
const __dirname = getCurrentPath(import.meta.url);
|
||||
|
||||
import { config } from '@/config';
|
||||
import md5 from '@/utils/md5';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { art } from '@/utils/render';
|
||||
import CryptoJS from 'crypto-js';
|
||||
|
||||
function iframe(aid: any, page?: any, bvid?: any) {
|
||||
return `<iframe src="https://www.bilibili.com/blackboard/html5mobileplayer.html?${bvid ? `bvid=${bvid}` : `aid=${aid}`}${
|
||||
page ? `&page=${page}` : ''
|
||||
}&high_quality=1&autoplay=0" width="650" height="477" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe>`;
|
||||
}
|
||||
import path from 'node:path';
|
||||
import { MediaResult, ResultResponse, SeasonResult } from './types';
|
||||
|
||||
// a
|
||||
function randomHexStr(length) {
|
||||
@@ -197,8 +198,107 @@ function addDmVerifyInfoWithInter(params: string, dmImgList: string, dmImgInter:
|
||||
|
||||
const bvidTime = 1_589_990_400;
|
||||
|
||||
/**
|
||||
* 获取番剧信息并缓存
|
||||
*
|
||||
* @param {string} id - 番剧 ID。
|
||||
* @param cache - 缓存 module。
|
||||
* @returns {Promise<MediaResult>} 番剧信息。
|
||||
*/
|
||||
export const getBangumi = (id: string, cache): Promise<MediaResult> =>
|
||||
cache.tryGet(
|
||||
`bilibili:getBangumi:${id}`,
|
||||
async () => {
|
||||
const res = await ofetch<ResultResponse<MediaResult>>('https://api.bilibili.com/pgc/view/web/media', {
|
||||
query: {
|
||||
media_id: id,
|
||||
},
|
||||
});
|
||||
if (res.result.share_url === undefined) {
|
||||
// reference: https://api.bilibili.com/pgc/review/user?media_id=${id}
|
||||
res.result.share_url = `https://www.bilibili.com/bangumi/media/md${res.result.media_id}`;
|
||||
}
|
||||
return res.result;
|
||||
},
|
||||
config.cache.routeExpire,
|
||||
false
|
||||
) as Promise<MediaResult>;
|
||||
|
||||
/**
|
||||
* 获取番剧分集信息并缓存
|
||||
*
|
||||
* @param {string} id - 番剧 ID。
|
||||
* @param cache - 缓存 module。
|
||||
* @returns {Promise<SeasonResult>} 番剧分集信息。
|
||||
*/
|
||||
export const getBangumiItems = (id: string, cache): Promise<SeasonResult> =>
|
||||
cache.tryGet(
|
||||
`bilibili:getBangumiItems:${id}`,
|
||||
async () => {
|
||||
const res = await ofetch<ResultResponse<SeasonResult>>('https://api.bilibili.com/pgc/web/season/section', {
|
||||
query: {
|
||||
season_id: id,
|
||||
},
|
||||
});
|
||||
return res.result;
|
||||
},
|
||||
config.cache.routeExpire,
|
||||
false
|
||||
) as Promise<SeasonResult>;
|
||||
|
||||
/**
|
||||
* 使用模板渲染 UGC(用户生成内容)描述。
|
||||
*
|
||||
* @param {boolean} embed - 是否嵌入视频。
|
||||
* @param {string} img - 要包含在描述中的图片 URL。
|
||||
* @param {string} description - UGC 的文本描述。
|
||||
* @param {string} [aid] - 可选。UGC 的 aid。
|
||||
* @param {string} [cid] - 可选。UGC 的 cid。
|
||||
* @param {string} [bvid] - 可选。UGC 的 bvid。
|
||||
* @returns {string} 渲染的 UGC 描述。
|
||||
*
|
||||
* @see https://player.bilibili.com/ 获取更多信息。
|
||||
*/
|
||||
export const renderUGCDescription = (embed: boolean, img: string, description: string, aid?: string, cid?: string, bvid?: string): string => {
|
||||
// docs: https://player.bilibili.com/
|
||||
const rendered = art(path.join(__dirname, 'templates/description.art'), {
|
||||
embed,
|
||||
ugc: true,
|
||||
aid,
|
||||
cid,
|
||||
bvid,
|
||||
img: img.replace('http://', 'https://'),
|
||||
description,
|
||||
});
|
||||
return rendered;
|
||||
};
|
||||
|
||||
/**
|
||||
* 使用模板渲染 OGV(原创视频)描述。
|
||||
*
|
||||
* @param {boolean} embed - 是否嵌入视频。
|
||||
* @param {string} img - 要包含在描述中的图片 URL。
|
||||
* @param {string} description - OGV 的文本描述。
|
||||
* @param {string} [seasonId] - 可选。OGV 的季 ID。
|
||||
* @param {string} [episodeId] - 可选。OGV 的集 ID。
|
||||
* @returns {string} 渲染的 OGV 描述。
|
||||
*
|
||||
* @see https://player.bilibili.com/ 获取更多信息。
|
||||
*/
|
||||
export const renderOGVDescription = (embed: boolean, img: string, description: string, seasonId?: string, episodeId?: string): string => {
|
||||
// docs: https://player.bilibili.com/
|
||||
const rendered = art(path.join(__dirname, 'templates/description.art'), {
|
||||
embed,
|
||||
ogv: true,
|
||||
seasonId,
|
||||
episodeId,
|
||||
img: img.replace('http://', 'https://'),
|
||||
description,
|
||||
});
|
||||
return rendered;
|
||||
};
|
||||
|
||||
export default {
|
||||
iframe,
|
||||
lsid,
|
||||
_uuid,
|
||||
hexsign,
|
||||
@@ -209,4 +309,8 @@ export default {
|
||||
addDmVerifyInfoWithInter,
|
||||
bvidTime,
|
||||
addRenderData,
|
||||
getBangumi,
|
||||
getBangumiItems,
|
||||
renderUGCDescription,
|
||||
renderOGVDescription,
|
||||
};
|
||||
|
||||
@@ -5,16 +5,21 @@ import utils from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/user/video-all/:uid/:disableEmbed?',
|
||||
path: '/user/video-all/:uid/:embed?',
|
||||
name: '用户所有视频',
|
||||
maintainers: [],
|
||||
handler,
|
||||
example: '/bilibili/user/video-all/2267573',
|
||||
parameters: {
|
||||
uid: '用户 id, 可在 UP 主主页中找到',
|
||||
embed: '默认为开启内嵌视频, 任意值为关闭',
|
||||
},
|
||||
categories: ['social-media'],
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const uid = ctx.req.param('uid');
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
const cookie = await cache.getCookie();
|
||||
const wbiVerifyString = await cache.getWbiVerifyString();
|
||||
const dmImgList = utils.getDmImgList();
|
||||
@@ -74,7 +79,7 @@ async function handler(ctx) {
|
||||
icon: face,
|
||||
item: vlist.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.description}${disableEmbed ? '' : `<br><br>${utils.iframe(item.aid)}`}<br><img src="${item.pic}">`,
|
||||
description: utils.renderUGCDescription(embed, item.pic, item.description, item.aid, undefined, item.bvid),
|
||||
pubDate: parseDate(item.created, 'X'),
|
||||
link: item.created > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: name,
|
||||
|
||||
@@ -5,11 +5,11 @@ import utils from './utils';
|
||||
import logger from '@/utils/logger';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/user/video/:uid/:disableEmbed?',
|
||||
path: '/user/video/:uid/:embed?',
|
||||
categories: ['social-media', 'popular'],
|
||||
view: ViewType.Videos,
|
||||
example: '/bilibili/user/video/2267573',
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { uid: '用户 id, 可在 UP 主主页中找到', embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -31,7 +31,7 @@ export const route: Route = {
|
||||
|
||||
async function handler(ctx) {
|
||||
const uid = ctx.req.param('uid');
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
const cookie = await cache.getCookie();
|
||||
const wbiVerifyString = await cache.getWbiVerifyString();
|
||||
const dmImgList = utils.getDmImgList();
|
||||
@@ -68,7 +68,7 @@ async function handler(ctx) {
|
||||
data.data.list.vlist &&
|
||||
data.data.list.vlist.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.description}${disableEmbed ? '' : `<br><br>${utils.iframe(item.aid)}`}<br><img src="${item.pic}">`,
|
||||
description: utils.renderUGCDescription(embed, item.pic, item.description, item.aid, undefined, item.bvid),
|
||||
pubDate: new Date(item.created * 1000).toUTCString(),
|
||||
link: item.created > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: name,
|
||||
|
||||
@@ -2,14 +2,18 @@ import { Route } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import utils from './utils';
|
||||
import { queryToBoolean } from '@/utils/readable-social';
|
||||
import cacheIn from './cache';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/vsearch/:kw/:order?/:disableEmbed?/:tid?',
|
||||
path: '/vsearch/:kw/:order?/:embed?/:tid?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/vsearch/RSSHub',
|
||||
parameters: { kw: '检索关键字', order: '排序方式, 综合:totalrank 最多点击:click 最新发布:pubdate(缺省) 最多弹幕:dm 最多收藏:stow', disableEmbed: '默认为开启内嵌视频, 任意值为关闭', tid: '分区 id' },
|
||||
parameters: {
|
||||
kw: '检索关键字',
|
||||
order: '排序方式, 综合:totalrank 最多点击:click 最新发布:pubdate(缺省) 最多弹幕:dm 最多收藏:stow',
|
||||
embed: '默认为开启内嵌视频, 任意值为关闭',
|
||||
tid: '分区 id',
|
||||
},
|
||||
features: {
|
||||
requireConfig: [
|
||||
{
|
||||
@@ -38,10 +42,22 @@ export const route: Route = {
|
||||
| 0 | 1 | 13 | 167 | 3 | 129 | 4 | 36 | 188 | 234 | 223 | 160 | 211 | 217 | 119 | 155 | 202 | 5 | 181 | 177 | 23 | 11 |`,
|
||||
};
|
||||
|
||||
const getIframe = (data, embed: boolean = true) => {
|
||||
if (!embed) {
|
||||
return '';
|
||||
}
|
||||
const aid = data?.aid;
|
||||
const bvid = data?.bvid;
|
||||
if (aid === undefined && bvid === undefined) {
|
||||
return '';
|
||||
}
|
||||
return utils.renderUGCDescription(embed, '', '', aid, undefined, bvid);
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const kw = ctx.req.param('kw');
|
||||
const order = ctx.req.param('order') || 'pubdate';
|
||||
const disableEmbed = queryToBoolean(ctx.req.param('disableEmbed'));
|
||||
const embed = !ctx.req.param('embed');
|
||||
const kw_url = encodeURIComponent(kw);
|
||||
const tids = ctx.req.param('tid') ?? 0;
|
||||
const cookie = await cacheIn.getCookie();
|
||||
@@ -84,7 +100,7 @@ async function handler(ctx) {
|
||||
`<br/>${des}<br/>` +
|
||||
`<img src="${img}"><br/>` +
|
||||
`Match By: ${item.hit_columns?.join(',') || ''}` +
|
||||
(disableEmbed ? '' : `<br><br>${utils.iframe(item.aid)}`),
|
||||
getIframe(item, embed),
|
||||
pubDate: parseDate(item.pubdate, 'X'),
|
||||
guid: item.arcurl,
|
||||
link: item.arcurl,
|
||||
|
||||
@@ -7,10 +7,10 @@ import { parseDate } from '@/utils/parse-date';
|
||||
import ConfigNotFoundError from '@/errors/types/config-not-found';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/watchlater/:uid/:disableEmbed?',
|
||||
path: '/watchlater/:uid/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/watchlater/2267573',
|
||||
parameters: { uid: '用户 id', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { uid: '用户 id', embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: [
|
||||
{
|
||||
@@ -38,7 +38,7 @@ export const route: Route = {
|
||||
|
||||
async function handler(ctx) {
|
||||
const uid = ctx.req.param('uid');
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
const name = await cache.getUsernameFromUID(uid);
|
||||
|
||||
const cookie = config.bilibili.cookies[uid];
|
||||
@@ -62,7 +62,7 @@ async function handler(ctx) {
|
||||
|
||||
const out = list.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.desc}<br><br><a href="https://www.bilibili.com/list/watchlater?bvid=${item.bvid}">在稍后再看列表中查看</a>${disableEmbed ? '' : `<br><br>${utils.iframe(item.aid)}`}<br><img src="${item.pic}">`,
|
||||
description: utils.renderUGCDescription(embed, item.pic, `${item.desc}<br><a href="https://www.bilibili.com/list/watchlater?bvid=${item.bvid}">在稍后再看列表中查看</a>`, item.aid, undefined, item.bvid),
|
||||
pubDate: parseDate(item.add_at * 1000),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: item.owner.name,
|
||||
|
||||
@@ -3,10 +3,10 @@ import got from '@/utils/got';
|
||||
import utils from './utils';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/weekly/:disableEmbed?',
|
||||
path: '/weekly/:embed?',
|
||||
categories: ['social-media'],
|
||||
example: '/bilibili/weekly',
|
||||
parameters: { disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
parameters: { embed: '默认为开启内嵌视频, 任意值为关闭' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -21,7 +21,7 @@ export const route: Route = {
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const disableEmbed = ctx.req.param('disableEmbed');
|
||||
const embed = !ctx.req.param('embed');
|
||||
|
||||
const status_response = await got({
|
||||
method: 'get',
|
||||
@@ -48,12 +48,7 @@ async function handler(ctx) {
|
||||
description: 'B站每周必看',
|
||||
item: data.map((item) => ({
|
||||
title: item.title,
|
||||
// description: `${weekly_name} ${item.title}<br>${item.rcmd_reason}<br>${!disableEmbed ? `${utils.iframe(item.param)}` : ''}<img src="${item.cover}">`,
|
||||
description: `
|
||||
${weekly_name} ${item.title}<br>
|
||||
${item.rcmd_reason}<br>
|
||||
${disableEmbed ? '' : utils.iframe(item.param)}<img src="${item.cover}">
|
||||
`,
|
||||
description: utils.renderUGCDescription(embed, item.cover, `${weekly_name} ${item.title} - ${item.rcmd_reason}`, item.param, undefined, item.bvid),
|
||||
link: weekly_number > 60 && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.param}`,
|
||||
})),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user