Skip to content

Commit

Permalink
fix(route): fix /iqiyi/user/video (#13154)
Browse files Browse the repository at this point in the history
* fix(route): fix iqiyi video

* fix some problem, but leave the images alone
  • Loading branch information
JimenezLi authored Sep 1, 2023
1 parent c103270 commit d6a7f6d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
2 changes: 1 addition & 1 deletion lib/v2/iqiyi/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
'/album/:id': ['TonyRL'],
'/user/video/:uid': ['talengu'],
'/user/video/:uid': ['talengu', 'JimenezLi'],
};
75 changes: 42 additions & 33 deletions lib/v2/iqiyi/video.js
Original file line number Diff line number Diff line change
@@ -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: `<img src="${$(item).find('.li-pic img').attr('src')}">`,
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: `<img src="${$(item).find('.site-piclist_pic img').attr('src')}">`,
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;
};

0 comments on commit d6a7f6d

Please sign in to comment.