新增百度音源
This commit is contained in:
@@ -3,12 +3,14 @@ import kw_api_temp from './kw/api-temp'
|
||||
import tx_api_messoer from './tx/api-messoer'
|
||||
import kg_api_messoer from './kg/api-messoer'
|
||||
import wy_api_messoer from './wy/api-messoer'
|
||||
import bd_api_messoer from './bd/api-messoer'
|
||||
|
||||
const apis = {
|
||||
kw_api_messoer,
|
||||
tx_api_messoer,
|
||||
kg_api_messoer,
|
||||
wy_api_messoer,
|
||||
bd_api_messoer,
|
||||
kw_api_temp,
|
||||
}
|
||||
|
||||
@@ -30,6 +32,8 @@ export default source => {
|
||||
return getAPI('kg')
|
||||
case 'wy':
|
||||
return getAPI('wy')
|
||||
case 'bd':
|
||||
return getAPI('bd')
|
||||
default:
|
||||
return getAPI('kw')
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { httpFatch } from '../../request'
|
||||
import { requestMsg } from '../../message'
|
||||
|
||||
const api_messoer = {
|
||||
getMusicUrl(songInfo, type) {
|
||||
const requestObj = httpFatch(`https://v1.itooi.cn/baidu/url?id=${songInfo.songmid}&quality=${type.replace(/k$/, '')}&isRedirect=0`, {
|
||||
method: 'get',
|
||||
timeout: 5000,
|
||||
})
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
return body.code === 200 ? Promise.resolve({ type, url: body.data }) : Promise.reject(new Error(requestMsg.fail))
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
getPic(songInfo, size = '500') {
|
||||
const requestObj = httpFatch(`https://v1.itooi.cn/baidu/pic?id=${songInfo.songmid}&imageSize=${size}&isRedirect=0`, {
|
||||
method: 'get',
|
||||
timeout: 5000,
|
||||
})
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
return body.code === 200 ? Promise.resolve(body.data) : Promise.reject(new Error(requestMsg.fail))
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
getLyric(songInfo) {
|
||||
const requestObj = httpFatch(`https://v1.itooi.cn/baidu/lrc?id=${songInfo.songmid}&isRedirect=0`, {
|
||||
method: 'get',
|
||||
timeout: 5000,
|
||||
})
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
return body ? Promise.resolve(body) : Promise.reject(new Error(requestMsg.fail))
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
}
|
||||
|
||||
export default api_messoer
|
||||
@@ -0,0 +1,21 @@
|
||||
import leaderboard from './leaderboard'
|
||||
import api_source from '../api-source'
|
||||
import musicInfo from './musicInfo'
|
||||
|
||||
const bd = {
|
||||
leaderboard,
|
||||
getMusicUrl(songInfo, type) {
|
||||
return api_source('bd').getMusicUrl(songInfo, type)
|
||||
},
|
||||
getLyric(songInfo) {
|
||||
return api_source('bd').getLyric(songInfo)
|
||||
},
|
||||
getPic(songInfo) {
|
||||
return api_source('bd').getPic(songInfo)
|
||||
},
|
||||
getMusicInfo(songInfo) {
|
||||
return musicInfo.getMusicInfo(songInfo.songmid)
|
||||
},
|
||||
}
|
||||
|
||||
export default bd
|
||||
@@ -0,0 +1,132 @@
|
||||
import { httpFatch } from '../../request'
|
||||
// import { formatPlayTime } from '../../index'
|
||||
// import jshtmlencode from 'js-htmlencode'
|
||||
|
||||
export default {
|
||||
limit: 20,
|
||||
list: [
|
||||
{
|
||||
id: 'bdrgb',
|
||||
name: '热歌榜',
|
||||
bangid: '2',
|
||||
},
|
||||
{
|
||||
id: 'bdxgb',
|
||||
name: '新歌榜',
|
||||
bangid: '1',
|
||||
},
|
||||
{
|
||||
id: 'bdycb',
|
||||
name: '原创榜',
|
||||
bangid: '200',
|
||||
},
|
||||
{
|
||||
id: 'bdhyjqb',
|
||||
name: '华语榜',
|
||||
bangid: '20',
|
||||
},
|
||||
{
|
||||
id: 'bdomjqb',
|
||||
name: '欧美榜',
|
||||
bangid: '21',
|
||||
},
|
||||
{
|
||||
id: 'bdwugqb',
|
||||
name: '网络榜',
|
||||
bangid: '25',
|
||||
},
|
||||
{
|
||||
id: 'bdjdlgb',
|
||||
name: '老歌榜',
|
||||
bangid: '22',
|
||||
},
|
||||
{
|
||||
id: 'bdysjqb',
|
||||
name: '影视金曲榜',
|
||||
bangid: '24',
|
||||
},
|
||||
{
|
||||
id: 'bdqgdcb',
|
||||
name: '情歌对唱榜',
|
||||
bangid: '23',
|
||||
},
|
||||
{
|
||||
id: 'bdygb',
|
||||
name: '摇滚榜',
|
||||
bangid: '11',
|
||||
},
|
||||
],
|
||||
getUrl(id, p) {
|
||||
return `http://musicmini.qianqian.com/2018/static/bangdan/bangdanList_${id}_${p}.html`
|
||||
},
|
||||
regExps: {
|
||||
item: /data-song="({.+?})"/g,
|
||||
info: /{total[\s:]+"(\d+)", size[\s:]+"(\d+)", page[\s:]+"(\d+)"}/,
|
||||
},
|
||||
requestObj: null,
|
||||
getData(url) {
|
||||
if (this.requestObj) this.requestObj.cancelHttp()
|
||||
this.requestObj = httpFatch(url)
|
||||
return this.requestObj.promise
|
||||
},
|
||||
filterData(rawList) {
|
||||
// console.log(rawList)
|
||||
return rawList.map(item => {
|
||||
const types = []
|
||||
const _types = {}
|
||||
let size = null
|
||||
types.push({ type: '128k', size })
|
||||
_types['128k'] = {
|
||||
size,
|
||||
}
|
||||
if (item.biaoshi) {
|
||||
types.push({ type: '320k', size })
|
||||
_types['320k'] = {
|
||||
size,
|
||||
}
|
||||
types.push({ type: 'flac', size })
|
||||
_types['flac'] = {
|
||||
size,
|
||||
}
|
||||
}
|
||||
// types.reverse()
|
||||
|
||||
return {
|
||||
singer: item.song_artist.replace(',', '、'),
|
||||
name: item.song_title,
|
||||
albumName: item.album_title,
|
||||
albumId: item.album_id,
|
||||
source: 'bd',
|
||||
interval: '',
|
||||
songmid: item.song_id,
|
||||
img: null,
|
||||
lrc: null,
|
||||
types,
|
||||
_types,
|
||||
typeUrl: {},
|
||||
}
|
||||
})
|
||||
},
|
||||
parseData(rawData) {
|
||||
// return rawData.map(item => JSON.parse(item.replace(this.regExps.item, '$1').replace(/"/g, '"').replace(/\\\//g, '/').replace(/(@s_1,w_)\d+(,h_)\d+/, '$1500$2500')))
|
||||
return rawData.map(item => JSON.parse(item.replace(this.regExps.item, '$1').replace(/"/g, '"').replace(/\\\//g, '/')))
|
||||
},
|
||||
getList(id, page) {
|
||||
let type = this.list.find(s => s.id === id)
|
||||
if (!type) return Promise.reject()
|
||||
return this.getData(this.getUrl(type.bangid, page)).then(({ body }) => {
|
||||
let result = body.match(this.regExps.item)
|
||||
if (!result) return Promise.reject(new Error('匹配list失败'))
|
||||
let info = body.match(this.regExps.info)
|
||||
if (!info) return Promise.reject(new Error('匹配info失败'))
|
||||
const list = this.filterData(this.parseData(result))
|
||||
this.limit = parseInt(info[2])
|
||||
return {
|
||||
total: parseInt(info[1]),
|
||||
list,
|
||||
limit: this.limit,
|
||||
page: parseInt(info[3]),
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { httpFatch } from '../../request'
|
||||
|
||||
export default {
|
||||
getMusicInfo(songmid) {
|
||||
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`)
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
return body.error_code == 22000 ? body.reqult.songinfo : Promise.reject(new Error('获取音乐信息失败'))
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import kw from './kw'
|
||||
import kg from './kg'
|
||||
import tx from './tx'
|
||||
import wy from './wy'
|
||||
import bd from './bd'
|
||||
export default {
|
||||
sources: [
|
||||
{
|
||||
@@ -20,9 +21,14 @@ export default {
|
||||
name: '网易音乐',
|
||||
id: 'wy',
|
||||
},
|
||||
{
|
||||
name: '百度音乐',
|
||||
id: 'bd',
|
||||
},
|
||||
],
|
||||
kw,
|
||||
kg,
|
||||
tx,
|
||||
wy,
|
||||
bd,
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ const wy = {
|
||||
return api_source('wy').getMusicUrl(songInfo, type)
|
||||
},
|
||||
getLyric(songInfo) {
|
||||
console.log(api_source('wy'))
|
||||
return api_source('wy').getLyric(songInfo)
|
||||
},
|
||||
getPic(songInfo) {
|
||||
|
||||
Reference in New Issue
Block a user