fix(route): 喜马拉雅(#8516) (#8520)

This commit is contained in:
prnake
2021-11-27 09:09:45 +00:00
committed by GitHub
parent 10bf6a572f
commit 3b83b0ec4b
5 changed files with 16 additions and 19 deletions
+1 -1
View File
@@ -201,7 +201,7 @@
source: '/:type/:id',
target: (params) => {
if (parseInt(params.id) + '' === params.id) {
return '/ximalaya/album/:id/';
return '/ximalaya/:type/:id/';
}
},
},
+3 -3
View File
@@ -1166,12 +1166,12 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
### 专辑(不输出 ShowNote)
<Route author="lengthmin jjeejj prnake" example="/ximalaya/album/299146" path="/ximalaya/album/:id/:all?" :paramsDesc="['专辑 id, 可在对应专辑页面的 URL 中找到','是否需要获取全部节目,填入 `1`、`true`、`all` 视为获取所有节目,填入其他则不获取。']" supportPodcast="1" radar="1" rssbud="1" selfhost="1">
<Route author="lengthmin jjeejj prnake" example="/ximalaya/album/299146" path="/ximalaya/:type/:id/:all?" :paramsDesc="['专辑类型, 通常可以使用 `album`,可在对应专辑页面的 URL 中找到','专辑 id, 可在对应专辑页面的 URL 中找到','是否需要获取全部节目,填入 `1`、`true`、`all` 视为获取所有节目,填入其他则不获取。']" supportPodcast="1" radar="1" rssbud="1" selfhost="1">
目前喜马拉雅的 API 只能一集一集的获取各节目上的 ShowNote,会极大的占用系统资源,所以默认为不获取节目的 ShowNote。下方有一个新的路径可选获取 ShowNote。
::: warning 注意
专辑 id 是跟在**分类拼音**后的那个 id, 不要输成某集的 id 了
专辑类型即 url 中的分类拼音,使用通用分类 `album` 通常是可行的,专辑 id 是跟在**分类拼音**后的那个 id, 不要输成某集的 id 了
**付费内容需要配置好已购买账户的 token 才能收听,详情见部署页面的配置模块**
:::
@@ -1180,7 +1180,7 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
### 专辑(输出 ShowNote)
<Route author="lengthmin jjeejj prnake" example="/ximalaya/album/39488639/0/shownote" path="/ximalaya/album/:id/:all/:shownote?" :paramsDesc="['专辑 id, 可在对应专辑页面的 URL 中找到','是否需要获取全部节目,填入 `1`、`true`、`all` 视为获取所有节目,填入其他则不获取。', '是否需要获取节目的 ShowNote,填入 `1`、`true`,`shownote` 视为获取,填入其他则不获取。']" supportPodcast="1" selfhost="1">
<Route author="lengthmin jjeejj prnake" example="/ximalaya/album/39488639/0/shownote" path="/ximalaya/:type/:id/:all/:shownote?" :paramsDesc="['专辑类型, 通常可以使用 `album`,可在对应专辑页面的 URL 中找到','专辑 id, 可在对应专辑页面的 URL 中找到','是否需要获取全部节目,填入 `1`、`true`、`all` 视为获取所有节目,填入其他则不获取。', '是否需要获取节目的 ShowNote,填入 `1`、`true`,`shownote` 视为获取,填入其他则不获取。']" supportPodcast="1" selfhost="1">
</Route>
+1 -1
View File
@@ -463,7 +463,7 @@ module.exports = {
source: '/:type/:id',
target: (params) => {
if (parseInt(params.id) + '' === params.id) {
return '/ximalaya/album/:id/';
return '/ximalaya/:type/:id/';
}
},
},
+2 -2
View File
@@ -327,8 +327,8 @@ router.get('/3dm/:name/:type', lazyloadRouteHandler('./routes/3dm/game'));
router.get('/3dm/news', lazyloadRouteHandler('./routes/3dm/news_center'));
// 喜马拉雅
router.get('/ximalaya/album/:id/:all?', lazyloadRouteHandler('./routes/ximalaya/album'));
router.get('/ximalaya/album/:id/:all/:shownote?', lazyloadRouteHandler('./routes/ximalaya/album'));
router.get('/ximalaya/:type/:id/:all?', lazyloadRouteHandler('./routes/ximalaya/album'));
router.get('/ximalaya/:type/:id/:all/:shownote?', lazyloadRouteHandler('./routes/ximalaya/album'));
// EZTV
router.get('/eztv/torrents/:imdb_id', lazyloadRouteHandler('./routes/eztv/imdb'));
+9 -12
View File
@@ -1,12 +1,7 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { getUrl, getRandom16 } = require('./utils');
const baseUrl = 'http://www.ximalaya.com';
const gotIns = got.extend({
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36',
},
});
const baseUrl = 'https://www.ximalaya.com';
const config = require('@/config').value;
// Find category from: https://help.apple.com/itc/podcasts_connect/?lang=en#/itc9267a2f12
@@ -47,11 +42,12 @@ function getTextFromElement(element) {
return '';
}
async function parseAlbumData(album_id) {
async function parseAlbumData(category, album_id) {
// 解析网页版的 HTML 获取该专辑的信息
// 这里的 {category} 并不重要,系统会准确的返回该 id 对应专辑的信息
// 现在 {category} 必须要精确到大的类别
// https://www.ximalaya.com/{category}/{album_id}/
const response = await gotIns(`https://www.ximalaya.com/category/${album_id}/`);
const response = await got(`https://www.ximalaya.com/${category}/${album_id}/`);
const data = response.body;
const $ = cheerio.load(data);
const stateElement = $('script')
@@ -83,12 +79,13 @@ function judgeTrue(str, ...validStrings) {
}
module.exports = async (ctx) => {
const type = ctx.params.type; // 专辑分类
const id = ctx.params.id; // 专辑id
const shouldAll = judgeTrue(ctx.params.all, 'all');
const shouldShowNote = judgeTrue(ctx.params.shownote, 'shownote');
const pageSize = shouldAll ? 200 : 30;
const albumData = await parseAlbumData(id);
const albumData = await parseAlbumData(type, id);
const isPaid = albumData.store.AlbumDetailPage.albumPageMainInfo.isPaid;
@@ -108,7 +105,7 @@ module.exports = async (ctx) => {
// const isAsc = albumData.store.AlbumDetailTrackList.sort === 0;
// 喜马拉雅的 API 的 query 参数 isAsc=0 时才是升序,不写就是降序。
const trackInfoApi = `http://mobile.ximalaya.com/mobile/v1/album/track/?albumId=${id}&pageSize=${pageSize}&pageId=`;
const trackInfoResponse = await gotIns.get(trackInfoApi + '1');
const trackInfoResponse = await got.get(trackInfoApi + '1');
const maxPageId = trackInfoResponse.data.data.maxPageId; // 最大页数
let playList = trackInfoResponse.data.data.list;
@@ -117,7 +114,7 @@ module.exports = async (ctx) => {
const promises = [];
for (let i = 2; i <= maxPageId; i++) {
// string + number -> string
promises.push(gotIns.get(trackInfoApi + i));
promises.push(got.get(trackInfoApi + i));
}
const responses = await Promise.all(promises);
for (let j = 0; j < responses.length; j++) {
@@ -132,7 +129,7 @@ module.exports = async (ctx) => {
let _desc;
if (shouldShowNote) {
const trackRichInfoApi = `https://mobile.ximalaya.com/mobile-track/richIntro?trackId=${item.trackId}`;
const trackRichInfoResponse = await gotIns.get(trackRichInfoApi);
const trackRichInfoResponse = await got.get(trackRichInfoApi);
_desc = trackRichInfoResponse.data.richIntro;
}
if (!_desc) {