From 30d24998faee20b58483e3714053d2a3510fb209 Mon Sep 17 00:00:00 2001 From: wolfyu1991 Date: Sat, 3 Aug 2019 15:31:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20MP4Ba=E6=BA=90=E7=AB=99=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E8=8E=B7=E5=8F=96=E9=94=99=E8=AF=AF=20(#2432)=20(#276?= =?UTF-8?q?3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: MP4Ba源站内容获取错误 (#2432) fix: MP4Ba源站内容获取错误 (#2432) * docs: 同步MP4BA说明文档 docs: 同步MP4BA说明文档 --- docs/multimedia.md | 26 ++++++++++++++-------- lib/routes/mp4ba/index.js | 47 +++++++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/docs/multimedia.md b/docs/multimedia.md index 4b65dc518..04e221add 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -89,22 +89,30 @@ pageClass: routes ## Mp4Ba +### 影视分类 + + + **类型参考这里** -| 1 | 2 | 3 | 4 | -| - | - | - | - | -| 电影 | 连续剧 | 综艺 | 动画 | +| 电影 | 连续剧 | 动画 | 综艺 | 纪录片 | +| - | - | - | - | - | +| 6 | 7 | 15 | 20 | 24 | -| 5 | 6 | 7 | 8 | 9 | -| ------ | ------ | ------ | ------ | ------ | | 动作片 | 喜剧片 | 爱情片 | 科幻片 | 恐怖片 | +| ------ | ------ | ------ | ------ | ------ | +| 8 | 9 | 10 | 11 | 12 | -| 10 | 11 | 12 | 13 | 14 | 15 | -| ------ | ------ | ------ | ------ | ------ | ------ | | 剧情片 | 战争片 | 国产剧 | 港台剧 | 日韩剧 | 欧美剧 | +| ------ | ------ | ------ | ------ | ------ | ------ | +| 13 | 14 | 16 | 17 | 18 | 19 | -### 资源 + - +### 影视搜索 + + + + ## rs05 人生 05 电影 diff --git a/lib/routes/mp4ba/index.js b/lib/routes/mp4ba/index.js index fd6ff7f99..4f5f7852d 100644 --- a/lib/routes/mp4ba/index.js +++ b/lib/routes/mp4ba/index.js @@ -1,7 +1,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const baseUrl = 'http://ww.mp4ba.com'; +const baseUrl = 'http://www.mp4ba.com'; class ParamType { static get paramType() { @@ -31,10 +31,10 @@ class ParamType { if (!this._url) { switch (this._type) { case ParamType.paramType.type: - url = `${baseUrl}/?m=vod-type-id-${this._param}.html`; + url = `${baseUrl}/index/index/lists/catid/${this._param}/`; break; case ParamType.paramType.search: - url = `${baseUrl}/index.php?m=vod-search&wd=${this._param}`; + url = `${baseUrl}/index.php?m=search&q=${this._param}`; break; } this._url = url; @@ -44,18 +44,24 @@ class ParamType { } async function buildRss($, paramType, ctx) { - const $list = (selector) => $('#data_list').find(selector); // 列表对象 + const $list = (selector) => $('.content').find(selector); // 列表对象 const title = $('title').text(); - const typeString = title.substring(0, title.indexOf('-')); + const typeString = title.substring(0, title.indexOf('_')); + let selectorPath1, + selectorPath2 = null; function buildDesc() { let desc = ''; switch (paramType.type) { case ParamType.paramType.type: desc = `${typeString}类型`; + selectorPath1 = '.detail .list ul li'; + selectorPath2 = 'a'; break; case ParamType.paramType.search: - desc = `${typeString}的搜索结果`; + desc = `${typeString}`; + selectorPath1 = '.search .search_content .sousuo'; + selectorPath2 = 'b a'; break; } return desc; @@ -63,23 +69,26 @@ async function buildRss($, paramType, ctx) { async function buildItem($) { return await Promise.all( - $('.alt1') + $(selectorPath1) .map(async (_, result) => { const $ = cheerio.load(result); - const $a = $('td') - .eq(2) - .children('a'); - const pageUrl = `${baseUrl}${$a.attr('href')}`; + const pubDate = new Date( + $('span') + .text() + .match(/\d{4}-\d{1,2}-\d{1,2}/) + ).toUTCString(); + const $a = $(selectorPath2); + const pageUrl = $a.attr('href'); const { cache } = ctx; - const title = $a.text().replace('.Mp4Ba', ''); + const title = $a.text(); const link = pageUrl; - const guid = pageUrl.match(/id-(\d+?).html/); + const guid = pageUrl.match(/(\d+?).html/); let description = null; const enclosure_type = 'application/x-bittorrent'; let $magnet = null; async function getDescription() { - const key = `Mp4Ba${pageUrl.match(/\d+/)}`; + const key = `Mp4Ba${pageUrl}`; const value = await ctx.cache.get(key); if (value) { description = value; @@ -88,11 +97,11 @@ async function buildRss($, paramType, ctx) { } else { const pageData = (await got.get(pageUrl)).data; const $page = cheerio.load(pageData); - $magnet = $page('.main') - .find('.down_list') + $magnet = $page('.content .article .box') + .find('.download') .find('a[href^="magnet:?xt=urn:btih:"]'); - description = $page('.main') - .find('.intro') + description = $page('.content .article .box') + .find('.info_con') .html(); cache.set(key, description); } @@ -100,7 +109,7 @@ async function buildRss($, paramType, ctx) { await getDescription(); const enclosure_url = $magnet.attr('href'); - return { title, link, description, enclosure_url, enclosure_type, guid }; + return { title, link, description, enclosure_url, enclosure_type, guid, pubDate }; }) .get() );