const got = require('@/utils/got'); const { load } = require('cheerio'); exports.getPage = async (url, ctx) => { const { data } = await got(url); const $ = load(data); const pageTitle = `JavBus - ${$('head > title') .text() .replace(' - JavBus', '')}`; return { title: pageTitle, link: url, description: pageTitle, item: await Promise.all(parseItems($, ctx)), }; }; exports.createHandler = (url) => async (ctx) => { ctx.state.data = await exports.getPage(url, ctx); }; const parseItems = ($, ctx) => $('.movie-box') .map((_, ele) => ({ title: $(ele) .find('img') .attr('title'), thumb: $(ele) .find('img') .attr('src'), link: $(ele).attr('href'), pubDate: new Date( $(ele) .find('date:nth-child(4)') .text() ).toUTCString(), aid: $(ele) .find('date:nth-child(3)') .text(), })) .toArray() .map(async ({ title, thumb, link, pubDate, aid }) => { const detail = await getDetail(link, ctx); title = `${aid} ${title}${detail.filmTime}`; if (detail.screenData) { detail.imgHTML = detail.screenData.map((url) => `
`); } return { title, link, pubDate, description: `

${title}


${detail.filmId ? `

識別碼 : ${detail.filmId}

` : ''} ${detail.filmTime ? `

发售日期 : ${detail.filmTime}

` : ''} ${detail.actresses ? `

女优 : ${detail.actresses}

` : ''} ${detail.filmEstabName ? `

發行商 : ${detail.filmEstabName}

` : ''} ${detail.filmMakerbName ? `

製作商 : ${detail.filmMakerbName}

` : ''} ${detail.seriesName ? `

系列 : ${detail.seriesName}

` : ''} ${detail.filmLast ? `

影片时长 : ${detail.filmLast}

` : ''} ${detail.screenData ? `

影片截图 :

${detail.imgHTML.join('')}` : ''} ${detail.videolink ? `

在线观看 : ${detail.videolink}

` : ''} ${detail.magnetlinks ? `

下载地址 :


${detail.magnetlinks.join('')}` : ''} ${detail.videoplayer ? `

视频预览 :


${detail.videoplayer}` : ''} `.trim(), }; }); const getDetail = async (link, ctx) => { const cache = await ctx.cache.get(link); if (cache) { return JSON.parse(cache); } else { const resp = await got(link); const detailPage = resp.data; // 演员 const actressReg = //g; let match = detailPage.match(actressReg); let actresses = []; if (match) { match.map((i) => { const name = /(.*?)<\/span>/.exec(i)[1]; actresses = actresses.concat(name); return null; }); } else { actresses = null; // [] } // 影片详情 // const filmCover = /([\s\S]*?)<\/span>/.exec(detailPage); if (filmId) { filmId = filmId[1]; } else { filmId = null; } let filmTime = /發行日期:<\/span>([\s\S]*?)<\/p>/.exec(detailPage); if (filmTime) { filmTime = filmTime[1]; } else { filmTime = null; } let filmLast = /長度:<\/span>([\s\S]*?)<\/p>/.exec(detailPage); if (filmLast) { const lastmins = /\d+/.exec(filmLast[1]); if (lastmins) { const hours = Math.floor(lastmins / 60); let mins = lastmins % 60; mins = mins === 0 ? '00' : mins; filmLast = hours + ':' + mins; } else { filmLast = null; } } else { filmLast = null; } let filmEstabName = /發行商:[\s\S]*?"(.*?)">(.*?)<\/a>/.exec(detailPage); if (filmEstabName) { filmEstabName = filmEstabName[2]; } else { filmEstabName = null; } let filmMakerbName = /製作商:[\s\S]*?"(.*?)">(.*?)<\/a>/.exec(detailPage); if (filmMakerbName) { filmMakerbName = filmMakerbName[2]; } else { filmMakerbName = null; } let seriesName = /系列:[\s\S]*?"(.*?)">(.*?)<\/a>/.exec(detailPage); if (seriesName) { seriesName = seriesName[2]; } else { seriesName = null; } let directorName = /導演:[\s\S]*?"(.*?)">(.*?)<\/a>/.exec(detailPage); if (directorName) { directorName = directorName[2]; } else { directorName = null; } const code = /識別碼:[\s\S]*?">([\s\S]*?)<\/span>/.exec(detailPage)[1]; // 影片截图 const regScreenshot = //g; match = detailPage.match(regScreenshot); let screenData = []; if (match) { screenData = match.map((i) => //g.exec(i)[1]); } else { screenData = null; } const filmGid = /gid = ([0-9]*?);/.exec(detailPage); const filmUc = /uc = ([0-9]*?);/.exec(detailPage); const filmImg = /var img = '(.*?)';/.exec(detailPage); const filmFloor = Math.floor(Math.random() * 1000 + 1); const apiurl = `https://www.javbus.com/ajax/uncledatoolsbyajax.php?gid=${filmGid[1]}&lang=zh&img=${filmImg[1]}&uc=${filmUc[1]}&floor=${filmFloor}`; const apiresp = await got({ method: 'get', url: apiurl, headers: { Referer: link, }, }); const magnettable = apiresp.data; match = magnettable.match(//gm); let magnetlinks = []; if (match) { magnetlinks = match.map(function(str) { // magnet地址 const mlink = /td width="70%" onclick="window.open\('(magnet.*?)',/.exec(str)[1]; // console.log(str); // 提取a链接 const mrow = str.match(/([\s\S]*?)([\s\S]*?)([\s\S]*?)"+mname+" -- "+msize+ "<\/a>