From d6a7f6d0214f74842006764bb26454605dc85022 Mon Sep 17 00:00:00 2001 From: JimenezLi <75196426+JimenezLi@users.noreply.github.com> Date: Sat, 2 Sep 2023 02:20:04 +0800 Subject: [PATCH] fix(route): fix `/iqiyi/user/video` (#13154) * fix(route): fix iqiyi video * fix some problem, but leave the images alone --- lib/v2/iqiyi/maintainer.js | 2 +- lib/v2/iqiyi/video.js | 75 +++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/lib/v2/iqiyi/maintainer.js b/lib/v2/iqiyi/maintainer.js index c664168821add6..8f3f796825b5e9 100644 --- a/lib/v2/iqiyi/maintainer.js +++ b/lib/v2/iqiyi/maintainer.js @@ -1,4 +1,4 @@ module.exports = { '/album/:id': ['TonyRL'], - '/user/video/:uid': ['talengu'], + '/user/video/:uid': ['talengu', 'JimenezLi'], }; diff --git a/lib/v2/iqiyi/video.js b/lib/v2/iqiyi/video.js index 1cac56057036d0..2754483b341760 100644 --- a/lib/v2/iqiyi/video.js +++ b/lib/v2/iqiyi/video.js @@ -1,43 +1,52 @@ -const got = require('@/utils/got'); const cheerio = require('cheerio'); +const config = require('@/config').value; +const { parseDate } = require('@/utils/parse-date'); +const logger = require('@/utils/logger'); // /iqiyi/user/video/:uid // http://localhost:1200/iqiyi/user/video/2289191062 module.exports = async (ctx) => { const uid = ctx.params.uid; + const link = `https://www.iqiyi.com/u/${uid}/videos`; - const response = await got({ - method: 'get', - url: `http://www.iqiyi.com/u/${uid}/v`, - headers: { - Host: 'www.iqiyi.com', - Referer: `http://www.iqiyi.com/u/${uid}/v`, - }, - }); - - const data = response.data; - const $ = cheerio.load(data); - const description = ''; + // Use puppeteer because iqiyi page has a delay. + const browser = await require('@/utils/puppeteer')(); + const data = await ctx.cache.tryGet( + link, + async () => { + const page = await browser.newPage(); + await page.setRequestInterception(true); + page.on('request', (request) => { + request.resourceType() === 'document' || request.resourceType() === 'script' ? request.continue() : request.abort(); + }); + logger.debug(`Requesting ${link}`); + await page.goto(link, { + waitUntil: 'domcontentloaded', + }); + await page.waitForSelector('li.pic-txt-li'); + const html = await page.content(); - const list = $('li[j-delegate="colitem"]'); + const $ = cheerio.load(html); + const list = $('li.pic-txt-li'); - ctx.state.data = { - title: $('title').text(), - link: `http://www.iqiyi.com/u/${uid}/v`, - description, - item: - list && - list - .map((index, item) => { - const title = $(item).find('.site-piclist_pic a').attr('data-title'); + return { + title: $('title').text(), + link, + item: + list && + list + .map((index, item) => ({ + title: $(item).attr('title'), + // description: ``, + pubDate: parseDate($(item).find('.li-sub span.sub-date').text(), 'YYYY-MM-DD'), + link: $(item).find('.li-dec a').attr('href'), + })) + .get(), + }; + }, + config.cache.routeExpire, + false + ); + browser.close(); - return { - title, - description: ``, - pubDate: new Date($(item).find('.playTimes_status.tl').text().substring(0, 10).replace(/-/g, '/')).toUTCString(), - link: $(item).find('.site-piclist_pic a').attr('href'), - }; - }) - .get(), - // .reverse(), - }; + ctx.state.data = data; };