feat(route): E站增加封面图嵌入RSS和封面图替换为代理网址的功能 (#9344)

* 增加封面图嵌入RSS的功能

* 增加EH封面图代理的功能

* 改用URLSearchParams代替querystring
增加对"Minimal", "Minimal+" and "Extended"页面模式的支持

* fix: matching logic

* refactor: migrate to v2

* docs: add missing description of EH_IMG_PROXY

* docs: remove ignoring EH_SK

Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
Howard Yin
2022-04-21 23:03:55 +08:00
committed by GitHub
co-authored by TonyRL
parent 9d9926d0bf
commit 67d87e2eea
13 changed files with 134 additions and 40 deletions
+2 -1
View File
@@ -532,7 +532,8 @@ See docs of the specified route and `lib/config.js` for detailed information.
- `EH_IPB_MEMBER_ID`: The value of `ipb_member_id` in the cookie header after logging in E-Hentai
- `EH_IPB_PASS_HASH`: The value of `ipb_pass_hash` in the cookie header after logging in E-Hentai
- `EH_SK`: The value of `sk` in the cookie header after logging in E-Hentai
- `EH_IGNEOUS`: The value of `igneous` in the cookie header after logging in ExHentai. If this value is set, RSS will be generated from ExHentai, `EH_SK` will be ignored.
- `EH_IGNEOUS`: The value of `igneous` in the cookie header after logging in ExHentai. If this value is set, RSS will be generated from ExHentai
- `EH_IMG_PROXY`: Cover proxy address. If this is set, the link to the cover image will be replaced with this value at the beginning. When using ExHentai, the cover image requires cookies to access it, so you can use this with a cookie-added proxy server to access the cover image without cookies in some readers.
- GitHub: [Access Token application](https://github.com/settings/tokens)
+21
View File
@@ -116,6 +116,27 @@ pageClass: routes
<RouteEn name="Daily Strip" author="Maecenas" example="/dilbert/strip" path="/dilbert/strip"/>
## E-Hentai
For RSS content, specify options in the `routeParams` parameter in query string format to control additional functionality
| Key | Meaning | Accepted keys | Default value |
| ----------- | -------------------------------------------------------------------------------- | -------------- | ------------- |
| bittorrent | Whether include a link to the latest torrent | 0/1/true/false | false |
| embed_thumb | Whether the cover image is embedded in the RSS feed rather than given as a link | 0/1/true/false | false |
### Favorites
<RouteEn author="yindaheng98" example="/ehentai/favorites/0/posted/1" path="/ehentai/favorites/:favcat?/:order?/:page?/:routeParams?" :paramsDesc="['Favorites folder number','`posted`(Sort by gallery release time) , `favorited`(Sort by time added to favorites)', 'Page number', 'Additional parameters, see the table above']" anticrawler="1" supportBT="1" />
### Tag
<RouteEn author="yindaheng98" example="/ehentai/tag/language:chinese/1" path="/ehentai/tag/:tag/:page?/:routeParams?" :paramsDesc="['Tag', 'Page number', 'Additional parameters, see the table above']" anticrawler="1" supportBT="1" />
### Search
<RouteEn author="yindaheng98" example="/ehentai/search/f_search=artist%3Amana%24/1" path="/ehentai/search/:params?/:page?/:routeParams?" :paramsDesc="['Search parameters. You can copy the content after `https://e-hentai.org/?`', 'Page number', 'Additional parameters, see the table above']" anticrawler="1" supportBT="1" />
## Elite Babes
### Home
+2 -1
View File
@@ -563,7 +563,8 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行
- `EH_IPB_MEMBER_ID`: E-Hentai 账户登录后 cookie 的 `ipb_member_id` 值
- `EH_IPB_PASS_HASH`: E-Hentai 账户登录后 cookie 的 `ipb_pass_hash` 值
- `EH_SK`: E-Hentai 账户登录后 cookie 中的`sk`值
- `EH_IGNEOUS`: ExHentai 账户登录后 cookie 中的`igneous`值。若设置此值,RSS 数据将全部从里站获取,`EH_SK`将被忽略
- `EH_IGNEOUS`: ExHentai 账户登录后 cookie 中的`igneous`值。若设置此值,RSS 数据将全部从里站获取
- `EH_IMG_PROXY`: 封面代理访问地址。若设置此值,封面图链接将被替换为以此值开头。使用ExHentai时,封面图需要有Cookie才能访问,在一些阅读软件上没法显示封面,可以使用此值搭配一个加Cookie的代理服务器实现阅读软件无Cookie获取封面图。
- GitHub 全部路由:[申请地址](https://github.com/settings/tokens)
+10 -3
View File
@@ -146,17 +146,24 @@ pageClass: routes
## E-Hentai
对于 RSS 内容,在 `routeParams` 参数中以 query string 格式指定选项,可以控制额外的功能
| 键 | 含义 | 接受的值 | 默认值 |
| ----------- | -------------------------- | -------------- | ----- |
| bittorrent | 是否包含最新种子的链接 | 0/1/true/false | false |
| embed_thumb | 是否将封面图片嵌入 RSS 中而不是以链接的形式给出 | 0/1/true/false | false |
### 收藏
<Route author="Howard Yin" example="/ehentai/favorites/0/posted" path="/ehentai/favorites/:favcat?/:order?/:page?/:bittorrent?" :paramsDesc="['收藏夹编号,可选','顺序,可选:posted-按画廊发布时间排序,favorited-按添加收藏的时间排序', '爬获取第多少页的数据', '是否获取种子链接']" anticrawler="1" supportBT="1" />
<Route author="yindaheng98" example="/ehentai/favorites/0/posted/1" path="/ehentai/favorites/:favcat?/:order?/:page?/:routeParams?" :paramsDesc="['收藏夹编号','顺序:posted-按画廊发布时间排序,favorited-按添加收藏的时间排序', '爬获取第多少页的数据', '额外参数;请参阅上面的说明和表格']" anticrawler="1" supportBT="1" />
### 标签
<Route author="Howard Yin" example="/ehentai/tag/language:chinese/1" path="/ehentai/tag/:tag/:page?/:bittorrent?" :paramsDesc="['标签', '爬获取第多少页的数据', '是否获取种子链接']" anticrawler="1" supportBT="1" />
<Route author="yindaheng98" example="/ehentai/tag/language:chinese/1" path="/ehentai/tag/:tag/:page?/:routeParams?" :paramsDesc="['标签', '爬获取第多少页的数据', '额外参数;请参阅上面的说明和表格']" anticrawler="1" supportBT="1" />
### 搜索
<Route author="Howard Yin" example="/ehentai/search/:params?/:page?" path="/ehentai/search/:params?/:page?/:bittorrent?" :paramsDesc="['用于搜索的关键词。可在原网站搜索后复制 `https://e-hentai.org/?` 后面的内容', '爬获取第多少页的数据', '是否获取种子链接']" anticrawler="1" supportBT="1" />
<Route author="yindaheng98" example="/ehentai/search/f_search=artist%3Amana%24/1" path="/ehentai/search/:params?/:page?/:routeParams?" :paramsDesc="['用于搜索的关键词。可在原网站搜索后复制 `https://e-hentai.org/?` 后面的内容', '爬获取第多少页的数据', '额外参数;请参阅上面的说明和表格']" anticrawler="1" supportBT="1" />
## Elite Babes
+1
View File
@@ -128,6 +128,7 @@ const calculateValue = () => {
ipb_pass_hash: envs.EH_IPB_PASS_HASH,
sk: envs.EH_SK,
igneous: envs.EH_IGNEOUS,
img_proxy: envs.EH_IMG_PROXY,
},
email: {
config: email_config,
+4 -4
View File
@@ -3937,10 +3937,10 @@ router.get('/tongli/news/:type', lazyloadRouteHandler('./routes/tongli/news'));
// OR
router.get('/or/:id?', lazyloadRouteHandler('./routes/or'));
// e-hentai
router.get('/ehentai/favorites/:favcat?/:order?/:page?/:bittorrent?', lazyloadRouteHandler('./routes/ehentai/favorites'));
router.get('/ehentai/search/:params?/:page?/:bittorrent?', lazyloadRouteHandler('./routes/ehentai/search'));
router.get('/ehentai/tag/:tag/:page?/:bittorrent?', lazyloadRouteHandler('./routes/ehentai/tag'));
// e-hentai migrated to v2
// router.get('/ehentai/favorites/:favcat?/:order?/:page?/:routeParams?', lazyloadRouteHandler('./routes/ehentai/favorites'));
// router.get('/ehentai/search/:params?/:page?/:routeParams?', lazyloadRouteHandler('./routes/ehentai/search'));
// router.get('/ehentai/tag/:tag/:page?/:routeParams?', lazyloadRouteHandler('./routes/ehentai/tag'));
// 字型故事
router.get('/fontstory', lazyloadRouteHandler('./routes/fontstory/tw'));
+21 -3
View File
@@ -6,19 +6,37 @@ module.exports = {
title: '分类',
docs: 'https://docs.rsshub.app/multimedia.html#e-hentai-fen-lei',
source: ['/:category', '/'],
target: '/e-hentai/category/:category?',
target: '/e-hentai/category/:category',
},
{
title: '收藏',
docs: 'https://docs.rsshub.app/picture.html#e-hentai',
source: ['/favorites.php', '/'],
target: (_params, url) => `/ehentai/favorites/${new URL(url).searchParams.get('favcat')}`,
},
{
title: '标签',
docs: 'https://docs.rsshub.app/multimedia.html#e-hentai-biao-qian',
source: ['/tag/:tag', '/'],
target: '/e-hentai/tag/:tag?',
target: '/e-hentai/tag/:tag',
},
{
title: '标签',
docs: 'https://docs.rsshub.app/picture.html#e-hentai',
source: ['/tag/:tag', '/'],
target: '/ehentai/tag/:tag',
},
{
title: '搜索',
docs: 'https://docs.rsshub.app/multimedia.html#e-hentai-sou-suo',
source: ['/:keyword', '/'],
target: '/e-hentai/search/:keyword?',
target: '/e-hentai/search/:keyword',
},
{
title: '搜索',
docs: 'https://docs.rsshub.app/picture.html#e-hentai',
source: ['/'],
target: (_params, url) => `/ehentai/search/${new URL(url).searchParams.get('f_search')}`,
},
],
},
@@ -1,14 +1,16 @@
const got = require('@/utils/got');
const logger = require('@/utils/logger');
const cheerio = require('cheerio');
const path = require('path');
const config = require('@/config').value.ehentai;
const headers = {};
const has_cookie = config.ipb_member_id && config.ipb_pass_hash && (config.sk || config.igneous);
const has_cookie = config.ipb_member_id && config.ipb_pass_hash && config.sk;
const from_ex = has_cookie && config.igneous;
if (has_cookie) {
if (from_ex) {
const { ipb_member_id, ipb_pass_hash, igneous } = config;
headers.cookie = `ipb_member_id=${ipb_member_id};ipb_pass_hash=${ipb_pass_hash};igneous=${igneous}`;
const { ipb_member_id, ipb_pass_hash, sk, igneous } = config;
headers.cookie = `ipb_member_id=${ipb_member_id};ipb_pass_hash=${ipb_pass_hash};sk=${sk};igneous=${igneous}`;
} else {
const { ipb_member_id, ipb_pass_hash, sk } = config;
headers.cookie = `ipb_member_id=${ipb_member_id};ipb_pass_hash=${ipb_pass_hash};sk=${sk}`;
@@ -23,26 +25,53 @@ function ehgot(url) {
}
}
async function parsePage(cache, data, get_bittorrent = false) {
function ehgot_thumb(cache, thumb_url) {
return cache.tryGet(thumb_url, async () => {
try {
const buffer = await got({ method: 'get', url: thumb_url, headers });
const data = new Buffer.from(buffer.rawBody).toString('base64');
const ext = path.extname(thumb_url).slice(1);
return `data:image/${ext};base64,${data}`;
} catch (e) {
logger.warn('Cannot download thumbnail: ' + thumb_url, e);
return thumb_url;
}
});
}
async function parsePage(cache, data, get_bittorrent = false, embed_thumb = false) {
const $ = cheerio.load(data);
const table = $('table[class="itg gltc"] tbody');
const table = $('table[class^="itg glt"] tbody');
if (!table) {
return [];
}
async function parseTableRow(cache, element) {
const el = $(element);
const el_a = el.find('td[class="gl3c glname"] a');
const el_img = el.find('td.gl2c div.glthumb div img');
const title = el_a.find('div.glink').html();
const thumbnail = el_img.attr('data-src') ? el_img.attr('data-src') : el_img.attr('src');
const description = `<img src='${thumbnail}' alt='thumbnail'>`;
const title = el.find('div.glink').html();
const pubDate = el.find('div[id^="posted_"]').html();
// match "Minimal", "Minimal+" and "Compact"
let el_a = el.find('td[class^="gl3"] a');
let el_img = el.find('td[class^=gl2] div.glthumb div img');
// if not, match "Extended"
if (!(el_a.length && el_img.length)) {
el_a = el.find('td[class^="gl1"] a');
el_img = el_a.find('img');
}
const link = el_a.attr('href');
let thumbnail = el_img.attr('data-src') ? el_img.attr('data-src') : el_img.attr('src');
if (config.img_proxy && thumbnail) {
const url = new URL(thumbnail);
thumbnail = config.img_proxy + url.pathname + url.search;
}
if (embed_thumb && thumbnail) {
thumbnail = await ehgot_thumb(cache, thumbnail);
}
const description = `<img src='${thumbnail}' alt='thumbnail'>`;
if (title && link) {
const item = { title, description, pubDate, link };
if (get_bittorrent) {
const el_down = el.find('td.gl2c div div.gldown');
const el_down = el.find('div.gldown');
const bittorrent_page_url = el_down.find('a').attr('href');
if (bittorrent_page_url) {
const bittorrent_url = await getBittorrent(cache, bittorrent_page_url);
@@ -113,31 +142,31 @@ function updateBittorrent_url(cache, items) {
return items;
}
async function gatherItemsByPage(cache, url, get_bittorrent = false) {
async function gatherItemsByPage(cache, url, get_bittorrent = false, embed_thumb = false) {
const response = await ehgot(url);
const items = await parsePage(cache, response.data, get_bittorrent);
const items = await parsePage(cache, response.data, get_bittorrent, embed_thumb);
return updateBittorrent_url(cache, items);
}
async function getFavoritesItems(cache, page, favcat, inline_set, get_bittorrent = false) {
async function getFavoritesItems(cache, page, favcat, inline_set, get_bittorrent = false, embed_thumb = false) {
const response = await ehgot(`favorites.php?favcat=${favcat}&inline_set=${inline_set}`);
if (parseInt(page) === 0) {
const items = await parsePage(cache, response.data, get_bittorrent);
const items = await parsePage(cache, response.data, get_bittorrent, embed_thumb);
return updateBittorrent_url(cache, items);
}
return gatherItemsByPage(cache, `favorites.php?page=${page}&favcat=${favcat}`, get_bittorrent);
return gatherItemsByPage(cache, `favorites.php?page=${page}&favcat=${favcat}`, get_bittorrent, embed_thumb);
}
function getSearchItems(cache, params, page = undefined, get_bittorrent = false) {
function getSearchItems(cache, params, page = undefined, get_bittorrent = false, embed_thumb = false) {
if (page) {
return gatherItemsByPage(cache, `?page=${page}&${params}`, get_bittorrent);
return gatherItemsByPage(cache, `?page=${page}&${params}`, get_bittorrent, embed_thumb);
} else {
return gatherItemsByPage(cache, `?${params}`, get_bittorrent);
return gatherItemsByPage(cache, `?${params}`, get_bittorrent, embed_thumb);
}
}
function getTagItems(cache, tag, page, get_bittorrent = false) {
return gatherItemsByPage(cache, `tag/${tag}/${page}`, get_bittorrent);
function getTagItems(cache, tag, page, get_bittorrent = false, embed_thumb = false) {
return gatherItemsByPage(cache, `tag/${tag}/${page}`, get_bittorrent, embed_thumb);
}
module.exports = { getFavoritesItems, getSearchItems, getTagItems, has_cookie, from_ex };
@@ -6,9 +6,11 @@ module.exports = async (ctx) => {
}
const favcat = ctx.params.favcat ? parseInt(ctx.params.favcat) : 0;
const page = ctx.params.page ? parseInt(ctx.params.page) : 0;
const bittorrent = ctx.params.bittorrent || false;
const routeParams = new URLSearchParams(ctx.params.routeParams);
const bittorrent = routeParams.get('bittorrent') || false;
const embed_thumb = routeParams.get('embed_thumb') || false;
const inline_set = ctx.params.order === 'posted' ? 'fs_p' : 'fs_f';
const items = await EhAPI.getFavoritesItems(ctx.cache, page, favcat, inline_set, bittorrent);
const items = await EhAPI.getFavoritesItems(ctx.cache, page, favcat, inline_set, bittorrent, embed_thumb);
if (EhAPI.from_ex) {
ctx.state.data = {
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
'/favorites/:favcat?/:order?/:page?/:routeParams?': ['yindaheng98'],
'/search/:params?/:page?/:routeParams?': ['yindaheng98'],
'/tag/:tag/:page?/:routeParams?': ['yindaheng98'],
};
+5
View File
@@ -0,0 +1,5 @@
module.exports = (router) => {
router.get('/favorites/:favcat?/:order?/:page?/:routeParams?', require('./favorites'));
router.get('/search/:params?/:page?/:routeParams?', require('./search'));
router.get('/tag/:tag/:page?/:routeParams?', require('./tag'));
};
@@ -3,14 +3,16 @@ const EhAPI = require('./ehapi');
module.exports = async (ctx) => {
const page = ctx.params.page;
let params = ctx.params.params;
const bittorrent = ctx.params.bittorrent || false;
const routeParams = new URLSearchParams(ctx.params.routeParams);
const bittorrent = routeParams.get('bittorrent') || false;
const embed_thumb = routeParams.get('embed_thumb') || false;
let items;
if (page) {
// 如果定义了page,就要覆盖params
params = params.replace(/&*page=[^&]$/, '').replace(/page=[^&]&/, '');
items = await EhAPI.getSearchItems(ctx.cache, params, parseInt(page), bittorrent);
items = await EhAPI.getSearchItems(ctx.cache, params, parseInt(page), bittorrent, embed_thumb);
} else {
items = await EhAPI.getSearchItems(ctx.cache, params, undefined, bittorrent);
items = await EhAPI.getSearchItems(ctx.cache, params, undefined, bittorrent, embed_thumb);
}
let title = params;
const match = /f_search=([^&]+)/.exec(title);
@@ -3,8 +3,10 @@ const EhAPI = require('./ehapi');
module.exports = async (ctx) => {
const page = ctx.params.page ? parseInt(ctx.params.page) : 0;
const tag = ctx.params.tag;
const bittorrent = ctx.params.bittorrent || false;
const items = await EhAPI.getTagItems(ctx.cache, tag, page, bittorrent);
const routeParams = new URLSearchParams(ctx.params.routeParams);
const bittorrent = routeParams.get('bittorrent') || false;
const embed_thumb = routeParams.get('embed_thumb') || false;
const items = await EhAPI.getTagItems(ctx.cache, tag, page, bittorrent, embed_thumb);
if (EhAPI.from_ex) {
ctx.state.data = {