-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(route): fix
/iqiyi/user/video
(#13154)
* fix(route): fix iqiyi video * fix some problem, but leave the images alone
- Loading branch information
Showing
2 changed files
with
43 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |