diff --git a/docs/en/install/README.md b/docs/en/install/README.md index 80abbae3b..93df0ee40 100644 --- a/docs/en/install/README.md +++ b/docs/en/install/README.md @@ -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) diff --git a/docs/en/picture.md b/docs/en/picture.md index cc070b3ad..ab164cdc9 100644 --- a/docs/en/picture.md +++ b/docs/en/picture.md @@ -116,6 +116,27 @@ pageClass: routes +## 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 + + + +### Tag + + + +### Search + + + ## Elite Babes ### Home diff --git a/docs/install/README.md b/docs/install/README.md index e9f26df2d..ff4d5a4f8 100644 --- a/docs/install/README.md +++ b/docs/install/README.md @@ -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) diff --git a/docs/picture.md b/docs/picture.md index 892533bde..3f9cc6333 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -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 | + ### 收藏 - + ### 标签 - + ### 搜索 - + ## Elite Babes diff --git a/lib/config.js b/lib/config.js index bdba65485..de73c5e73 100644 --- a/lib/config.js +++ b/lib/config.js @@ -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, diff --git a/lib/router.js b/lib/router.js index 01112c31c..5f88ccd9a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/v2/e-hentai/radar.js b/lib/v2/e-hentai/radar.js index 97766e050..e288c4106 100644 --- a/lib/v2/e-hentai/radar.js +++ b/lib/v2/e-hentai/radar.js @@ -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')}`, }, ], }, diff --git a/lib/routes/ehentai/ehapi.js b/lib/v2/ehentai/ehapi.js similarity index 68% rename from lib/routes/ehentai/ehapi.js rename to lib/v2/ehentai/ehapi.js index b97c14ed3..86e99225e 100644 --- a/lib/routes/ehentai/ehapi.js +++ b/lib/v2/ehentai/ehapi.js @@ -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 = `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 = `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 }; diff --git a/lib/routes/ehentai/favorites.js b/lib/v2/ehentai/favorites.js similarity index 80% rename from lib/routes/ehentai/favorites.js rename to lib/v2/ehentai/favorites.js index 1fa7123e8..d049ebc54 100644 --- a/lib/routes/ehentai/favorites.js +++ b/lib/v2/ehentai/favorites.js @@ -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 = { diff --git a/lib/v2/ehentai/maintainer.js b/lib/v2/ehentai/maintainer.js new file mode 100644 index 000000000..92834b355 --- /dev/null +++ b/lib/v2/ehentai/maintainer.js @@ -0,0 +1,5 @@ +module.exports = { + '/favorites/:favcat?/:order?/:page?/:routeParams?': ['yindaheng98'], + '/search/:params?/:page?/:routeParams?': ['yindaheng98'], + '/tag/:tag/:page?/:routeParams?': ['yindaheng98'], +}; diff --git a/lib/v2/ehentai/router.js b/lib/v2/ehentai/router.js new file mode 100644 index 000000000..7c7d29085 --- /dev/null +++ b/lib/v2/ehentai/router.js @@ -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')); +}; diff --git a/lib/routes/ehentai/search.js b/lib/v2/ehentai/search.js similarity index 77% rename from lib/routes/ehentai/search.js rename to lib/v2/ehentai/search.js index 180dfbb1b..f63e10ad9 100644 --- a/lib/routes/ehentai/search.js +++ b/lib/v2/ehentai/search.js @@ -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); diff --git a/lib/routes/ehentai/tag.js b/lib/v2/ehentai/tag.js similarity index 72% rename from lib/routes/ehentai/tag.js rename to lib/v2/ehentai/tag.js index a50be06fd..6c65241cf 100644 --- a/lib/routes/ehentai/tag.js +++ b/lib/v2/ehentai/tag.js @@ -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 = {