fix: douban movie
This commit is contained in:
parent
f1092152ee
commit
101f3ee61c
|
|
@ -388,7 +388,7 @@ pageClass: routes
|
|||
|
||||
### 正在上映的高分电影
|
||||
|
||||
<Route author="DIYgod" example="/douban/movie/playing/7.5/杭州" path="/douban/movie/playing/:score/:city?" :paramsDesc="['返回大于等于这个分数的电影', '城市的中文名, 可选, 默认北京']"/>
|
||||
<Route author="DIYgod" example="/douban/movie/playing/7.5" path="/douban/movie/playing/:score" :paramsDesc="['返回大于等于这个分数的电影'"/>
|
||||
|
||||
### 即将上映的电影
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,34 @@
|
|||
const axios = require('@/utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const city = ctx.params.city;
|
||||
const score = parseFloat(ctx.params.score, 10);
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: 'https://api.douban.com/v2/movie/in_theaters',
|
||||
params: { city },
|
||||
url: `https://movie.douban.com/cinema/nowplaying/beijing`,
|
||||
});
|
||||
const movieList = score ? response.data.subjects.filter((item) => item.rating.average >= score) : response.data.subjects;
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${city ? city : ''}正在上映的${score ? `超过 ${score} 分的` : ''}电影`,
|
||||
link: 'https://movie.douban.com/cinema/nowplaying/',
|
||||
item: movieList.map((item) => ({
|
||||
title: item.title,
|
||||
description: `标题:${item.title}<br> 影片类型:${item.genres.join(' | ')} <br>评分:${item.rating.average} <br/> <img referrerpolicy="no-referrer" src="${item.images.large}">`,
|
||||
link: item.alt,
|
||||
})),
|
||||
title: `正在上映的${score ? `超过 ${score} 分的` : ''}电影`,
|
||||
link: `https://movie.douban.com/cinema/nowplaying/`,
|
||||
item: $('.list-item')
|
||||
.get()
|
||||
.map((i) => {
|
||||
const item = $(i);
|
||||
const itemScore = parseFloat(item.attr('data-score'), 10);
|
||||
if (itemScore >= score) {
|
||||
return {
|
||||
title: item.attr('data-title'),
|
||||
description: `标题:${item.attr('data-title')}<br>评分:${itemScore}<br>片长:${item.attr('data-duration')}<br>制片国家/地区:${item.attr('data-region')}<br>导演:${item.attr(
|
||||
'data-director'
|
||||
)}<br>主演:${item.attr('data-actors')}<br><img referrerpolicy="no-referrer" src="${item.find('.poster img').attr('src')}">`,
|
||||
link: `https://movie.douban.com/subject/${item.attr('id')}`,
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter((item) => item),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue