1+ /*
2+ @header ({
3+ searchable: 1,
4+ filterable: 1,
5+ quickSearch: 1,
6+ title: '听了么[听]',
7+ lang: 'cat'
8+ })
9+ */
10+
11+ function home ( ) {
12+ return JSON . stringify ( {
13+ 'class' : [
14+ { 'type_id' : 'hot' , 'type_name' : '热门歌单' } ,
15+ { 'type_id' : 'new' , 'type_name' : '新歌推荐' }
16+ ]
17+ } ) ;
18+ }
19+
20+ async function homeVod ( ) {
21+ let url = 'http://wapi.kuwo.cn/api/pc/classify/playlist/getRcmPlayList?loginUid=0&loginSid=0&appUid=76039576&rn=30&order=hot&pn=1' ;
22+ let res = JSON . parse ( ( await req ( url ) ) . content ) ;
23+ let data = res . data ?. data || res . data || [ ] ;
24+ let d = data . map ( it => ( {
25+ vod_name : it . name || it . title || '未命名歌单' ,
26+ vod_id : ( it . id || it . pid || '' ) . toString ( ) ,
27+ vod_pic : it . img || it . pic || it . cover || 'https://p1.music.126.net/SUeqMM8HOIpHv9Nhl9qt9w==/109951165647004069.jpg' ,
28+ vod_remarks : it . info || it . uname || it . userName || '' ,
29+ type_name : 'hot'
30+ } ) ) ;
31+ return JSON . stringify ( { list : d } ) ;
32+ }
33+
34+ async function category ( tid , pg ) {
35+ let api = `http://wapi.kuwo.cn/api/pc/classify/playlist/getRcmPlayList?loginUid=0&loginSid=0&appUid=76039576&rn=30&order=${ tid } &pn=${ pg } &_=${ Date . now ( ) } ` ;
36+ let res = JSON . parse ( ( await req ( api ) ) . content ) ;
37+ let data = res . data ?. data || res . data || [ ] ;
38+ let arr = data . map ( it => ( {
39+ vod_name : it . name || it . title || '未命名歌单' ,
40+ vod_id : ( it . id || it . pid || '' ) . toString ( ) ,
41+ vod_pic : it . img || it . pic || it . cover || 'https://p1.music.126.net/SUeqMM8HOIpHv9Nhl9qt9w==/109951165647004069.jpg' ,
42+ vod_remarks : it . info || it . uname || it . userName || '' ,
43+ type_name : tid
44+ } ) ) ;
45+ return JSON . stringify ( { list : arr , page : + pg , pagecount : 999 , limit : 30 , total : 999 } ) ;
46+ }
47+
48+ async function detail ( vod_url ) {
49+ let api = `http://nplserver.kuwo.cn/pl.svc?op=getlistinfo&pid=${ vod_url . trim ( ) } &pn=0&rn=200&encode=utf8&keyset=pl2012&identity=kuwo&pcmp4=1&vipver=MUSIC_9.1.1.2_BCS2&newver=1` ;
50+ console . log ( `✅[api]: ${ api } ` ) ;
51+ let d = JSON . parse ( ( await req ( api ) ) . content ) ;
52+ console . log ( `✅[d的结果: ]${ JSON . stringify ( d , null , 4 ) } ` ) ;
53+ let list = d . musiclist || [ ] ;
54+
55+ let playArr = [ ] ;
56+ let artistPicArr = [ ] ;
57+
58+ list . forEach ( it => {
59+ let rid = ( it . id || '' ) . toString ( ) ;
60+ let song = ( it . name || it . SONGNAME || it . displaysongname || '' ) . toString ( ) ;
61+ let artist = ( it . artist || it . ARTIST || it . FARTIST || it . displayartistname || '' ) . toString ( ) ;
62+ let albumpic = it . albumpic || '' ;
63+ let artistPic = it . artistPic || '' ;
64+ let displayName = artist ? `${ song } [${ artist } ]` : song ;
65+
66+ if ( rid ) {
67+ playArr . push ( `${ displayName } $${ rid } &&${ albumpic } &&${ artistPic } ` ) ;
68+ artistPicArr . push ( artistPic ) ;
69+ }
70+ } ) ;
71+
72+ return JSON . stringify ( {
73+ list : [ {
74+ vod_id : vod_url ,
75+ vod_name : d . name || d . title || '酷我歌单' ,
76+ vod_pic : d . pic || d . img ,
77+ vod_content : d . info || d . desc || '' ,
78+ vod_play_from : '酷我歌单' ,
79+ vod_play_pic : artistPicArr . join ( '#' ) ,
80+ vod_play_pic_ratio : 1.5 ,
81+ vod_play_url : playArr . join ( '#' )
82+ } ]
83+ } ) ;
84+ }
85+
86+ async function play ( flag , id ) {
87+ // 解析格式:显示名称$歌曲ID&&专辑图片&&歌手图片
88+ let parts = id . split ( '&&' ) ;
89+
90+ // 第一部分可能包含显示名称$歌曲ID
91+ let firstPart = parts [ 0 ] || '' ;
92+ let firstParts = firstPart . split ( '$' ) ;
93+ let songId = firstParts . length > 1 ? firstParts [ 1 ] : firstParts [ 0 ] ;
94+
95+ let albumPic = parts [ 1 ] || '' ;
96+ let artistPic = parts [ 2 ] || '' ;
97+
98+ // 优先使用专辑图片,没有则使用歌手图片
99+ let picUrl = albumPic || artistPic ;
100+
101+ if ( / \. ( m 3 u 8 | m p 4 | m 4 a | m p 3 | a a c ) ( \? | $ ) / i. test ( songId ) ) {
102+ return JSON . stringify ( {
103+ parse : 0 ,
104+ jx : 0 ,
105+ url : songId ,
106+ pic : picUrl
107+ } ) ;
108+ }
109+
110+ async function getUrl ( rid , br ) {
111+ let api = `http://nmobi.kuwo.cn/mobi.s?f=web&user=0&source=kwplayerhd_ar_4.3.0.8_tianbao_T1A_qirui.apk&type=convert_url_with_sign&rid=${ rid } &br=${ br } ` ;
112+ let j = JSON . parse ( ( await req ( api ) ) . content ) ;
113+ return j ?. data ?. url ?. trim ( ) || '' ;
114+ }
115+
116+ let url = await getUrl ( songId , '320kmp3' ) || await getUrl ( songId , '128kmp3' ) ;
117+ let lrc = await getLyric ( songId ) ;
118+
119+ return JSON . stringify ( {
120+ parse : 0 ,
121+ jx : 0 ,
122+ url : url ,
123+ pic : picUrl ,
124+ cover : albumPic ,
125+ lrc : lrc
126+ } ) ;
127+ }
128+
129+ async function getLyric ( rid ) {
130+ let url = `http://m.kuwo.cn/newh5/singles/songinfoandlrc?musicId=${ rid } ` ;
131+ let res = ( await req ( url ) ) . content ;
132+ let json = JSON . parse ( res ) ;
133+ let lrclist = json ?. data ?. lrclist ;
134+ if ( ! lrclist ) return '' ;
135+
136+ return lrclist . map ( item => {
137+ let time = + item . time ;
138+ let min = Math . floor ( time / 60 ) . toString ( ) . padStart ( 2 , '0' ) ;
139+ let sec = Math . floor ( time % 60 ) . toString ( ) . padStart ( 2 , '0' ) ;
140+ let ms = Math . floor ( ( time % 1 ) * 100 ) . toString ( ) . padStart ( 2 , '0' ) ;
141+ return `[${ min } :${ sec } .${ ms } ]${ item . lineLyric } ` ;
142+ } ) . join ( '\n' ) ;
143+ }
144+
145+ async function search ( wd , quick ) {
146+ let searchUrl = `https://search.kuwo.cn/r.s?client=kt&all=${ encodeURIComponent ( wd ) } &pn=0&rn=20&vipver=1&ft=music&encoding=utf8&rformat=json&mobi=1` ;
147+
148+ let res = ( await req ( searchUrl ) ) . content ;
149+ let json = JSON . parse ( res ) ;
150+ let d = [ ] ;
151+
152+ if ( json . abslist ) {
153+ json . abslist . forEach ( it => {
154+ if ( it . MUSICRID ) {
155+ let musicId = it . MUSICRID . replace ( 'MUSIC_' , '' ) ;
156+ let picUrl = it . hts_MVPIC || '' ;
157+
158+ d . push ( {
159+ vod_name : ( it . NAME || '未知歌曲' ) + ( it . ARTIST ? ' - ' + it . ARTIST : '' ) ,
160+ vod_id : musicId ,
161+ vod_pic : picUrl ,
162+ vod_remarks : '酷我音乐' ,
163+ type_name : 'search'
164+ } ) ;
165+ }
166+ } ) ;
167+ }
168+
169+ return JSON . stringify ( { list : d } ) ;
170+ }
171+
172+ export function __jsEvalReturn ( ) {
173+ return { home, homeVod, category, detail, play, search} ;
174+ }
0 commit comments