From 14e7761ef53e12b90b95f319483a031ab7e98d18 Mon Sep 17 00:00:00 2001 From: xianghuawe Date: Wed, 15 May 2024 01:03:04 +0800 Subject: [PATCH] fix(route): 6v123 processItems export error (#15587) * fix: processItems export error * fix: optimize code typo --- lib/routes/6v123/utils.ts | 120 ++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 62 deletions(-) diff --git a/lib/routes/6v123/utils.ts b/lib/routes/6v123/utils.ts index 72ccebc62b501c..098a6cd5f5e9c7 100644 --- a/lib/routes/6v123/utils.ts +++ b/lib/routes/6v123/utils.ts @@ -5,80 +5,76 @@ import { load } from 'cheerio'; import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; -const utils = { - loadDetailPage: async function loadDetailPage(link) { - const response = await got.get(link, { - responseType: 'buffer', - }); - response.data = iconv.decode(response.data, 'gb2312'); +export async function loadDetailPage(link) { + const response = await got.get(link, { + responseType: 'buffer', + }); + response.data = iconv.decode(response.data, 'gb2312'); - const $ = load(response.data); + const $ = load(response.data); - const detailInfo = { - title: $('title') - .text() - .replaceAll(/,免费下载,迅雷下载|,6v电影/g, ''), - description: $('meta[name="description"]').attr('content'), - enclosure_urls: $('table td') - .map((i, e) => ({ - title: $(e).text().replace('磁力:', ''), - magnet: $(e).find('a').attr('href'), - })) - .toArray() - .filter((item) => item.magnet?.includes('magnet')), - }; - return detailInfo; - }, - processItems: async (ctx, baseURL) => { - const response = await got.get(baseURL, { - responseType: 'buffer', - }); - response.data = iconv.decode(response.data, 'gb2312'); + return { + title: $('title') + .text() + .replaceAll(/,免费下载,迅雷下载|,6v电影/g, ''), + description: $('meta[name="description"]').attr('content'), + enclosure_urls: $('table td') + .map((i, e) => ({ + title: $(e).text().replace('磁力:', ''), + magnet: $(e).find('a').attr('href'), + })) + .toArray() + .filter((item) => item.magnet?.includes('magnet')), + }; +} - const $ = load(response.data); - const list = $('ul.list')[0].children; +export async function processItems(ctx, baseURL) { + const response = await got.get(baseURL, { + responseType: 'buffer', + }); + response.data = iconv.decode(response.data, 'gb2312'); - const process = await Promise.all( - list.map((item) => { - const link = $(item).find('a'); - const href = link.attr('href'); - const pubDate = timezone(parseDate($(item).find('span').text().replaceAll(/[[\]]/g, ''), 'MM-DD'), +8); + const $ = load(response.data); + const list = $('ul.list')[0].children; - if (href === undefined) { - return; - } + const process = await Promise.all( + list.map((item) => { + const link = $(item).find('a'); + const href = link.attr('href'); + const pubDate = timezone(parseDate($(item).find('span').text().replaceAll(/[[\]]/g, ''), 'MM-DD'), +8); - const itemUrl = 'https://www.hao6v.cc' + link.attr('href'); + if (href === undefined) { + return; + } - return cache.tryGet(itemUrl, async () => { - const detailInfo = await utils.loadDetailPage(itemUrl); + const itemUrl = 'https://www.hao6v.cc' + link.attr('href'); - if (detailInfo.enclosure_urls.length > 1) { - return detailInfo.enclosure_urls.map((url) => ({ - enclosure_url: url.magnet, - enclosure_type: 'application/x-bittorrent', - title: `${link.text()} ( ${url.title} )`, - description: detailInfo.description, - pubDate, - link: itemUrl, - guid: `${itemUrl}#${url.title}`, - })); - } + return cache.tryGet(itemUrl, async () => { + const detailInfo = await loadDetailPage(itemUrl); - return { - enclosure_url: detailInfo.enclosure_urls.length === 0 ? '' : detailInfo.enclosure_urls[0].magnet, + if (detailInfo.enclosure_urls.length > 1) { + return detailInfo.enclosure_urls.map((url) => ({ + enclosure_url: url.magnet, enclosure_type: 'application/x-bittorrent', - title: link.text(), + title: `${link.text()} ( ${url.title} )`, description: detailInfo.description, pubDate, link: itemUrl, - }; - }); - }) - ); + guid: `${itemUrl}#${url.title}`, + })); + } - return process.filter((item) => item !== undefined).flat(); - }, -}; + return { + enclosure_url: detailInfo.enclosure_urls.length === 0 ? '' : detailInfo.enclosure_urls[0].magnet, + enclosure_type: 'application/x-bittorrent', + title: link.text(), + description: detailInfo.description, + pubDate, + link: itemUrl, + }; + }); + }) + ); -export default utils; + return process.filter((item) => item !== undefined).flat(); +}