喜马拉雅: 增加泛用型播客订阅支持 (#499)
This commit is contained in:
parent
7e40e5cc87
commit
f4b3027be6
|
|
@ -169,7 +169,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
|
|||
- 攻略
|
||||
- 下载
|
||||
- 喜马拉雅
|
||||
- 专辑
|
||||
- 专辑(支持泛用型播客订阅)
|
||||
- EZTV
|
||||
- Lookup Torrents by IMDB ID(根据 IMDB ID 查找种子)
|
||||
- 什么值得买
|
||||
|
|
|
|||
|
|
@ -1375,17 +1375,31 @@ language,语言,可在 [Trending 页](https://github.com/trending/javascript
|
|||
|
||||
## 喜马拉雅
|
||||
|
||||
### 专辑 <Author uid="jjeejj"/>
|
||||
### 专辑(支持泛用型播客订阅) <Author uid="lengthmin jjeejj"/>
|
||||
|
||||
举例: [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
|
||||
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
{{ if itunes_author }}
|
||||
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
|
||||
{{else}}
|
||||
<rss version="2.0">
|
||||
{{ /if }}
|
||||
<channel>
|
||||
<title><![CDATA[{{@ title || 'RSSHub' }}]]></title>
|
||||
<link>{{ link || 'https://github.com/DIYgod/RSSHub' }}</link>
|
||||
<description><![CDATA[{{@ description || title }} - Made with love by RSSHub(https://github.com/DIYgod/RSSHub)]]></description>
|
||||
<generator>RSSHub</generator>
|
||||
<webMaster>i@html.love</webMaster>
|
||||
<webMaster>i@html.love (DIYgod)</webMaster>
|
||||
{{ if itunes_author }}<itunes:author>{{ itunes_author}}</itunes:author>{{ /if }}
|
||||
<language>zh-cn</language>
|
||||
{{ if image }}
|
||||
<image>
|
||||
|
|
@ -23,6 +28,8 @@
|
|||
{{ if $value.pubDate }}<pubDate>{{ $value.pubDate }}</pubDate>{{ /if }}
|
||||
<guid>{{ $value.guid || $value.link }}</guid>
|
||||
<link>{{ $value.link }}</link>
|
||||
{{ if $value.itunes_item_image }}<itunes:image href="{{ $value.itunes_item_image }}"/>{{ /if }}
|
||||
{{ if $value.enclosure_url }}<enclosure url="{{ $value.enclosure_url }}" length="{{ $value.enclosure_length }}" type="{{ $value.enclosure_type }}" />{{ /if }}
|
||||
{{ if $value.author }}<author><![CDATA[{{ $value.author }}]]></author>{{ /if }}
|
||||
</item>
|
||||
{{ /each }}
|
||||
|
|
|
|||
Loading…
Reference in New Issue