11import { httpFetch } from '../../request'
2- import { decodeLyric } from './util '
2+ import { decodeName } from '../../index '
33
44export default {
5+ formatTime ( time ) {
6+ let m = parseInt ( time / 60 )
7+ let s = ( time % 60 ) . toFixed ( 2 )
8+ return ( m < 10 ? '0' + m : m ) + ':' + ( s < 10 ? '0' + s : s )
9+ } ,
10+ sortLrcArr ( arr ) {
11+ const lrcSet = new Set ( )
12+ let lrc = [ ]
13+ let lrcT = [ ]
14+
15+ for ( const item of arr ) {
16+ if ( lrcSet . has ( item . time ) ) {
17+ lrc . push ( item )
18+ } else {
19+ lrcT . push ( item )
20+ lrcSet . add ( item . time )
21+ }
22+ }
23+ if ( lrc . length ) {
24+ lrc . unshift ( lrcT . shift ( ) )
25+ } else {
26+ lrc = lrcT
27+ lrcT = [ ]
28+ }
29+
30+ return {
31+ lrc,
32+ lrcT,
33+ }
34+ } ,
35+ transformLrc ( songinfo , lrclist ) {
36+ return `[ti:${ songinfo . songName } ]\n[ar:${ songinfo . artist } ]\n[al:${ songinfo . album } ]\n[by:]\n[offset:0]\n${ lrclist ? lrclist . map ( l => `[${ this . formatTime ( l . time ) } ]${ l . lineLyric } \n` ) . join ( '' ) : '暂无歌词' } `
37+ } ,
38+ getLyric ( songId ) {
39+ const requestObj = httpFetch ( `http://m.kuwo.cn/newh5/singles/songinfoandlrc?musicId=${ songId } ` )
40+ requestObj . promise = requestObj . promise . then ( ( { body } ) => {
41+ // console.log(body)
42+ if ( ! body . data ?. lrclist ?. length ) return Promise . reject ( new Error ( 'Get lyric failed' ) )
43+ const { lrc, lrcT } = this . sortLrcArr ( body . data . lrclist )
44+ // console.log(body.data.lrclist)
45+ // console.log(lrc, lrcT)
46+ // console.log({
47+ // lyric: decodeName(this.transformLrc(body.data.songinfo, lrc)),
48+ // tlyric: decodeName(this.transformLrc(body.data.songinfo, lrcT)),
49+ // })
50+ return {
51+ lyric : decodeName ( this . transformLrc ( body . data . songinfo , lrc ) ) ,
52+ tlyric : lrcT . length ? decodeName ( this . transformLrc ( body . data . songinfo , lrcT ) ) : '' ,
53+ }
54+ } )
55+ return requestObj
56+ } ,
57+ }
58+
59+
60+ /* export default {
561 lrcInfoRxp: /<lyric>(.+?)<\/lyric>[\s\S]+<lyric_zz>(.+?)<\/lyric_zz>/,
662 parseLyricInfo(str) {
763 let result = str.match(this.lrcInfoRxp)
@@ -10,6 +66,7 @@ export default {
1066 getLyric(songId, isGetLyricx = false) {
1167 const requestObj = httpFetch(`http://player.kuwo.cn/webmusic/st/getNewMuiseByRid?rid=MUSIC_${songId}`)
1268 requestObj.promise = requestObj.promise.then(({ statusCode, body }) => {
69+ console.log(body)
1370 if (statusCode != 200) return Promise.reject(new Error(JSON.stringify(body)))
1471 let info = this.parseLyricInfo(body)
1572 if (!info) return Promise.reject(new Error(JSON.stringify(body)))
@@ -27,3 +84,4 @@ export default {
2784 return requestObj
2885 },
2986}
87+ */
0 commit comments