From d9826eb3bc19a11c1fa089546bdc4fc41edc27d8 Mon Sep 17 00:00:00 2001 From: Goren G Date: Sat, 25 Feb 2023 22:58:29 +0800 Subject: [PATCH] fix(router): parse images from `.pattl` (#11951) * fix: parse images from .pattl * chore: use for of * refactor: update route path * docs: update table mapping --------- --- docs/multimedia.md | 14 +- lib/v2/dsndsht23/index.js | 121 ---------------- lib/v2/sehuatang/index.js | 129 ++++++++++++++++++ lib/v2/{dsndsht23 => sehuatang}/maintainer.js | 0 lib/v2/{dsndsht23 => sehuatang}/radar.js | 4 +- lib/v2/{dsndsht23 => sehuatang}/router.js | 0 6 files changed, 138 insertions(+), 130 deletions(-) delete mode 100644 lib/v2/dsndsht23/index.js create mode 100644 lib/v2/sehuatang/index.js rename lib/v2/{dsndsht23 => sehuatang}/maintainer.js (100%) rename lib/v2/{dsndsht23 => sehuatang}/radar.js (81%) rename lib/v2/{dsndsht23 => sehuatang}/router.js (100%) diff --git a/docs/multimedia.md b/docs/multimedia.md index 417cef71a..46d4e85ed 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -1561,19 +1561,19 @@ JavDB 有多个备用域名,本路由默认使用永久域名 + **原创 BT 电影** -| 每日合集 | 国产原创 | 亚洲无码原创 | 亚洲有码原创 | 高清中文字幕 | 三级写真 | 亚洲名站有码 | VR 系列 | 欧美无码 | 动漫原创 | AI 换脸电影 | 原档收藏 WMV | 综合讨论区 | -| ---- | ---- | ------ | ------ | ------ | ---- | ------ | ----- | ---- | ---- | ------- | -------- | ----- | -| mrhj | gcyc | yzwmyc | yzymyc | gqzwzm | sjxz | yzmzym | vr | omwm | dmyc | ai | ydsc | zhtlq | +| 国产原创 | 亚洲无码原创 | 亚洲有码原创 | 高清中文字幕 | 三级写真 | VR 视频 | 素人有码 | 欧美无码 | 韩国主播 | 动漫原创 | 综合讨论 | +| ---- | ------ | ------ | ------ | ---- | ----- | ---- | ---- | ---- | ---- | ---- | +| gcyc | yzwmyc | yzymyc | gqzwzm | sjxz | vr | srym | omwm | hgzb | dmyc | zhtl | **色花图片** -| 华人性爱自拍 | 华人街拍区 | 亚洲性爱 | 欧美性爱 | 卡通动漫 | -| ------ | ----- | ---- | ---- | ---- | -| hrxazp | hrjpq | yzxa | omxa | ktdm | +| 原创自拍 | 转贴自拍 | 华人街拍 | 亚洲性爱 | 欧美性爱 | 卡通动漫 | 套图下载 | +| ---- | ---- | ---- | ---- | ---- | ---- | ---- | +| yczp | ztzp | hrjp | yzxa | omxa | ktdm | ttxz | diff --git a/lib/v2/dsndsht23/index.js b/lib/v2/dsndsht23/index.js deleted file mode 100644 index 1aac5fe1f..000000000 --- a/lib/v2/dsndsht23/index.js +++ /dev/null @@ -1,121 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); - -const host = 'https://www.sehuatang.net/'; - -const forumIdMaps = { - mrhj: '106', - gcyc: '2', - yzwmyc: '36', - yzymyc: '37', - gqzwzm: '103', - sjxz: '107', - yzmzym: '104', - vr: '102', - omwm: '38', - dmyc: '39', - ai: '113', - ydsc: '111', - hrxazp: '98', - hrjpq: '50', - yzxa: '48', - omxa: '49', - ktdm: '117', - zhtlq: '95', -}; - -module.exports = async (ctx) => { - const subformName = ctx.params.subforumid ?? 'gqzwzm'; - const subformId = subformName in forumIdMaps ? forumIdMaps[subformName] : subformName; - const typefilter = ctx.params.type ? `&filter=typeid&typeid=${ctx.params.type}` : ''; - const link = `${host}forum.php?mod=forumdisplay&orderby=dateline&fid=${subformId}${typefilter}`; - const headers = { - 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', - }; - let c; - const response = await got(link, { - headers, - hooks: { - beforeRedirect: [ - (options, response) => { - const cookie = response.headers['set-cookie']; - if (cookie) { - const cook = cookie.map((c) => c.split(';')[0]).join('; '); - options.headers.Cookie = cook; - c = cook; - options.headers.Referer = response.url; - } - }, - ], - }, - }); - headers.Cookie = c; - const $ = cheerio.load(response.data); - - const list = $('#threadlisttableid tbody[id^=normalthread]') - .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 25) - .map(function () { - const info = { - title: '[' + $(this).find('th em a').text() + '] ' + $(this).find('a.xst').text(), - link: $(this).find('a.xst').attr('href'), - date: $(this).find('td.by').find('em span span').attr('title') || $(this).find('td.by').find('em span').first().text(), - }; - return info; - }) - .get(); - - const out = await Promise.all( - list.map((info) => { - const title = info.title; - const date = info.date; - const itemUrl = host + info.link; - - return ctx.cache.tryGet(itemUrl, async () => { - const response = await got(itemUrl, { - headers, - }); - - const $ = cheerio.load(response.data); - const postMessage = $("td[id^='postmessage']").slice(0, 1); - const images = $(postMessage).find('img'); - for (let k = 0; k < images.length; k++) { - if (!$(images[k]).attr('file') || $(images[k]).attr('file') === 'undefined') { - $(images[k]).replaceWith(''); - } else { - $(images[k]).replaceWith(``); - } - } - const description = (postMessage.html() || '抓取原帖失败').replace(/ignore_js_op/g, 'div'); - - const single = { - title, - link: itemUrl, - description, - pubDate: date ? parseDate(date) : null, - }; - const magnet = postMessage.find('div.blockcode li').first().text(); - const isMag = magnet.startsWith('magnet'); - const torrent = postMessage.find('a[href^=forum\\.php\\?mod\\=attachment]:not([href$=nothumb\\=yes])').attr('href'); - - const hasEnclosureUrl = isMag || torrent !== undefined; - if (hasEnclosureUrl) { - const enclosureUrl = isMag ? magnet : new URL(torrent, host).href; - const enclosure = { - enclosure_url: enclosureUrl, - enclosure_type: isMag ? 'application/x-bittorrent' : 'application/octet-stream', - }; - Object.assign(single, enclosure); - } - return single; - }); - }) - ); - - ctx.state.data = { - title: `色花堂 - ${$('#pt > div:nth-child(1) > a:last-child').text()}`, - link, - item: out, - }; -}; diff --git a/lib/v2/sehuatang/index.js b/lib/v2/sehuatang/index.js new file mode 100644 index 000000000..06451d87b --- /dev/null +++ b/lib/v2/sehuatang/index.js @@ -0,0 +1,129 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const { CookieJar } = require('tough-cookie'); +const cookieJar = new CookieJar(); + +const host = 'https://www.sehuatang.net/'; + +const forumIdMaps = { + // 原创 BT 电影 + gcyc: '2', // 国产原创 + yzwmyc: '36', // 亚洲无码原创 + yzymyc: '37', // 亚洲有码原创 + gqzwzm: '103', // 高清中文字幕 + sjxz: '107', // 三级写真 + vr: '160', // VR 视频 + srym: '104', // 素人有码 + omwm: '38', // 欧美无码 + '4k': '151', // 4K 原版 + hgzb: '152', // 韩国主播 + dmyc: '39', // 动漫原创 + // 色花图片 + yczp: '155', // 原创自拍 + ztzp: '125', // 转贴自拍 + hrjp: '50', // 华人街拍 + yzxa: '48', // 亚洲性爱 + omxa: '49', // 欧美性爱 + ktdm: '117', // 卡通动漫 + ttxz: '165', // 套图下载 + + zhtl: '95', // 综合讨论 + // no longer updated/available + mrhj: '106', // 每日合集 + ai: '113', // AI 换脸电影 + ydsc: '111', // 原档收藏 WMV + hrxazp: '98', // 华人性爱自拍 +}; + +module.exports = async (ctx) => { + const subformName = ctx.params.subforumid ?? 'gqzwzm'; + const subformId = subformName in forumIdMaps ? forumIdMaps[subformName] : subformName; + const { type } = ctx.params; + const typefilter = type ? `&filter=typeid&typeid=${type}` : ''; + const link = `${host}forum.php?mod=forumdisplay&orderby=dateline&fid=${subformId}${typefilter}`; + const headers = { + 'Accept-Encoding': 'gzip, deflate, br', + 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', + }; + const response = await got(link, { + cookieJar, + headers, + }); + const $ = cheerio.load(response.data); + + const list = $('#threadlisttableid tbody[id^=normalthread]') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 25) + .toArray() + .map((item) => { + item = $(item); + const hasCategory = item.find('th em a').length; + return { + title: `${hasCategory ? `[${item.find('th em a').text()}]` : ''} ${item.find('a.xst').text()}`, + link: host + item.find('a.xst').attr('href'), + pubDate: parseDate(item.find('td.by').find('em span span').attr('title')), + author: item.find('td.by cite a').first().text(), + }; + }); + + const out = await Promise.all( + list.map((info) => + ctx.cache.tryGet(info.link, async () => { + const response = await got(info.link, { + cookieJar, + headers, + }); + + const $ = cheerio.load(response.data); + const postMessage = $("td[id^='postmessage']").slice(0, 1); + const images = $(postMessage).find('img'); + for (const image of images) { + const file = $(image).attr('file'); + if (!file || file === 'undefined') { + $(image).replaceWith(''); + } else { + $(image).replaceWith($(``)); + } + } + // if postMessage does not have any images, try to parse image url from `.pattl` + if (images.length === 0) { + const pattl = $('.pattl'); + const pattlImages = $(pattl).find('img'); + for (const pattlImage of pattlImages) { + const file = $(pattlImage).attr('file'); + if (!file || file === 'undefined') { + $(pattlImage).replaceWith(''); + } else { + $(pattlImage).replaceWith($(``)); + } + } + postMessage.append($(pattl)); + } + $('em[onclick]').remove(); + + info.description = (postMessage.html() || '抓取原帖失败').replace(/ignore_js_op/g, 'div'); + info.pubDate = timezone(parseDate($('.authi em span').attr('title')), 8); + + const magnet = postMessage.find('div.blockcode li').first().text(); + const isMag = magnet.startsWith('magnet'); + const torrent = postMessage.find('p.attnm a').attr('href'); + + const hasEnclosureUrl = isMag || torrent !== undefined; + if (hasEnclosureUrl) { + const enclosureUrl = isMag ? magnet : new URL(torrent, host).href; + info.enclosure_url = enclosureUrl; + info.enclosure_type = isMag ? 'application/x-bittorrent' : 'application/octet-stream'; + } + + return info; + }) + ) + ); + + ctx.state.data = { + title: `色花堂 - ${$('#pt > div:nth-child(1) > a:last-child').text()}`, + link, + item: out, + }; +}; diff --git a/lib/v2/dsndsht23/maintainer.js b/lib/v2/sehuatang/maintainer.js similarity index 100% rename from lib/v2/dsndsht23/maintainer.js rename to lib/v2/sehuatang/maintainer.js diff --git a/lib/v2/dsndsht23/radar.js b/lib/v2/sehuatang/radar.js similarity index 81% rename from lib/v2/dsndsht23/radar.js rename to lib/v2/sehuatang/radar.js index 1037947f0..592f8fae1 100644 --- a/lib/v2/dsndsht23/radar.js +++ b/lib/v2/sehuatang/radar.js @@ -8,10 +8,10 @@ module.exports = { source: ['/:category', '/'], target: (params, url) => { const theUrl = new URL(url); - const matches = String(theUrl).match(/forum-(\d)+-\d+/); + const matches = theUrl.href.match(/forum-(\d)+-\d+/); const fid = theUrl.searchParams.get('fid') || (matches ? matches[1] : ''); const tid = theUrl.searchParams.get('typeid'); - return `/dsndsht23${fid ? `/${fid}` : ''}${tid ? `/${tid}` : ''}`; + return `/sehuatang${fid ? `/${fid}` : ''}${tid ? `/${tid}` : ''}`; }, }, ], diff --git a/lib/v2/dsndsht23/router.js b/lib/v2/sehuatang/router.js similarity index 100% rename from lib/v2/dsndsht23/router.js rename to lib/v2/sehuatang/router.js