新增网易云、酷狗排行榜音乐直接试听下载

This commit is contained in:
lyswhut
2019-08-20 01:19:01 +08:00
parent b8d07b365b
commit 78d2541c14
18 changed files with 266 additions and 43 deletions
+8
View File
@@ -1,10 +1,14 @@
import kw_api_messoer from './kw/api-messoer'
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'
const apis = {
kw_api_messoer,
tx_api_messoer,
kg_api_messoer,
wy_api_messoer,
kw_api_temp,
}
@@ -22,6 +26,10 @@ export default source => {
switch (source) {
case 'tx':
return getAPI('tx')
case 'kg':
return getAPI('kg')
case 'wy':
return getAPI('wy')
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/kugou/url?id=${songInfo._types[type].hash}&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) {
const requestObj = httpFatch(`https://v1.itooi.cn/kugou/pic?id=${songInfo.hash}&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/kugou/lrc?id=${songInfo.hash}&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
+11
View File
@@ -1,7 +1,18 @@
import leaderboard from './leaderboard'
import api_source from '../api-source'
const kg = {
leaderboard,
getMusicUrl(songInfo, type) {
return api_source('kg').getMusicUrl(songInfo, type)
},
getLyric(songInfo) {
return api_source('kg').getLyric(songInfo)
},
getPic(songInfo) {
return api_source('kg').getPic(songInfo)
},
}
export default kg
+53 -13
View File
@@ -1,5 +1,5 @@
import { httpGet, cancelHttp } from '../../request'
import { formatPlayTime } from '../../index'
import { formatPlayTime, sizeFormate } from '../../index'
export default {
list: [
@@ -89,18 +89,58 @@ export default {
})
},
filterData(rawList) {
return rawList.map(item => ({
singer: item.singername,
name: item.songname,
albumName: item.album_name,
albumId: item.album_id,
songmid: item.audio_id,
source: 'kg',
interval: formatPlayTime(item.duration / 1000),
img: null,
lrc: null,
typeUrl: {},
}))
// console.log(rawList)
return rawList.map(item => {
const types = []
const _types = {}
if (item.filesize !== 0) {
let size = sizeFormate(item.filesize)
types.push({ type: '128k', size, hash: item.hash })
_types['128k'] = {
size,
hash: item.hash,
}
}
if (item.filesize_320 !== 0) {
let size = sizeFormate(item.filesize_320)
types.push({ type: '320k', size, hash: item.hash_320 })
_types['320k'] = {
size,
hash: item.hash_320,
}
}
if (item.filesize_ape !== 0) {
let size = sizeFormate(item.filesize_ape)
types.push({ type: 'ape', size, hash: item.hash_ape })
_types.ape = {
size,
hash: item.hash_ape,
}
}
if (item.filesize_flac !== 0) {
let size = sizeFormate(item.filesize_flac)
types.push({ type: 'flac', size, hash: item.hash_flac })
_types.flac = {
size,
hash: item.hash_flac,
}
}
return {
singer: item.singername,
name: item.songname,
albumName: item.album_name,
albumId: item.album_id,
songmid: item.audio_id,
source: 'kg',
interval: formatPlayTime(item.duration / 1000),
img: null,
lrc: null,
hash: item.HASH,
types,
_types,
typeUrl: {},
}
})
},
getList(id, page) {
let type = this.list.find(s => s.id === id)
+6
View File
@@ -3,8 +3,14 @@
* @param {*} info
* @param {*} type
*/
const types = ['flac', 'ape', '320k', '192k', '128k']
export const getMusicType = (info, type) => {
switch (window.globalObj.apiSource) {
case 'kg':
case 'wy':
return '128k'
}
const rangeType = types.slice(types.indexOf(type))
for (const type of rangeType) {
if (info._types[type]) return type
@@ -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/netease/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) {
const requestObj = httpFatch(`https://v1.itooi.cn/netease/pic?id=${songInfo.songmid}&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/netease/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
+11
View File
@@ -1,7 +1,18 @@
import leaderboard from './leaderboard'
import api_source from '../api-source'
const wy = {
leaderboard,
getMusicUrl(songInfo, type) {
return api_source('wy').getMusicUrl(songInfo, type)
},
getLyric(songInfo) {
console.log(api_source('wy'))
return api_source('wy').getLyric(songInfo)
},
getPic(songInfo) {
return api_source('wy').getPic(songInfo)
},
}
export default wy
@@ -91,6 +91,42 @@ export default {
filterData(rawList) {
// console.log(rawList)
return rawList.map(item => {
const types = []
const _types = {}
let size
switch (item.privilege.maxbr) {
case 999000:
size = null
types.push({ type: 'flac', size })
_types['flac'] = {
size,
}
case 320000:
size = null
types.push({ type: '320k', size })
_types['320k'] = {
size,
}
case 192000:
case 190000:
size = null
types.push({ type: '192k', size })
_types['192k'] = {
size,
}
// case '160000':
default:
size = null
types.push({ type: '128k', size })
_types['128k'] = {
size,
}
break
}
types.reverse()
return {
singer: this.getSinger(item.artists),
name: item.name,
@@ -101,6 +137,8 @@ export default {
songmid: item.id,
img: item.album.picUrl,
lrc: null,
types,
_types,
typeUrl: {},
}
})