From d8ae8d8d44414f61e1a5ef90e548fe641b3ca701 Mon Sep 17 00:00:00 2001 From: miemieYaho Date: Wed, 3 Jul 2024 20:02:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(routes):=20bt0(=E4=B8=8D=E5=A4=AA=E7=81=B5)?= =?UTF-8?q?=20use=20new=20api=20(#16061)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * bt0 * bt0 * bt0 --- lib/routes/bt0/mv.ts | 45 +++++++++++++++++++---------------------- lib/routes/bt0/tlist.ts | 45 +++++++++++++++++------------------------ lib/routes/bt0/util.ts | 9 ++++++--- 3 files changed, 46 insertions(+), 53 deletions(-) diff --git a/lib/routes/bt0/mv.ts b/lib/routes/bt0/mv.ts index 0633761d7..36ef8d33e 100644 --- a/lib/routes/bt0/mv.ts +++ b/lib/routes/bt0/mv.ts @@ -1,5 +1,4 @@ import { Route } from '@/types'; -import { load } from 'cheerio'; import InvalidParameterError from '@/errors/types/invalid-parameter'; import { doGot, genSize } from './util'; @@ -38,31 +37,29 @@ async function handler(ctx) { } const host = `https://www.${domain}bt0.com`; - const _link = `${host}/mv/${number}.html`; + const _link = `${host}/prod/core/system/getVideoDetail/${number}`; - const $ = load(await doGot(0, host, _link)); - const name = $('span.info-title.lh32').text(); - const items = $('div.container .container .col-md-10.tex_l') - .toArray() - .map((item) => { - item = $(item); - const torrent_info = item.find('.torrent-title').first(); - const _title = torrent_info.text(); - const len = item.find('.tag-sm.tag-size.text-center').first().text(); - return { - title: _title, - guid: _title, - description: `${_title}[${len}]`, - link: host + torrent_info.attr('href'), - pubDate: item.find('.tag-sm.tag-download.text-center').eq(1).text(), - enclosure_type: 'application/x-bittorrent', - enclosure_url: item.find('.col-md-3 a').first().attr('href'), - enclosure_length: genSize(len), - }; - }); + const data = (await doGot(0, host, _link)).data; + const items = Object.values(data.ecca).flatMap((item) => + item.map((i) => ({ + title: i.zname, + guid: i.zname, + description: `${i.zname}[${i.zsize}]`, + link: `${host}/tr/${i.id}.html`, + pubDate: i.ezt, + enclosure_type: 'application/x-bittorrent', + enclosure_url: i.zlink, + enclosure_length: genSize(i.zsize), + category: strsJoin(i.zqxd, i.text_html, i.audio_html, i.new === 1 ? '新' : ''), + })) + ); return { - title: name, - link: _link, + title: data.title, + link: `${host}/mv/${number}.html`, item: items, }; } + +function strsJoin(...strings) { + return strings.filter((str) => str !== '').join(','); +} diff --git a/lib/routes/bt0/tlist.ts b/lib/routes/bt0/tlist.ts index aca921da2..481eab960 100644 --- a/lib/routes/bt0/tlist.ts +++ b/lib/routes/bt0/tlist.ts @@ -1,21 +1,21 @@ import { Route } from '@/types'; -import { load } from 'cheerio'; import InvalidParameterError from '@/errors/types/invalid-parameter'; import { doGot, genSize } from './util'; +import { parseRelativeDate } from '@/utils/parse-date'; const categoryDict = { 1: '电影', 2: '电视剧', - 3: '周热门', - 4: '月热门', - 5: '年度热门', + 3: '近日热门', + 4: '本周热门', + 5: '本月热门', }; export const route: Route = { path: '/tlist/:sc/:domain?', categories: ['multimedia'], example: '/bt0/tlist/1', - parameters: { sc: '分类(1-5), 1:电影, 2:电视剧, 3:周热门, 4:月热门, 5:年度热门', domain: '数字1-9, 比如1表示请求域名为 1bt0.com, 默认为 2' }, + parameters: { sc: '分类(1-5), 1:电影, 2:电视剧, 3:近日热门, 4:本周热门, 5:本月热门', domain: '数字1-9, 比如1表示请求域名为 1bt0.com, 默认为 2' }, features: { requireConfig: false, requirePuppeteer: false, @@ -45,30 +45,23 @@ async function handler(ctx) { } const host = `https://www.${domain}bt0.com`; - const _link = `${host}/tlist.php?sc=${sc}`; + const _link = `${host}/prod/core/system/getTList?sc=${sc}`; - const $ = load(await doGot(0, host, _link)); - const items = $('div.left.bf100.hig90.ov_hid.po_rel.trall3.dou3') - .toArray() - .map((item) => { - item = $(item); - const ah = item.find('a'); - const _title = ah.eq(1).text(); - const ds = item.find('.huise2.fs12 .left'); - return { - title: _title, - guid: _title, - description: `${ds.eq(0).text()} ${ds.eq(1).text()}
${ds.eq(2).text()}
${ds.eq(3).text()}
${ds.eq(4).text()}`, - link: host + ah.eq(1).attr('href'), - pubDate: item.find('.bghuise9').first().text(), - enclosure_type: 'application/x-bittorrent', - enclosure_url: ah.eq(2).attr('href'), - enclosure_length: genSize(item.find('.marl10.bgzise').first().text()), - }; - }); + const data = await doGot(0, host, _link); + const items = data.data.list.map((item) => ({ + title: item.zname, + guid: item.zname, + description: `《${item.title}》 导演: ${item.daoyan}
编剧: ${item.bianji}
演员: ${item.yanyuan}
简介: ${item.conta.trim()}`, + link: host + item.aurl, + pubDate: item.eztime.endsWith('前') ? parseRelativeDate(item.eztime) : item.eztime, + enclosure_type: 'application/x-bittorrent', + enclosure_url: item.zlink, + enclosure_length: genSize(item.zsize), + itunes_item_image: item.epic, + })); return { title: `不太灵-最新资源列表-${categoryDict[sc]}`, - link: _link, + link: `${host}/tlist/${sc}_1.html`, item: items, }; } diff --git a/lib/routes/bt0/util.ts b/lib/routes/bt0/util.ts index 1b8c58e64..1cb34774a 100644 --- a/lib/routes/bt0/util.ts +++ b/lib/routes/bt0/util.ts @@ -10,9 +10,12 @@ async function doGot(num, host, link) { cookieJar, }); const data = response.data; - const regex = /document\.cookie\s*=\s*"([^"]*)"/; - const match = data.match(regex); - if (match) { + if (typeof data === 'string') { + const regex = /document\.cookie\s*=\s*"([^"]*)"/; + const match = data.match(regex); + if (!match) { + throw new Error('api error'); + } cookieJar.setCookieSync(match[1], host); return doGot(++num, host, link); }