Skip to content

Commit 3a615a4

Browse files
committed
新增百度音源
1 parent 78d2541 commit 3a615a4

14 files changed

Lines changed: 245 additions & 11 deletions

File tree

publish/changeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
### 新增
22

3+
- 新增**百度音乐**排行榜及其音乐直接试听与下载
34
- 新增网易云排行榜音乐直接试听与下载(目前仅支持128k音质)
45
- 新增酷狗排行榜音乐直接试听与下载(目前仅支持128k音质)
56

67
### 修复
78

89
- 修复更新弹窗历史版本描述多余的换行问题
10+
- 修复歌曲无法播放的情况下歌词仍会播放的问题

src/renderer/components/core/Player.vue

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ export default {
6161
name: '^',
6262
singer: '^',
6363
},
64+
targetSong: null,
6465
pregessWidth: 0,
6566
lyric: {
6667
lrc: null,
6768
text: '',
6869
line: 0,
6970
},
71+
retryNum: 0,
7072
}
7173
},
7274
computed: {
@@ -137,6 +139,7 @@ export default {
137139
'fixPlayIndex',
138140
'resetChangePlay',
139141
]),
142+
...mapMutations('list', ['updateMusicInfo']),
140143
init() {
141144
this.audio = document.createElement('audio')
142145
this.audio.controls = false
@@ -161,10 +164,16 @@ export default {
161164
this.handleNext()
162165
})
163166
this.audio.addEventListener('error', () => {
167+
// console.log('code', this.audio.error.code)
164168
if (!this.musicInfo.songmid) return
165169
console.log('出错')
170+
if (this.audio.error.code == 4 && this.retryNum < 5) {
171+
// console.log(this.retryNum)
172+
this.retryNum++
173+
this.setUrl(this.list[this.playIndex], true)
174+
return
175+
}
166176
this.stopPlay()
167-
this.status = '加载出错'
168177
this.sendProgressEvent(this.progress, 'error')
169178
170179
// let urls = this.player_info.targetSong.urls
@@ -182,10 +191,14 @@ export default {
182191
// } else {
183192
// this.handleNext()
184193
// }
185-
this.handleNext()
194+
this.status = '音频加载出错,2 两秒后切换下一首'
195+
setTimeout(() => {
196+
this.handleNext()
197+
}, 2000)
186198
})
187199
this.audio.addEventListener('loadeddata', () => {
188200
this.maxPlayTime = this.audio.duration
201+
if (!this.targetSong.interval && this.listId != 'download') this.updateMusicInfo({ index: this.playIndex, data: { interval: formatPlayTime2(this.maxPlayTime) } })
189202
this.status = '音乐加载中...'
190203
})
191204
// this.audio.addEventListener('loadstart', () => {
@@ -228,7 +241,8 @@ export default {
228241
},
229242
play() {
230243
console.log('play', this.playIndex)
231-
let targetSong = this.list[this.playIndex]
244+
let targetSong = this.targetSong = this.list[this.playIndex]
245+
this.retryNum = 0
232246
233247
if (this.listId == 'download') {
234248
if (!checkPath(targetSong.filePath) || !targetSong.isComplate || /\.ape$/.test(targetSong.filePath)) {
@@ -321,16 +335,21 @@ export default {
321335
this.musicInfo.img = null
322336
},
323337
getPlayType(highQuality, songInfo) {
338+
switch (songInfo.source) {
339+
case 'wy':
340+
case 'kg':
341+
return '128k'
342+
}
324343
let type = songInfo._types['192k'] ? '192k' : '128k'
325344
if (highQuality && songInfo._types['320k']) type = '320k'
326345
return type
327346
},
328-
setUrl(targetSong) {
347+
setUrl(targetSong, isRefresh) {
329348
let type = this.getPlayType(this.setting.player.highQuality, targetSong)
330349
this.musicInfo.url = targetSong.typeUrl[type]
331350
this.status = '歌曲链接获取中...'
332351
333-
let urlP = this.musicInfo.url
352+
let urlP = this.musicInfo.url && !isRefresh
334353
? Promise.resolve()
335354
: this.getUrl({ musicInfo: targetSong, type }).then(() => {
336355
this.musicInfo.url = targetSong.typeUrl[type]
@@ -366,7 +385,7 @@ export default {
366385
lrcP
367386
.then(() => {
368387
this.lyric.lrc.setLyric(this.musicInfo.lrc)
369-
if (this.isPlay) this.lyric.lrc.play(this.audio.currentTime * 1000)
388+
if (this.isPlay && (this.musicInfo.url || this.listId == 'download')) this.lyric.lrc.play(this.audio.currentTime * 1000)
370389
})
371390
.catch(err => {
372391
this.status = err.message

src/renderer/store/modules/download.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ const actions = {
191191
commit('resumeTask', downloadInfo)
192192
},
193193
}
194+
commit('setStatusText', { downloadInfo, text: '获取URL中...' })
194195
let p = options.url ? Promise.resolve() : refreshUrl(downloadInfo).then(result => {
195196
commit('updateUrl', { downloadInfo, url: result.url })
196197
if (!result.url) return Promise.reject(new Error('获取URL失败'))

src/renderer/store/modules/list.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ const mutations = {
3939
defaultListRemove(state, index) {
4040
state.defaultList.list.splice(index, 1)
4141
},
42+
updateMusicInfo(state, { index, data }) {
43+
Object.assign(state.defaultList.list[index], data)
44+
},
4245
defaultListRemoveMultiple(state, list) {
4346
list.forEach(musicInfo => {
4447
let index = state.defaultList.list.indexOf(musicInfo)

src/renderer/store/modules/player.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const actions = {
3535
if (picRequest && picRequest.cancelHttp) picRequest.cancelHttp()
3636
picRequest = music[musicInfo.source].getPic(musicInfo)
3737
return picRequest.promise.then(url => {
38-
console.log(url)
3938
commit('getPic', { musicInfo, url })
4039
}).finally(() => {
4140
picRequest = null

src/renderer/utils/music/api-source.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import kw_api_temp from './kw/api-temp'
33
import tx_api_messoer from './tx/api-messoer'
44
import kg_api_messoer from './kg/api-messoer'
55
import wy_api_messoer from './wy/api-messoer'
6+
import bd_api_messoer from './bd/api-messoer'
67

78
const apis = {
89
kw_api_messoer,
910
tx_api_messoer,
1011
kg_api_messoer,
1112
wy_api_messoer,
13+
bd_api_messoer,
1214
kw_api_temp,
1315
}
1416

@@ -30,6 +32,8 @@ export default source => {
3032
return getAPI('kg')
3133
case 'wy':
3234
return getAPI('wy')
35+
case 'bd':
36+
return getAPI('bd')
3337
default:
3438
return getAPI('kw')
3539
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { httpFatch } from '../../request'
2+
import { requestMsg } from '../../message'
3+
4+
const api_messoer = {
5+
getMusicUrl(songInfo, type) {
6+
const requestObj = httpFatch(`https://v1.itooi.cn/baidu/url?id=${songInfo.songmid}&quality=${type.replace(/k$/, '')}&isRedirect=0`, {
7+
method: 'get',
8+
timeout: 5000,
9+
})
10+
requestObj.promise = requestObj.promise.then(({ body }) => {
11+
return body.code === 200 ? Promise.resolve({ type, url: body.data }) : Promise.reject(new Error(requestMsg.fail))
12+
})
13+
return requestObj
14+
},
15+
getPic(songInfo, size = '500') {
16+
const requestObj = httpFatch(`https://v1.itooi.cn/baidu/pic?id=${songInfo.songmid}&imageSize=${size}&isRedirect=0`, {
17+
method: 'get',
18+
timeout: 5000,
19+
})
20+
requestObj.promise = requestObj.promise.then(({ body }) => {
21+
return body.code === 200 ? Promise.resolve(body.data) : Promise.reject(new Error(requestMsg.fail))
22+
})
23+
return requestObj
24+
},
25+
getLyric(songInfo) {
26+
const requestObj = httpFatch(`https://v1.itooi.cn/baidu/lrc?id=${songInfo.songmid}&isRedirect=0`, {
27+
method: 'get',
28+
timeout: 5000,
29+
})
30+
requestObj.promise = requestObj.promise.then(({ body }) => {
31+
return body ? Promise.resolve(body) : Promise.reject(new Error(requestMsg.fail))
32+
})
33+
return requestObj
34+
},
35+
}
36+
37+
export default api_messoer
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import leaderboard from './leaderboard'
2+
import api_source from '../api-source'
3+
import musicInfo from './musicInfo'
4+
5+
const bd = {
6+
leaderboard,
7+
getMusicUrl(songInfo, type) {
8+
return api_source('bd').getMusicUrl(songInfo, type)
9+
},
10+
getLyric(songInfo) {
11+
return api_source('bd').getLyric(songInfo)
12+
},
13+
getPic(songInfo) {
14+
return api_source('bd').getPic(songInfo)
15+
},
16+
getMusicInfo(songInfo) {
17+
return musicInfo.getMusicInfo(songInfo.songmid)
18+
},
19+
}
20+
21+
export default bd
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import { httpFatch } from '../../request'
2+
// import { formatPlayTime } from '../../index'
3+
// import jshtmlencode from 'js-htmlencode'
4+
5+
export default {
6+
limit: 20,
7+
list: [
8+
{
9+
id: 'bdrgb',
10+
name: '热歌榜',
11+
bangid: '2',
12+
},
13+
{
14+
id: 'bdxgb',
15+
name: '新歌榜',
16+
bangid: '1',
17+
},
18+
{
19+
id: 'bdycb',
20+
name: '原创榜',
21+
bangid: '200',
22+
},
23+
{
24+
id: 'bdhyjqb',
25+
name: '华语榜',
26+
bangid: '20',
27+
},
28+
{
29+
id: 'bdomjqb',
30+
name: '欧美榜',
31+
bangid: '21',
32+
},
33+
{
34+
id: 'bdwugqb',
35+
name: '网络榜',
36+
bangid: '25',
37+
},
38+
{
39+
id: 'bdjdlgb',
40+
name: '老歌榜',
41+
bangid: '22',
42+
},
43+
{
44+
id: 'bdysjqb',
45+
name: '影视金曲榜',
46+
bangid: '24',
47+
},
48+
{
49+
id: 'bdqgdcb',
50+
name: '情歌对唱榜',
51+
bangid: '23',
52+
},
53+
{
54+
id: 'bdygb',
55+
name: '摇滚榜',
56+
bangid: '11',
57+
},
58+
],
59+
getUrl(id, p) {
60+
return `http://musicmini.qianqian.com/2018/static/bangdan/bangdanList_${id}_${p}.html`
61+
},
62+
regExps: {
63+
item: /data-song="({.+?})"/g,
64+
info: /{total[\s:]+"(\d+)", size[\s:]+"(\d+)", page[\s:]+"(\d+)"}/,
65+
},
66+
requestObj: null,
67+
getData(url) {
68+
if (this.requestObj) this.requestObj.cancelHttp()
69+
this.requestObj = httpFatch(url)
70+
return this.requestObj.promise
71+
},
72+
filterData(rawList) {
73+
// console.log(rawList)
74+
return rawList.map(item => {
75+
const types = []
76+
const _types = {}
77+
let size = null
78+
types.push({ type: '128k', size })
79+
_types['128k'] = {
80+
size,
81+
}
82+
if (item.biaoshi) {
83+
types.push({ type: '320k', size })
84+
_types['320k'] = {
85+
size,
86+
}
87+
types.push({ type: 'flac', size })
88+
_types['flac'] = {
89+
size,
90+
}
91+
}
92+
// types.reverse()
93+
94+
return {
95+
singer: item.song_artist.replace(',', '、'),
96+
name: item.song_title,
97+
albumName: item.album_title,
98+
albumId: item.album_id,
99+
source: 'bd',
100+
interval: '',
101+
songmid: item.song_id,
102+
img: null,
103+
lrc: null,
104+
types,
105+
_types,
106+
typeUrl: {},
107+
}
108+
})
109+
},
110+
parseData(rawData) {
111+
// return rawData.map(item => JSON.parse(item.replace(this.regExps.item, '$1').replace(/&quot;/g, '"').replace(/\\\//g, '/').replace(/(@s_1,w_)\d+(,h_)\d+/, '$1500$2500')))
112+
return rawData.map(item => JSON.parse(item.replace(this.regExps.item, '$1').replace(/&quot;/g, '"').replace(/\\\//g, '/')))
113+
},
114+
getList(id, page) {
115+
let type = this.list.find(s => s.id === id)
116+
if (!type) return Promise.reject()
117+
return this.getData(this.getUrl(type.bangid, page)).then(({ body }) => {
118+
let result = body.match(this.regExps.item)
119+
if (!result) return Promise.reject(new Error('匹配list失败'))
120+
let info = body.match(this.regExps.info)
121+
if (!info) return Promise.reject(new Error('匹配info失败'))
122+
const list = this.filterData(this.parseData(result))
123+
this.limit = parseInt(info[2])
124+
return {
125+
total: parseInt(info[1]),
126+
list,
127+
limit: this.limit,
128+
page: parseInt(info[3]),
129+
}
130+
})
131+
},
132+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { httpFatch } from '../../request'
2+
3+
export default {
4+
getMusicInfo(songmid) {
5+
const requestObj = httpFatch(`https://musicapi.qianqian.com/v1/restserver/ting?method=baidu.ting.song.getSongLink&format=json&from=bmpc&version=1.0.0&version_d=11.1.6.0&songid=${songmid}&type=1&res=1&s_protocol=1&aac=2&project=tpass`)
6+
requestObj.promise = requestObj.promise.then(({ body }) => {
7+
return body.error_code == 22000 ? body.reqult.songinfo : Promise.reject(new Error('获取音乐信息失败'))
8+
})
9+
return requestObj
10+
},
11+
}

0 commit comments

Comments
 (0)