mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-15 01:30:33 +08:00
feat: add 即刻 (#4967)
This commit is contained in:
@@ -688,6 +688,26 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
|
|||||||
|
|
||||||
<Route author="LogicJake" example="/vocus/user/tsetyan" path="/vocus/user/:id" :paramsDesc="['用户 id,可在用户主页的 URL 找到']"/>
|
<Route author="LogicJake" example="/vocus/user/tsetyan" path="/vocus/user/:id" :paramsDesc="['用户 id,可在用户主页的 URL 找到']"/>
|
||||||
|
|
||||||
|
## 即刻
|
||||||
|
|
||||||
|
### 圈子
|
||||||
|
|
||||||
|
<Route author="DIYgod prnake" example="/jike/topic/556688fae4b00c57d9dd46ee" path="/jike/topic/:id" :paramsDesc="['圈子 id, 可在即刻 web 端圈子页或 APP 分享出来的圈子页 URL 中找到']" anticrawler="1"/>
|
||||||
|
|
||||||
|
::: tip 提示
|
||||||
|
|
||||||
|
部分圈子如 `一觉醒来发生了什么: 553870e8e4b0cafb0a1bef68` 提供纯文字内容,<a href="#/jike/topic/text/:id">圈子 - 纯文字 /jike/topic/text/:id</a> 可能会提供更好的体验.
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
### 圈子 - 纯文字
|
||||||
|
|
||||||
|
<Route author="HenryQW" example="/jike/topic/text/553870e8e4b0cafb0a1bef68" path="/jike/topic/text/:id" :paramsDesc="['圈子 id, 可在即刻 web 端圈子页或 APP 分享出来的圈子页 URL 中找到']" anticrawler="1"/>
|
||||||
|
|
||||||
|
### 用户动态
|
||||||
|
|
||||||
|
<Route author="DIYgod prnake" example="/jike/user/3EE02BC9-C5B3-4209-8750-4ED1EE0F67BB" path="/jike/user/:id" :paramsDesc="['用户 id, 可在即刻 web 端用户页 URL 中找到']" anticrawler="1"/>
|
||||||
|
|
||||||
## 简书
|
## 简书
|
||||||
|
|
||||||
### 首页
|
### 首页
|
||||||
|
|||||||
@@ -2853,4 +2853,9 @@ router.get('/futunn/highlights', require('./routes/futunn/highlights'));
|
|||||||
// 外接大脑
|
// 外接大脑
|
||||||
router.get('/waijiedanao/article/:caty', require('./routes/waijiedanao/article'));
|
router.get('/waijiedanao/article/:caty', require('./routes/waijiedanao/article'));
|
||||||
|
|
||||||
|
// 即刻
|
||||||
|
router.get('/jike/topic/:id', require('./routes/jike/topic'));
|
||||||
|
router.get('/jike/topic/text/:id', require('./routes/jike/topicText'));
|
||||||
|
router.get('/jike/user/:id', require('./routes/jike/user'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
135
lib/routes/jike/common.js
Normal file
135
lib/routes/jike/common.js
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
const url = require('url');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
emptyResponseCheck: (ctx, data) => {
|
||||||
|
if (data.length === 0) {
|
||||||
|
ctx.state.data = {
|
||||||
|
title: '主题 ID 不存在,或该主题暂无内容',
|
||||||
|
};
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
topicDataHanding: (data) =>
|
||||||
|
data.posts.map((item) => {
|
||||||
|
let audioName, videoName, linkName;
|
||||||
|
|
||||||
|
// 获取纯文字内容 和 即刻原文链接
|
||||||
|
let content, link;
|
||||||
|
switch (item.type) {
|
||||||
|
case 'ORIGINAL_POST':
|
||||||
|
content = item.content;
|
||||||
|
link = `https://m.okjike.com/originalPosts/${item.id}`;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* case 'QUESTION':
|
||||||
|
content = item.title;
|
||||||
|
link = `https://m.okjike.com/questions/${item.id}`;
|
||||||
|
break;
|
||||||
|
case 'OFFICIAL_MESSAGE':
|
||||||
|
content = item.content;
|
||||||
|
link = `https://web.okjike.com/message-detail/${item.id}/officialMessage`;
|
||||||
|
break;*/
|
||||||
|
default:
|
||||||
|
content = '未知类型,请前往GitHub提交issue';
|
||||||
|
link = 'https://github.com/DIYgod/RSSHub/issues';
|
||||||
|
}
|
||||||
|
|
||||||
|
// rss内容
|
||||||
|
let description = '';
|
||||||
|
|
||||||
|
if (item.linkInfo) {
|
||||||
|
const linkUrl = item.linkInfo.originalLinkUrl || item.linkInfo.linkUrl;
|
||||||
|
|
||||||
|
// 对于即刻抓取的微信公众号文章 特殊处理
|
||||||
|
// 此时 Rss原文链接 变为 微信公众号链接
|
||||||
|
if (url.parse(linkUrl).host === 'mp.weixin.qq.com') {
|
||||||
|
link = linkUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. 音频
|
||||||
|
const audioObject = item.linkInfo.audio || item.audio;
|
||||||
|
if (audioObject) {
|
||||||
|
const audioImage = audioObject.image.picUrl || audioObject.image.thumbnailUrl;
|
||||||
|
const audioLink = linkUrl;
|
||||||
|
const audioTitle = audioObject.title;
|
||||||
|
const audioAuthor = audioObject.author;
|
||||||
|
audioName = `${audioTitle} - ${audioAuthor}`;
|
||||||
|
description += `
|
||||||
|
<img referrerpolicy="no-referrer" src="${audioImage}"/>
|
||||||
|
<a href="${audioLink}">${audioName}</a>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 视频
|
||||||
|
const videoObject = item.linkInfo.video || item.video;
|
||||||
|
if (videoObject) {
|
||||||
|
const videoImage = videoObject.image.picUrl || videoObject.image.thumbnailUrl;
|
||||||
|
const videoLink = linkUrl;
|
||||||
|
const videoDuration = Math.floor(videoObject.duration / 60000);
|
||||||
|
videoName = item.linkInfo.title;
|
||||||
|
description += `
|
||||||
|
<img referrerpolicy="no-referrer" src="${videoImage}"/>
|
||||||
|
<a href="${videoLink}">${videoName || '观看视频'} - 约${videoDuration}分钟</a>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 链接
|
||||||
|
if (!audioObject && !videoObject && linkUrl) {
|
||||||
|
// 部分链接有标题
|
||||||
|
linkName = item.linkInfo.title;
|
||||||
|
const linkTitle = linkName || '访问原文';
|
||||||
|
// 部分链接有缩略图
|
||||||
|
const linkImage = item.linkInfo.pictureUrl;
|
||||||
|
const imageTag = `<img referrerpolicy="no-referrer" src="${linkImage}"/>`;
|
||||||
|
description += `
|
||||||
|
${linkImage ? imageTag : ''}
|
||||||
|
<a href="${linkUrl}">${linkTitle}</a>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 文字内容
|
||||||
|
description += `<br/>${content}`;
|
||||||
|
|
||||||
|
// 5. 图片
|
||||||
|
if (item.pictures) {
|
||||||
|
item.pictures.forEach((pic) => {
|
||||||
|
if (pic.format === 'gif') {
|
||||||
|
description += `<img referrerpolicy="no-referrer" src="${pic.picUrl.split('?imageMogr2/')[0]}"></picture>`;
|
||||||
|
} else {
|
||||||
|
// jpeg, bmp, png, gif, webp
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
|
||||||
|
let type = 'jpeg';
|
||||||
|
switch (pic.format) {
|
||||||
|
case 'bmp':
|
||||||
|
type = 'bmp';
|
||||||
|
break;
|
||||||
|
case 'png':
|
||||||
|
type = 'png';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const imgUrl = pic.picUrl.match(/\.[a-z0-9]+?\?imageMogr2/) ? pic.picUrl.split('?imageMogr2/')[0] : pic.picUrl.replace(/thumbnail\/.+/, '');
|
||||||
|
description += `<br/><picture><source srcset="${
|
||||||
|
pic.picUrl.split('/thumbnail/')[0]
|
||||||
|
}/strip/format/webp" type="image/webp"><source srcset="${imgUrl}" type="image/${type}"><img referrerpolicy="no-referrer" src="${imgUrl}"></picture>`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// rss标题
|
||||||
|
// 优先将音频和视频名作为标题
|
||||||
|
// 其次将正文内容作为标题
|
||||||
|
// 若都没有 则是推送型消息,将连接标题作为主题
|
||||||
|
// “无题” fallback
|
||||||
|
const title = audioName || videoName || content || linkName || '无题';
|
||||||
|
|
||||||
|
return {
|
||||||
|
title,
|
||||||
|
description: description.replace(new RegExp('\n', 'g'), '<br/>'),
|
||||||
|
pubDate: new Date(item.createdAt).toUTCString(),
|
||||||
|
link: link,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
65
lib/routes/jike/topic.js
Normal file
65
lib/routes/jike/topic.js
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const common = require('./common');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const dayjs = require('dayjs');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const id = ctx.params.id;
|
||||||
|
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: `https://m.okjike.com/topics/${id}`,
|
||||||
|
headers: {
|
||||||
|
Referer: `https://m.okjike.com/topics/${id}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const html = response.data;
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
const raw = $('[type = "application/json"]').html();
|
||||||
|
const data = JSON.parse(raw).props.pageProps;
|
||||||
|
|
||||||
|
if (common.emptyResponseCheck(ctx, data)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const topic = data.topic;
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `${topic.content} - 即刻圈子`,
|
||||||
|
link: `https://m.okjike.com/topics/${id}`,
|
||||||
|
description: topic.briefIntro,
|
||||||
|
image: topic.squarePicture.picUrl || topic.squarePicture.middlePicUrl || topic.squarePicture.thumbnailUrl,
|
||||||
|
item: common.topicDataHanding(data),
|
||||||
|
};
|
||||||
|
if (id === '553870e8e4b0cafb0a1bef68' || id === '55963702e4b0d84d2c30ce6f') {
|
||||||
|
const promises = ctx.state.data.item.map(async (one) => {
|
||||||
|
const item = { ...one };
|
||||||
|
const regResult = /https:\/\/www.okjike.com\/medium\/[a-zA-Z0-9]*/.exec(item.description);
|
||||||
|
if (regResult) {
|
||||||
|
const newsUrl = regResult[0];
|
||||||
|
const cache = await ctx.cache.get(newsUrl);
|
||||||
|
if (cache) {
|
||||||
|
item.description = cache;
|
||||||
|
} else {
|
||||||
|
const { data } = await got.get(newsUrl);
|
||||||
|
const $ = cheerio.load(data);
|
||||||
|
const upper = $('ul.main > li.item');
|
||||||
|
const links = upper.find('a').map((_, ele) => $(ele).attr('href'));
|
||||||
|
const texts = upper.find('span.text').map((_, ele) => $(ele).text());
|
||||||
|
let description = '';
|
||||||
|
for (let i = 0; i < links.length; i++) {
|
||||||
|
description += `${i + 1}、<a href="${links[i]}">${texts[i]}</a><br/>`;
|
||||||
|
}
|
||||||
|
if (description) {
|
||||||
|
item.description = description;
|
||||||
|
await ctx.cache.set(newsUrl, description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item.title = `${topic.content} ${dayjs(new Date(one.pubDate)).format('MM月DD日')}`;
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
|
||||||
|
ctx.state.data.item = await Promise.all(promises);
|
||||||
|
}
|
||||||
|
};
|
||||||
42
lib/routes/jike/topicText.js
Normal file
42
lib/routes/jike/topicText.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const dayjs = require('dayjs');
|
||||||
|
const common = require('./common');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const id = ctx.params.id;
|
||||||
|
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: `https://m.okjike.com/topics/${id}`,
|
||||||
|
headers: {
|
||||||
|
Referer: `https://m.okjike.com/topics/${id}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const html = response.data;
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
const raw = $('[type = "application/json"]').html();
|
||||||
|
const data = JSON.parse(raw).props.pageProps;
|
||||||
|
|
||||||
|
if (common.emptyResponseCheck(ctx, data)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = data.topic.content;
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `${title} - 即刻`,
|
||||||
|
link: `https://m.okjike.com/topics/${id}`,
|
||||||
|
description: `${title} - 即刻`,
|
||||||
|
item: data.posts.map((item) => {
|
||||||
|
const date = new Date(item.createdAt);
|
||||||
|
return {
|
||||||
|
title: `${title} ${dayjs(date).format('MM月DD日')}`,
|
||||||
|
description: item.content.replace(new RegExp('\n', 'g'), '<br />'),
|
||||||
|
pubDate: date.toUTCString(),
|
||||||
|
link: `https://m.okjike.com/originalPosts/${item.id}`,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
};
|
||||||
112
lib/routes/jike/user.js
Normal file
112
lib/routes/jike/user.js
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const id = ctx.params.id;
|
||||||
|
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: `https://m.okjike.com/users/${id}`,
|
||||||
|
headers: {
|
||||||
|
Referer: `https://m.okjike.com/users/${id}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const html = response.data;
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
const raw = $('[type = "application/json"]').html();
|
||||||
|
const data = JSON.parse(raw).props.pageProps;
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `${data.user.screenName}的即刻动态`,
|
||||||
|
link: `https://m.okjike.com/users/${id}`,
|
||||||
|
image: data.user.avatarImage.picUrl,
|
||||||
|
item: data.posts.map((item) => {
|
||||||
|
const typeMap = {
|
||||||
|
ORIGINAL_POST: '发布',
|
||||||
|
REPOST: '转发',
|
||||||
|
ANSWER: '回答',
|
||||||
|
QUESTION: '提问',
|
||||||
|
PERSONAL_UPDATE: '创建新主题',
|
||||||
|
};
|
||||||
|
|
||||||
|
const linkMap = {
|
||||||
|
ORIGINAL_POST: `https://m.okjike.com/originalPosts/${item.id}`,
|
||||||
|
REPOST: `https://m.okjike.com/reposts/${item.id}`,
|
||||||
|
// OFFICIAL_MESSAGE: `https://m.okjike.com/originalPosts/${item.id}`,
|
||||||
|
// ANSWER: `https://m.okjike.com/answer/${item.id}`,
|
||||||
|
// QUESTION: `https://m.okjike.com/originalPosts/${item.id}`,
|
||||||
|
// PERSONAL_UPDATE: `https://m.okjike.com/topic/${item.id}${item.topic && item.topic.id}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
let linkTemplate = '';
|
||||||
|
if (item.linkInfo && item.linkInfo.linkUrl) {
|
||||||
|
linkTemplate = `<a href="${item.linkInfo.linkUrl}">${item.linkInfo.title}</a><br>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let imgTemplate = '';
|
||||||
|
item.pictures &&
|
||||||
|
item.pictures.forEach((item) => {
|
||||||
|
imgTemplate += `<img referrerpolicy="no-referrer" src="${item.picUrl}"><br>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
let content = item.content || (item.linkInfo && item.linkInfo.title) || (item.question && item.question.title) || item.title || '';
|
||||||
|
|
||||||
|
let shortenTitle = '一条动态';
|
||||||
|
if (content) {
|
||||||
|
shortenTitle = content.length > 75 ? `${content.substr(0, 75)}...` : content;
|
||||||
|
content = `${content}<br><br>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.type === 'REPOST') {
|
||||||
|
const screenNameTemplate = item.target.user ? `<a href="https://m.okjike.com/users/${item.target.user.username}" target="_blank">@${item.target.user.screenName}</a>` : '';
|
||||||
|
|
||||||
|
let repostImgTemplate = '';
|
||||||
|
item.target.pictures &&
|
||||||
|
item.target.pictures.forEach((item) => {
|
||||||
|
repostImgTemplate += `<br><img referrerpolicy="no-referrer" src="${item.thumbnailUrl}">`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const repostContent = `转发 ${screenNameTemplate}: ${item.target.content}${repostImgTemplate}`;
|
||||||
|
content = `${content}${repostContent}`.replace(/\n|\r/g, '<br>');
|
||||||
|
}
|
||||||
|
// 部分功能未知
|
||||||
|
/* else if (item.type === 'ANSWER') {
|
||||||
|
let answerTextTemplate = '';
|
||||||
|
let answerImgTemplate = '';
|
||||||
|
let answerImgKeys = [];
|
||||||
|
item.richtextContent.blocks &&
|
||||||
|
item.richtextContent.blocks.forEach((item) => {
|
||||||
|
if (item.entityRanges.length && item.text === '[图片]') {
|
||||||
|
answerImgKeys = [...answerImgKeys, ...Object.keys(item.entityRanges)];
|
||||||
|
} else {
|
||||||
|
answerTextTemplate += item.text;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (answerImgKeys.length) {
|
||||||
|
answerImgKeys.forEach((key) => {
|
||||||
|
const entity = item.richtextContent.entityMap[key];
|
||||||
|
if (entity.type.toUpperCase() === 'IMAGE') {
|
||||||
|
answerImgTemplate += `<br><img referrerpolicy="no-referrer" src="${entity.data.pictureUrl.middlePicUrl}">`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const answerContent = `回答: ${answerTextTemplate}${answerImgTemplate}`;
|
||||||
|
content = `${content}${answerContent}`.replace(/\n|\r/g, '<br>');
|
||||||
|
} else if (item.type === 'QUESTION') {
|
||||||
|
content = `在主题 <a href="https://web.okjike.com/topic/${item.topic.id}/official" target="_blank">${item.topic.content}</a> 提出了一个问题:<br><br>${content}`;
|
||||||
|
} else if (item.type === 'PERSONAL_UPDATE') {
|
||||||
|
shortenTitle = item.topic.content;
|
||||||
|
content = `<img referrerpolicy="no-referrer" src="${item.topic.squarePicture.picUrl}"> 主题简介:<br>${item.topic.briefIntro.replace(/(?:\r\n|\r|\n)/g, '<br>')}`;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: `${typeMap[item.type]}了: ${shortenTitle}`,
|
||||||
|
description: `${content}${linkTemplate}${imgTemplate}`,
|
||||||
|
pubDate: new Date(item.createdAt).toUTCString(),
|
||||||
|
link: `${linkMap[item.type]}`,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user