feat: add picuki video support (#5471)

This commit is contained in:
hoilc 2020-08-21 05:04:34 +08:00 committed by GitHub
parent 36536ce9e0
commit 0da7051539
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 11 deletions

View File

@ -75,7 +75,7 @@ These feed do not include boosts (a.k.a. reblogs). RSSHub provides a feed for us
### User Profile
<Route author="hoilc" example="/picuki/profile/stefaniejoosten" path="/picuki/profile/:id" :paramsDesc="['Instagram id']" />
<Route author="hoilc" example="/picuki/profile/stefaniejoosten" path="/picuki/profile/:id/:displayVideo?" :paramsDesc="['Instagram id','Default to disable the embedded video, set to any value to enable embedding']" />
## pixiv

View File

@ -363,7 +363,7 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
### 用户
<Route author="hoilc" example="/picuki/profile/stefaniejoosten" path="/picuki/profile/:id" :paramsDesc="['Instagram 用户 id']" radar="1" />
<Route author="hoilc" example="/picuki/profile/stefaniejoosten" path="/picuki/profile/:id/:displayVideo?" :paramsDesc="['Instagram 用户 id','是否显示视频,任意值为是,留空为否']" radar="1" />
## pixiv

View File

@ -3024,7 +3024,7 @@ router.get('/furstar/archive/:lang?', require('./routes/furstar/archive'));
router.get('/bwu/news', require('./routes/universities/bwu/news'));
// Picuki
router.get('/picuki/profile/:id', require('./routes/picuki/profile'));
router.get('/picuki/profile/:id/:displayVideo?', require('./routes/picuki/profile'));
// 新榜
router.get('/newrank/wechat/:wxid', require('./routes/newrank/wechat'));

View File

@ -4,6 +4,7 @@ const chrono = require('chrono-node');
module.exports = async (ctx) => {
const id = ctx.params.id;
const displayVideo = ctx.params.displayVideo ? true : false;
const url = `https://www.picuki.com/profile/${id}`;
@ -16,13 +17,16 @@ module.exports = async (ctx) => {
const list = $('ul.box-photos [data-s="media"]').get();
ctx.state.data = {
title: `${profile_name} (@${id}) - Picuki`,
link: url,
image: profile_img,
description: profile_description,
item: list.map((post) => {
async function getVideo(url) {
const response = await got.get(url);
const $ = cheerio.load(response.data);
return $('.single-photo').html();
}
const items = await Promise.all(
list.map(async (post) => {
post = $(post);
const isVideo = post.find('.video-icon').length !== 0 && displayVideo;
const post_image = post.find('.post-image').attr('src');
const post_description = post.find('.photo-description').text().trim();
const post_link = post.find('.photo > a').attr('href');
@ -30,10 +34,18 @@ module.exports = async (ctx) => {
return {
title: post_description || 'Untitled',
author: `@${id}`,
description: `<img src="${post_image}">` + (post_description.length > 100 ? `<p>${post_description}</p>` : ''),
description: (isVideo ? await getVideo(post_link) : `<img src="${post_image}">`) + (post_description.length > 100 ? `<p>${post_description}</p>` : ''),
link: post_link,
pubDate: post_time ? chrono.parseDate(post_time.text()) : new Date(),
};
}),
})
);
ctx.state.data = {
title: `${profile_name} (@${id}) - Picuki`,
link: url,
image: profile_img,
description: profile_description,
item: items,
};
};