fix(bilibili): 为排行榜获取详细的视频描述和发布时间 (#2883)

This commit is contained in:
zhshch2002
2019-08-20 14:08:21 +08:00
committed by DIYgod
parent e6e7e8cc6b
commit 4ad0862e01
2 changed files with 40 additions and 8 deletions
+5 -8
View File
@@ -1,4 +1,5 @@
const got = require('@/utils/got');
const utils = require('./utils');
module.exports = async (ctx) => {
const rid = ctx.params.rid || '0';
@@ -7,7 +8,7 @@ module.exports = async (ctx) => {
const arc_type1 = arc_type === '0' ? '全部投稿' : '近期投稿';
const rid_1 = ['0', '1', '168', '3', '129', '4', '36', '160', '119', '155', '5', '181'];
const rid_2 = ['全站', '动画', '国创相关', '音乐', '舞蹈', '游戏', '科技', '生活', '鬼畜', '时尚', '娱乐', '影视'];
const rid_i = rid_1.indexOf(arc_type);
const rid_i = rid_1.indexOf(rid + '');
const rid_type = rid_2[rid_i];
const response = await got({
method: 'get',
@@ -27,15 +28,11 @@ module.exports = async (ctx) => {
list = list.concat(list[i].others);
}
}
list = list.map((i) => i.aid);
const resultItems = await utils.ProcessFeed(list, ctx.cache);
ctx.state.data = {
title: `bilibili ${day}日排行榜-${rid_type}-${arc_type1}`,
link: `https://www.bilibili.com/ranking/all/${rid}/0/${day}`,
item: list.map((item) => ({
title: item.title,
description: `作者:${item.author}<br>播放量:${item.play}<br>时长:${item.duration}<br>综合得分:${item.pts}<br>弹幕:${item.video_review}<br><img referrerpolicy="no-referrer" src="${item.pic}">`,
link: `https://www.bilibili.com/video/av${item.aid}`,
author: item.author,
})),
item: resultItems,
};
};
+35
View File
@@ -0,0 +1,35 @@
const got = require('@/utils/got');
async function load(aid) {
const response = await got({
method: 'get',
url: `https://api.bilibili.com/x/article/archives?ids=${aid}`,
});
return response.data;
}
const ProcessFeed = async (list, caches) =>
await Promise.all(
list
.filter(async (aid) => {
const data = await caches.tryGet('av' + aid, async () => await load(aid));
return data.code == 0;
})
.map(async (aid) => {
let data = await caches.tryGet('av' + aid, async () => await load(aid));
data = data.data[aid + ''];
const single = {
title: data.title,
description: data.desc,
pubDate: new Date(data.pubdate * 1000).toUTCString(),
author: data.owner.name,
link: `https://www.bilibili.com/video/av${aid}`,
guid: `https://www.bilibili.com/video/av${aid}`,
};
return Promise.resolve(single);
})
);
module.exports = {
ProcessFeed,
};