From 7ad64175ef926af14db204e9f475fcdd5efec85c Mon Sep 17 00:00:00 2001 From: metowolf Date: Fri, 13 Apr 2018 20:15:27 +0800 Subject: [PATCH] add ncm artist --- docs/README.md | 10 ++++++++- index.js | 3 ++- routes/ncm/artist.js | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 routes/ncm/artist.js diff --git a/docs/README.md b/docs/README.md index 88429fdbf9..8b23e5ce69 100644 --- a/docs/README.md +++ b/docs/README.md @@ -172,6 +172,14 @@ s 参数: id,歌单 id,可在歌单页 URL 中找到 +#### 歌手专辑 + +举例: https://rss.prprpr.me/ncm/artist/2116 + +路由: `/ncm/artist/:id` + +参数: id,歌手 id,可在歌手详情页 URL 中找到 + ### 掘金 #### 分类 @@ -268,4 +276,4 @@ number: 快递单号 - Redis -- Node.js \ No newline at end of file +- Node.js diff --git a/index.js b/index.js index 7dac7ca404..a8cb42974f 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,7 @@ app.get('/weibo/user/:uid', require('./routes/weibo/user')); // 网易云音乐 app.get('/ncm/playlist/:id', require('./routes/ncm/playlist')); +app.get('/ncm/artist/:id', require('./routes/ncm/artist')); // 掘金 app.get('/juejin/category/:category', require('./routes/juejin/category')); @@ -37,4 +38,4 @@ app.get('/jianshu/trending/monthly', require('./routes/jianshu/monthly')); app.get('/jianshu/collection/:id', require('./routes/jianshu/collection')); app.get('/jianshu/user/:id', require('./routes/jianshu/user')); -app.listen(1200); \ No newline at end of file +app.listen(1200); diff --git a/routes/ncm/artist.js b/routes/ncm/artist.js new file mode 100644 index 0000000000..dbb16eb7e1 --- /dev/null +++ b/routes/ncm/artist.js @@ -0,0 +1,48 @@ +const request = require('request'); +const art = require('art-template'); +const path = require('path'); +const base = require('../base'); +const mix = require('../../utils/mix'); + +module.exports = (req, res) => { + const id = req.params.id; + + base({ + req: req, + res: res, + getHTML: (callback) => { + request.get({ + url: 'https://music.163.com/api/artist/albums/' + id, + headers: { + 'User-Agent': mix.ua, + 'Referer': 'https://music.163.com/' + } + }, (err, httpResponse, body) => { + let data; + try { + data = JSON.parse(body); + } + catch (e) { + data = {}; + } + const result = data; + + const html = art(path.resolve(__dirname, '../../views/rss.art'), { + title: result.artist.name, + link: `https://music.163.com/#/album?id=${id}`, + description: `网易云音乐歌手专辑 - ${result.artist.name}`, + lastBuildDate: new Date().toUTCString(), + item: result.hotAlbums && result.hotAlbums.map((item) => { + const singer = item.artists.length === 1 ? item.artists[0].name : item.artists.reduce((prev, cur) => (prev.name || prev) + '/' + cur.name); + return { + title: `${item.name} - ${singer}`, + description: `歌手:${singer}
专辑:${item.name}
日期:${new Date(item.publishTime).toLocaleDateString()}
`, + link: `https://music.163.com/#/album?id=${item.id}` + }; + }), + }); + callback(html); + }); + } + }); +};