diff --git a/README.md b/README.md index 07c9bbbfb..5f135de53 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,9 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 详情 - pixiv - 用户动态 +- 豆瓣 + - 正在上映的电影 + - 正在上映的高分电影 ## 参与我们 diff --git a/docs/README.md b/docs/README.md index c22308e09..d55666085 100644 --- a/docs/README.md +++ b/docs/README.md @@ -372,16 +372,27 @@ number: 快递单号 参数: id,用户 id,可在用户主页 URL 中找到 - ### 豆瓣 -#### 正在热映的高分电影 +#### 正在上映的电影 -举例: https://rss.now.sh/douban/playing-movie/上海/8 +举例: https://rss.now.sh/douban/movie/intheaters -路由: `/douban/playing-movie/:city/:score` +路由: `/douban/movie/intheaters` -参数: city,城市的中文名 score,返回大于等于这个分数的电影, +参数: 无 + +#### 正在上映的高分电影 + +举例: https://rss.now.sh/douban/movie/intheaters/7.5 + +路由: `/douban/movie/intheaters/:score/:city` + +参数 + +score: 返回大于等于这个分数的电影 + +city: 城市的中文名,可选,默认北京 ## 搭建 diff --git a/router.js b/router.js index 85e04375a..116ce631e 100644 --- a/router.js +++ b/router.js @@ -61,5 +61,8 @@ router.get('/mzitu/tag/:tag', require('./routes/mzitu/tag')); router.get('/pixiv/user/:id', require('./routes/pixiv/user')); // 豆瓣 -router.get('/douban/playing-movie/:city/:score', require('./routes/douban/playingMovie')); +router.get('/douban/movie/intheaters', require('./routes/douban/intheaters')); +router.get('/douban/movie/intheaters/:score', require('./routes/douban/intheaters')); +router.get('/douban/movie/intheaters/:score/:city', require('./routes/douban/intheaters')); + module.exports = router; diff --git a/routes/douban/intheaters.js b/routes/douban/intheaters.js new file mode 100644 index 000000000..8735a1f0e --- /dev/null +++ b/routes/douban/intheaters.js @@ -0,0 +1,25 @@ +const axios = require('axios'); +const art = require('art-template'); +const path = require('path'); + +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 } + }); + const movieList = score ? response.data.subjects.filter((item) => item.rating.average >= score) : response.data.subjects; + + ctx.body = art(path.resolve(__dirname, '../../views/rss.art'), { + title: `${city ? city : ''}正在上映的${score ? `超过 ${score} 分的` : ''}电影`, + link: 'https://movie.douban.com/cinema/nowplaying/', + lastBuildDate: new Date().toUTCString(), + item: movieList.map((item) => ({ + title: item.title, + description: `标题:${item.title}
影片类型:${item.genres.join(' | ')}
评分:${item.rating.average}
`, + link: item.alt + })), + }); +}; \ No newline at end of file diff --git a/routes/douban/playingMovie.js b/routes/douban/playingMovie.js deleted file mode 100644 index 0c69076f7..000000000 --- a/routes/douban/playingMovie.js +++ /dev/null @@ -1,27 +0,0 @@ -const axios = require('axios'); -const art = require('art-template'); -const path = require('path'); - -module.exports = async (ctx) => { - const city = ctx.params.city; - const score = parseFloat(ctx.params.score, 10) || 7.5; - const response = await axios({ - method: 'get', - url: 'https://api.douban.com/v2/movie/in_theaters', - params: { city } - }); - const movieList = response.data.subjects. - filter((item) => item.rating.average >= score); - - ctx.body = art(path.resolve(__dirname, '../../views/rss.art'), { - title: `${city} 最近上映的好电影`, - link: `https://movie.douban.com/cinema/nowplaying/${city}/`, - description: `${city} 最近上映的评分大于等于${score}分的电影`, - lastBuildDate: new Date().toUTCString(), - item: movieList.map((item) => ({ - title: item.title, - description: `中文名:${item.title}
类型:${item.genres.join(' | ')}
评分:${item.rating.average}
`, - link: item.alt - })), - }); -}; \ No newline at end of file