Skip to content

Commit f1117bc

Browse files
authored
fix(route/radio): use new api (#19283)
1 parent e98eef7 commit f1117bc

File tree

2 files changed

+42
-51
lines changed

2 files changed

+42
-51
lines changed

lib/routes/radio/album.ts

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Route } from '@/types';
22

3-
import got from '@/utils/got';
3+
import ofetch from '@/utils/ofetch';
44
import { parseDate } from '@/utils/parse-date';
55
import { art } from '@/utils/render';
66
import path from 'node:path';
7-
import CryptoJS from 'crypto-js';
7+
import timezone from '@/utils/timezone';
88

99
const audio_types = {
1010
m3u8: 'x-mpegURL',
@@ -39,79 +39,70 @@ export const route: Route = {
3939
};
4040

4141
async function handler(ctx) {
42-
const KEY = 'f0fc4c668392f9f9a447e48584c214ee';
43-
4442
const id = ctx.req.param('id');
45-
const size = ctx.req.query('limit') ?? '100';
46-
47-
const rootUrl = 'https://www.radio.cn';
48-
49-
const currentUrl = `${rootUrl}/pc-portal/sanji/detail.html?columnId=${id}`;
50-
const apiRootUrl = 'https://ytmsout.radio.cn';
51-
52-
const timestamp = Date.now();
53-
const id_params = `id=${id}`;
54-
const detailApiUrl = `${apiRootUrl}/web/appAlbum/detail/${id}?${id_params}`;
55-
56-
const details = await got({
57-
method: 'get',
58-
url: detailApiUrl,
59-
headers: {
60-
sign: CryptoJS.MD5(`${id_params}&timestamp=${timestamp}&key=${KEY}`).toString().toUpperCase(),
61-
timestamp,
62-
'Content-Type': 'application/json',
63-
equipmentId: '0000',
64-
platformCode: 'WEB',
65-
},
66-
});
6743

68-
const params = `albumId=${id}&pageNo=0&pageSize=${size}`;
69-
const apiUrl = `${apiRootUrl}/web/appSingle/pageByAlbum?${params}`;
44+
const rootUrl = 'https://ytweb.radio.cn';
45+
const currentUrl = `${rootUrl}/share/albumDetail?columnId=${id}`;
46+
const apiRootUrl = 'https://ytapi.radio.cn';
7047

71-
const response = await got({
72-
method: 'get',
73-
url: apiUrl,
48+
const response = await ofetch(`${apiRootUrl}/ytsrv/srv/wifimusicbox/demand/detail`, {
49+
method: 'POST',
7450
headers: {
75-
sign: CryptoJS.MD5(`${params}&timestamp=${timestamp}&key=${KEY}`).toString().toUpperCase(),
76-
timestamp,
77-
'Content-Type': 'application/json',
78-
equipmentId: '0000',
79-
platformCode: 'WEB',
51+
accept: 'application/json, text/plain, */*',
52+
'content-type': 'application/x-www-form-urlencoded',
53+
equipmentSource: 'WEB', // only this header is mandatory
54+
equipmentType: '3',
55+
platformCode: 'H5',
56+
productId: '1605403829833195520',
57+
providerCode: '25010',
58+
referer: 'https://ytweb.radio.cn/',
59+
timestamp: String(Date.now()),
60+
version: '4.0.0',
8061
},
62+
body: new URLSearchParams({
63+
pageIndex: '0',
64+
sortType: '',
65+
mobileId: '',
66+
providerCode: '25010',
67+
pid: id,
68+
paySongFlag: '1',
69+
richText: '1',
70+
h5flag: '1',
71+
}),
72+
parseResponse: JSON.parse,
8173
});
8274

83-
const data = response.data.data.data;
84-
const items = data.map((item) => {
85-
let enclosure_url = item.playUrlHigh ?? item.playUrlLow;
75+
const items = response.con.map((item) => {
76+
let enclosure_url = item.playUrlHigh ?? item.playUrlMedium ?? item.playUrlLow ?? item.playUrl;
8677
enclosure_url = /\.m3u8$/.test(enclosure_url) ? item.downloadUrl : enclosure_url;
8778

88-
const file_ext = new URL(enclosure_url).pathname.split('.').pop();
89-
const enclosure_type = file_ext ? `audio/${audio_types[file_ext]}` : '';
79+
const fileExt = new URL(enclosure_url).pathname.split('.').pop();
80+
const enclosure_type = fileExt ? `audio/${audio_types[fileExt]}` : '';
9081

9182
return {
9283
guid: item.id,
9384
title: item.name,
94-
link: enclosure_url,
85+
link: `${rootUrl}/share/albumPlay?correlateId=${item.id}&columnId=${id}`,
9586
description: art(path.join(__dirname, 'templates/description.art'), {
96-
description: item.des,
9787
enclosure_url,
9888
enclosure_type,
9989
}),
100-
pubDate: parseDate(item.publishTime),
90+
pubDate: timezone(parseDate(item.createTime), +8),
10191
enclosure_url,
10292
enclosure_type,
10393
enclosure_length: item.fileSize,
10494
itunes_duration: item.duration,
105-
itunes_item_image: details.data.data.image,
95+
itunes_item_image: item.logoUrl,
10696
};
10797
});
10898

10999
return {
110-
title: `云听 - ${details.data.data.name}`,
100+
title: `云听 - ${response.columnName}`,
111101
link: currentUrl,
112102
item: items,
113-
image: details.data.data.image,
114-
description: details.data.data.des ?? details.data.data.desSimple,
115-
itunes_author: details.data.data.ownerNickName || 'radio.cn',
103+
image: response.posterInfo.imgUrl,
104+
logo: response.logoUrl,
105+
description: response.descriptions ?? response.descriptionSimple,
106+
itunes_author: response.ownerNickName || 'radio.cn',
116107
};
117108
}

lib/routes/radio/templates/description.art

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<p>{{ description }}</p>
33
{{ /if }}
44
{{ if enclosure_url && enclosure_type }}
5-
<audio controls="controls">
5+
<audio controls="controls" preload="metadata">
66
<source src="{{ enclosure_url }}" type="{{ enclosure_type }}">
77
</audio>
8-
{{ /if }}
8+
{{ /if }}

0 commit comments

Comments
 (0)