ximalaya: 更新item内容,适配itunes播客 (#524)

fix:#523
This commit is contained in:
Artin
2018-08-24 11:57:15 +08:00
committed by DIYgod
parent d3e7ad7a96
commit e7662ebec0
5 changed files with 61 additions and 15 deletions
+3 -3
View File
@@ -1512,10 +1512,10 @@ language,语言,可在 [Trending 页](https://github.com/trending/javascript
::: warning 注意
**付费内容可获取更新但无法收听**
目前[输出格式](https://docs.rsshub.app/#输出格式)中标明的格式只有 rss 支持,也就是说你**不能使用**以下链接来订阅播客:
目前支持泛用型播客订阅的[输出格式](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.rss
:::
+37
View File
@@ -66,6 +66,43 @@ ctx.state.data = {
};
```
<details><summary>如果你想制作播客馈送型RSS,点这儿</summary><br>
播客馈送是指向 XML 格式 RSS(丰富站点摘要)的网址(URL)。
这些多的字段能使你的 RSS 被泛用型播客软件订阅:
- [Podcasts Connect 帮助 创建播客 - Apple](https://help.apple.com/itc/podcasts_connect/#/itca5b22233a)
- [Podcasts Connect 帮助 播客最佳做法 - Apple](https://help.apple.com/itc/podcasts_connect/#/itc2b3780e76)
- RSS 格式参考:https://codepen.io/jon-walstedt/pen/jsIup
- 播客验证:https://podba.se/validate/?url=https://rsshub.app/ximalaya/album/299146/
```js
ctx.state.data = {
title: '', // 项目的标题
link: '', // 指向项目的链接
itunes_author: '', // 主播名字,并且开启此项就认为该RSS是播客,会自动添加头部的xmlns
itunes_category: '',// 播客分类
description: '', // 描述项目
item: [
// 其中一篇文章或一项内容
{
title: '', // 文章标题
description: '', // 文章内容或描述
pubDate: '', // 文章发布时间
guid: '', // 文章唯一标示,必须唯一,可选,默认为文章链接
link: '', // 指向文章的链接
itunes_item_image: '', // 图像
enclosure_url: '', // 音频链接
enclosure_length: '', // 时间戳(播放长度),一般是秒数
enclosure_type: '', // [.mp3就填'audio/mpeg'] [.m4a就填'audio/m4a']
itunes_duration: '', // 由enclosure_length转换为 时:分:秒
},
],
};
```
</details>
## 参与讨论
1. [Telegram 群](https://t.me/rsshub)
+1
View File
@@ -296,6 +296,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'));
+18 -12
View File
@@ -14,15 +14,16 @@ module.exports = async (ctx) => {
const authorinfo = AlbumInfoResponse.data.data.anchorInfo; // 作者数据
const trackinfo = AlbumInfoResponse.data.data.tracksInfo; // tracks数据
const classify = albuminfo.crumbs.categoryPinyin; // 专辑分类
const classify = albuminfo.crumbs.categoryPinyin; // 专辑分类的拼音
const album_category = albuminfo.crumbs.categoryTitle; // 专辑分类
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 ispaid = albuminfo.isPaid; // 是否需要付费
const album_title = albuminfo.albumTitle; // 专辑标题
const album_url = baseUrl + albumUrl; // 专辑链接
const album_desc = authorinfo.anchorName + ' ' + authorinfo.personalIntroduction + ' </br>' + albuminfo.detailRichIntro;
const album_cover_url = albuminfo.cover.split('&')[0];
const album_author = authorinfo.anchorName;
const tracks_count = trackinfo.trackTotalCount + 1;
const tracks_count = trackinfo.trackTotalCount;
const PlayInfoApi = `http://mobile.ximalaya.com/mobile/v1/album/track?albumId=${id}&pageSize=${tracks_count}`; // 声音播放数据
const PlayInfoResponse = await axios_ins.get(PlayInfoApi);
@@ -31,12 +32,15 @@ module.exports = async (ctx) => {
const resultItems = await Promise.all(
playList.map(async (item) => {
let title = item.title;
let desc = '查看收听提示: ' + baseUrl + albumUrl + item.trackId;
const title = item.title;
let desc = title + '</br>查看收听提示: </br>' + baseUrl + albumUrl + item.trackId;
if (ispaid) {
title = '[付费内容无法收听] ' + item.title;
desc = '[付费内容无法收听] 请到APP购买收听: ' + baseUrl + albumUrl + item.trackId;
desc = title + '</br> [付费内容无法收听] 原文链接: </br>' + baseUrl + albumUrl + item.trackId;
}
const enclosure_length = item.duration; // 时间长度:单位(秒)
// itunes_duration格式:<itunes:duration>32:46</itunes:duration>
const itunes_duration = Math.floor(enclosure_length / 3600) + ':' + Math.floor((enclosure_length % 3600) / 60) + ':' + (((enclosure_length % 3600) % 60) / 100).toFixed(2).slice(-2);
const resultItem = {
title: title,
link: baseUrl + albumUrl + item.trackId,
@@ -44,8 +48,9 @@ module.exports = async (ctx) => {
pubDate: new Date(item.createdAt).toUTCString(),
itunes_item_image: item.coverLarge,
enclosure_url: item.playPathAacv224,
enclosure_length: item.duration,
enclosure_type: 'audio/mpeg',
enclosure_length: enclosure_length,
enclosure_type: 'audio/m4a',
itunes_duration: itunes_duration,
};
return Promise.resolve(resultItem);
})
@@ -57,6 +62,7 @@ module.exports = async (ctx) => {
description: album_desc,
image: album_cover_url,
itunes_author: album_author,
itunes_category: album_category,
item: resultItems,
};
};
+2
View File
@@ -11,6 +11,7 @@
<generator>RSSHub</generator>
<webMaster>i@html.love (DIYgod)</webMaster>
{{ if itunes_author }}<itunes:author>{{ itunes_author}}</itunes:author>{{ /if }}
{{ if itunes_category }}<itunes:category text="{{ itunes_category }}"/>{{ /if }}
<language>zh-cn</language>
{{ if image }}
<image>
@@ -30,6 +31,7 @@
<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.itunes_duration }}<itunes:duration>{{ $value.itunes_duration }}</itunes:duration> {{ /if }}
{{ if $value.author }}<author><![CDATA[{{ $value.author }}]]></author>{{ /if }}
</item>
{{ /each }}