fix: douban group
This commit is contained in:
parent
dadac29057
commit
cabcc238bd
|
|
@ -770,7 +770,7 @@ YouTube 官方亦有提供频道 RSS,形如 <https://www.youtube.com/feeds/vid
|
|||
|
||||
### 豆瓣小组
|
||||
|
||||
<Route author="DIYgod" example="/douban/group/camera" path="/douban/group/:groupid" :paramsDesc="['豆瓣小组的 id']"/>
|
||||
<Route author="DIYgod" example="/douban/group/camera" path="/douban/group/:groupid/:type?" :paramsDesc="['豆瓣小组的 id', '缺省 最新,essence 最热,elite 精华']"/>
|
||||
|
||||
### 浏览发现
|
||||
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ router.get('/douban/movie/later', require('./routes/douban/later'));
|
|||
router.get('/douban/movie/ustop', require('./routes/douban/ustop'));
|
||||
router.get('/douban/movie/weekly/:type?', require('./routes/douban/weekly_best'));
|
||||
router.get('/douban/movie/classification/:sort?/:score?/:tags?', require('./routes/douban/classification.js'));
|
||||
router.get('/douban/group/:groupid', require('./routes/douban/group'));
|
||||
router.get('/douban/group/:groupid/:type?', require('./routes/douban/group'));
|
||||
router.get('/douban/explore', require('./routes/douban/explore'));
|
||||
router.get('/douban/music/latest/:area?', require('./routes/douban/latest_music'));
|
||||
router.get('/douban/book/latest', require('./routes/douban/latest_book'));
|
||||
|
|
|
|||
|
|
@ -1,47 +1,48 @@
|
|||
const got = require('../../utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const groupid = ctx.params.groupid;
|
||||
const type = ctx.params.type;
|
||||
|
||||
const url = `https://www.douban.com/group/${groupid}/${type ? `?type=${type}` : ''}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://api.douban.com/v2/group/${groupid}/topics?start=0&count=50`,
|
||||
url,
|
||||
});
|
||||
|
||||
const topics = response.data.topics;
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('.olt tr:not(.th)').slice(0, 30).get();
|
||||
|
||||
// 替换图片到内容中
|
||||
topics.map((topic) => {
|
||||
const { photos = [] } = topic;
|
||||
let { content } = topic;
|
||||
const items = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $1 = $(item);
|
||||
const result = {
|
||||
title: $1.find('.title a').attr('title'),
|
||||
author: $1.find('a').eq(1).text(),
|
||||
link: $1.find('.title a').attr('href'),
|
||||
};
|
||||
return await ctx.cache.tryGet(result.link, async () => {
|
||||
try {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: result.link,
|
||||
});
|
||||
const $ = cheerio.load(detailResponse.data);
|
||||
|
||||
content = content.replace(/ /g, '<br>');
|
||||
topic.content = content.replace(/<图片(\d*)>/g, function () {
|
||||
try {
|
||||
const photo = photos.filter((p) => p.seq_id === arguments[1]);
|
||||
|
||||
if (photo.length > 0) {
|
||||
const src = photo[0].alt;
|
||||
return `<img src='${src}'/><br>`;
|
||||
} else {
|
||||
return '';
|
||||
result.pubDate = $('.create-time').text();
|
||||
result.description = $('.rich-content').html();
|
||||
return result;
|
||||
} catch (error) {
|
||||
return result;
|
||||
}
|
||||
} catch (ex) {
|
||||
return '';
|
||||
}
|
||||
});
|
||||
return topic;
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `豆瓣小组-${groupid}`,
|
||||
link: `https://www.douban.com/group/${groupid}/`,
|
||||
item: topics.map((topic) => ({
|
||||
title: `${topic.title} [来自: ${topic.author.name}]`,
|
||||
author: topic.author.name,
|
||||
pubDate: new Date(topic.updated).toUTCString(),
|
||||
description: topic.content,
|
||||
link: topic.share_url,
|
||||
})),
|
||||
title: `豆瓣小组-${$('h1').text().trim()}`,
|
||||
link: url,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue