From f4b3027be648f2a77559c444f8a16dd67deb88bd Mon Sep 17 00:00:00 2001 From: Artin Date: Tue, 21 Aug 2018 23:58:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=96=9C=E9=A9=AC=E6=8B=89=E9=9B=85:=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=9B=E7=94=A8=E5=9E=8B=E6=92=AD=E5=AE=A2?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E6=94=AF=E6=8C=81=20(#499)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- docs/README.md | 24 ++++++++-- router.js | 2 +- routes/ximalaya/album.js | 98 ++++++++++++++++++++++------------------ views/rss.art | 9 +++- 5 files changed, 84 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 3f68f8407..7e486db87 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 攻略 - 下载 - 喜马拉雅 - - 专辑 + - 专辑(支持泛用型播客订阅) - EZTV - Lookup Torrents by IMDB ID(根据 IMDB ID 查找种子) - 什么值得买 diff --git a/docs/README.md b/docs/README.md index acb2a969b..c2d0363b7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1375,17 +1375,31 @@ language,语言,可在 [Trending 页](https://github.com/trending/javascript ## 喜马拉雅 -### 专辑 +### 专辑(支持泛用型播客订阅) -举例: [https://rsshub.app/ximalaya/album/shangye/299146/](https://rsshub.app/ximalaya/album/shangye/299146/) +::: warning 注意 +**付费内容可获取更新但无法收听** -路由: `/ximalaya/album/:classify/:id` +目前[输出格式](https://docs.rsshub.app/#输出格式)中标明的格式只有 rss 支持,也就是说你**不能使用**以下链接来订阅播客: + +- https://rsshub.app/ximalaya/album/299146.atom +- https://rsshub.app/ximalaya/album/299146.json + +::: + +举例: [https://rsshub.app/ximalaya/album/299146/](https://rsshub.app/ximalaya/album/299146/) + +路由: `/ximalaya/album/:id` 参数: -classify, 专辑分类, 可在对应专辑页面的 URL 中找到 +id, 专辑 id, 可在对应**专辑**页面的 URL 中找到 -id, 专辑 id, 可在对应专辑页面的 URL 中找到 +::: tip 提示 + +专辑 id 是跟在分类拼音后的那个 id, 不要输成某集的 id 了 + +::: ## EZTV diff --git a/router.js b/router.js index 3e05c7054..b24298d38 100755 --- a/router.js +++ b/router.js @@ -294,7 +294,7 @@ router.get('/3dm/news', require('./routes/3dm/news_center')); // 喜马拉雅 router.get('/ximalaya/album/:classify/:id', require('./routes/ximalaya/album')); - +router.get('/ximalaya/album/:id', require('./routes/ximalaya/album')); // EZTV router.get('/eztv/torrents/:imdb_id', require('./routes/eztv/imdb')); diff --git a/routes/ximalaya/album.js b/routes/ximalaya/album.js index 7a18efe32..4a515b23b 100644 --- a/routes/ximalaya/album.js +++ b/routes/ximalaya/album.js @@ -1,50 +1,62 @@ const axios = require('../../utils/axios'); -const cheerio = require('cheerio'); -const formatPubDate = require('../../utils/date.js'); - const baseUrl = 'http://www.ximalaya.com'; +const axios_ins = axios.create({ + responseType: 'json', +}); + module.exports = async (ctx) => { const id = ctx.params.id; // 专辑id - const classify = ctx.params.classify; // 专辑分类 - const apiUrl = `${baseUrl}/revision/album/getTracksList?albumId=${id}&pageNum=1&sort=1`; - const responseApi = await axios({ - method: 'get', - url: `${apiUrl}`, - headers: { - Host: 'www.ximalaya.com', - Referer: `${baseUrl}/${classify}/${id}`, - }, - }); - const responseDom = await axios({ - method: 'get', - url: `${baseUrl}/${classify}/${id}`, - headers: { - Host: 'www.ximalaya.com', - Referer: `${baseUrl}/${classify}/${id}`, - }, - }); - const $ = cheerio.load(responseDom.data); - const title = $('div.info > h1') - .eq(0) - .text(); - const cover_url = $('div.album-info>img') - .eq(0) - .attr('src'); - const trackList = responseApi.data.data.tracks; - const items = []; - for (let i = 0; i < trackList.length; i++) { - const track = trackList[i]; - const item = { - title: track.title, - link: baseUrl + track.url, - pubDate: formatPubDate(track.createDateFormat), - }; - items.push(item); - } + + const AlbumInfoApi = `http://www.ximalaya.com/revision/album?albumId=${id}`; // 专辑数据的API + const AlbumInfoResponse = await axios_ins.get(AlbumInfoApi); + + const albuminfo = AlbumInfoResponse.data.data.mainInfo; // 专辑数据 + const authorinfo = AlbumInfoResponse.data.data.anchorInfo; // 作者数据 + const trackinfo = AlbumInfoResponse.data.data.tracksInfo; // tracks数据 + + const classify = albuminfo.crumbs.categoryPinyin; // 专辑分类 + const albumUrl = '/' + classify + '/' + id + '/'; // 某分类的链接 + const ispaid = albuminfo.isPaid; + const album_title = albuminfo.albumTitle; + const album_url = baseUrl + albumUrl; + const album_desc = albuminfo.detailRichIntro + ' ' + authorinfo.anchorName + ' ' + authorinfo.personalIntroduction; + const album_cover_url = albuminfo.cover.split('&')[0]; + const album_author = authorinfo.anchorName; + const tracks_count = trackinfo.trackTotalCount + 1; + + const PlayInfoApi = `http://mobile.ximalaya.com/mobile/v1/album/track?albumId=${id}&pageSize=${tracks_count}`; // 声音播放数据 + const PlayInfoResponse = await axios_ins.get(PlayInfoApi); + + const playList = PlayInfoResponse.data.data.list; + + const resultItems = await Promise.all( + playList.map(async (item) => { + let title = item.title; + let desc = '查看收听提示: ' + baseUrl + albumUrl + item.trackId; + if (ispaid) { + title = '[付费内容无法收听] ' + item.title; + desc = '[付费内容无法收听] 请到APP购买收听: ' + baseUrl + albumUrl + item.trackId; + } + const resultItem = { + title: title, + link: baseUrl + albumUrl + item.trackId, + description: desc, + pubDate: new Date(item.createdAt).toUTCString(), + itunes_item_image: item.coverLarge, + enclosure_url: item.playPathAacv224, + enclosure_length: item.duration, + enclosure_type: 'audio/mpeg', + }; + return Promise.resolve(resultItem); + }) + ); + ctx.state.data = { - title: `喜马拉雅专辑 - ${title}`, - link: `${baseUrl}/${classify}/${id}`, - image: cover_url, - item: items, + title: `${album_title}`, + link: `${album_url}`, + description: album_desc, + image: album_cover_url, + itunes_author: album_author, + item: resultItems, }; }; diff --git a/views/rss.art b/views/rss.art index eb3764140..6fa48c7c2 100644 --- a/views/rss.art +++ b/views/rss.art @@ -1,11 +1,16 @@ +{{ if itunes_author }} + +{{else}} +{{ /if }} <![CDATA[{{@ title || 'RSSHub' }}]]> {{ link || 'https://github.com/DIYgod/RSSHub' }} RSSHub - i@html.love + i@html.love (DIYgod) + {{ if itunes_author }}{{ itunes_author}}{{ /if }} zh-cn {{ if image }} @@ -23,6 +28,8 @@ {{ if $value.pubDate }}{{ $value.pubDate }}{{ /if }} {{ $value.guid || $value.link }} {{ $value.link }} + {{ if $value.itunes_item_image }}{{ /if }} + {{ if $value.enclosure_url }}{{ /if }} {{ if $value.author }}{{ /if }} {{ /each }}