更新到0.1.4版本
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import kw_api_messoer from './kw/api-messoer'
|
||||
import kw_api_temp from './kw/api-temp'
|
||||
import tx_api_messoer from './tx/api-messoer'
|
||||
|
||||
const apis = {
|
||||
kw_api_messoer,
|
||||
tx_api_messoer,
|
||||
kw_api_temp,
|
||||
}
|
||||
|
||||
|
||||
const getAPI = source => {
|
||||
switch (window.globalObj.apiSource) {
|
||||
case 'messoer':
|
||||
return apis[`${source}_api_messoer`]
|
||||
case 'temp':
|
||||
return apis[`${source}_api_temp`]
|
||||
}
|
||||
}
|
||||
|
||||
export default source => {
|
||||
switch (source) {
|
||||
case 'tx':
|
||||
return getAPI('tx')
|
||||
default:
|
||||
return getAPI('kw')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { httpFatch } from '../../request'
|
||||
|
||||
const api_messoer = {
|
||||
getMusicUrl(songInfo, type) {
|
||||
const requestObj = httpFatch(`https://v1.itooi.cn/kuwo/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(body.msg))
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
getPic(songInfo) {
|
||||
const requestObj = httpFatch(`https://v1.itooi.cn/kuwo/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(body.msg))
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
}
|
||||
|
||||
export default api_messoer
|
||||
@@ -0,0 +1,33 @@
|
||||
import { httpFatch } from '../../request'
|
||||
|
||||
const api_temp = {
|
||||
getMusicUrl(songInfo, type) {
|
||||
const requestObj = httpFatch(`https://www.stsky.cn/api/temp/getMusicUrl.php?id=${songInfo.songmid}&type=${type}`, {
|
||||
method: 'get',
|
||||
})
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
return body.code === 0 ? Promise.resolve({ type, url: body.data }) : Promise.reject(new Error(body.msg))
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
if (err.message === 'socket hang up') return Promise.reject(new Error('接口挂了'))
|
||||
if (err.code === 'ENOTFOUND') return Promise.reject(new Error('无法连接网络'))
|
||||
return Promise.reject(err)
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
getPic(songInfo) {
|
||||
const requestObj = httpFatch(`https://www.stsky.cn/api/temp/getPic.php?size=320&songmid=${songInfo.songmid}`, {
|
||||
method: 'get',
|
||||
})
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
return body.code === 0 ? Promise.resolve(body.data) : Promise.reject(new Error(body.msg))
|
||||
}).catch(err => {
|
||||
if (err.message === 'socket hang up') return Promise.reject(new Error('接口挂了'))
|
||||
if (err.code === 'ENOTFOUND') return Promise.reject(new Error('无法连接网络'))
|
||||
return Promise.reject(err)
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
}
|
||||
|
||||
export default api_temp
|
||||
@@ -4,6 +4,7 @@ import musicSearch from './musicSearch'
|
||||
import { formatSinger } from './util'
|
||||
import leaderboard from './leaderboard'
|
||||
import lyric from './lyric'
|
||||
import api_source from '../api-source'
|
||||
|
||||
const kw = {
|
||||
_musicInfoRequestObj: null,
|
||||
@@ -52,36 +53,7 @@ const kw = {
|
||||
},
|
||||
|
||||
getMusicUrl(songInfo, type) {
|
||||
let requestObj
|
||||
let cancelFn
|
||||
const p = new Promise((resolve, reject) => {
|
||||
cancelFn = reject
|
||||
// requestObj = httpGet(`https://v1.itooi.cn/kuwo/url?id=${songInfo.songmid}&quality=${type.replace(/k$/, '')}&isRedirect=0`, (err, resp, body) => {
|
||||
requestObj = httpGet(`https://www.stsky.cn/api/temp/getMusicUrl.php?id=${songInfo.songmid}&type=${type}`, (err, resp, body) => {
|
||||
requestObj = null
|
||||
cancelFn = null
|
||||
if (err) {
|
||||
if (err.message === 'socket hang up') return reject(new Error('接口挂了'))
|
||||
const { promise, cancelHttp } = this.getMusicUrl(songInfo, type)
|
||||
obj.cancelHttp = cancelHttp
|
||||
return promise
|
||||
}
|
||||
// body.code === 200 ? resolve({ type, url: body.data }) : reject(new Error(body.msg))
|
||||
body.code === 0 ? resolve({ type, url: body.data }) : reject(new Error(body.msg))
|
||||
})
|
||||
})
|
||||
const obj = {
|
||||
promise: p,
|
||||
cancelHttp() {
|
||||
console.log('cancel')
|
||||
if (!requestObj) return
|
||||
cancelHttp(requestObj)
|
||||
cancelFn(new Error('取消http请求'))
|
||||
requestObj = null
|
||||
cancelFn = null
|
||||
},
|
||||
}
|
||||
return obj
|
||||
return api_source('kw').getMusicUrl(songInfo, type)
|
||||
},
|
||||
|
||||
getMusicInfo(songInfo) {
|
||||
@@ -119,24 +91,7 @@ const kw = {
|
||||
},
|
||||
|
||||
getPic(songInfo) {
|
||||
if (this._musicPicRequestObj != null) {
|
||||
cancelHttp(this._musicPicRequestObj)
|
||||
this._musicPicPromiseCancelFn(new Error('取消http请求'))
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this._musicPicPromiseCancelFn = reject
|
||||
// this._musicPicRequestObj = httpGet(`https://v1.itooi.cn/kuwo/pic?id=${songInfo.songmid}&isRedirect=0`, (err, resp, body) => {
|
||||
this._musicPicRequestObj = httpGet(`https://www.stsky.cn/api/temp/getPic.php?size=320&songmid=${songInfo.songmid}`, (err, resp, body) => {
|
||||
this._musicPicRequestObj = null
|
||||
this._musicPicPromiseCancelFn = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
reject(err)
|
||||
}
|
||||
// body.code === 200 ? resolve(body.data) : reject(new Error(body.msg))
|
||||
body.code === 0 ? resolve(body.data) : reject(new Error(body.msg))
|
||||
})
|
||||
})
|
||||
return api_source('kw').getPic(songInfo)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,7 @@ export default {
|
||||
})
|
||||
},
|
||||
filterData(rawList, rawList2) {
|
||||
// console.log(rawList.length, rawList2.length)
|
||||
return rawList.map((item, inedx) => {
|
||||
let formats = item.formats.split('|')
|
||||
let types = []
|
||||
@@ -148,7 +149,7 @@ export default {
|
||||
albumId: item.albumid,
|
||||
songmid: item.id,
|
||||
source: 'kw',
|
||||
interval: formatPlayTime(rawList2[inedx].duration),
|
||||
interval: rawList2[inedx] && formatPlayTime(rawList2[inedx].duration),
|
||||
img: item.pic,
|
||||
lrc: null,
|
||||
types,
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { httpGet, cancelHttp } from '../../request'
|
||||
import { httpFatch } from '../../request'
|
||||
|
||||
export default {
|
||||
_musicLrcRequestObj: null,
|
||||
_musicLrcPromiseCancelFn: null,
|
||||
formatTime(time) {
|
||||
let m = parseInt(time / 60)
|
||||
let s = (time % 60).toFixed(2)
|
||||
@@ -12,23 +10,10 @@ export default {
|
||||
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('') : '暂无歌词'}`
|
||||
},
|
||||
getLyric(songId) {
|
||||
if (this._musicLrcRequestObj != null) {
|
||||
cancelHttp(this._musicLrcRequestObj)
|
||||
this._musicLrcPromiseCancelFn(new Error('取消http请求'))
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this._musicLrcPromiseCancelFn = reject
|
||||
// this._musicLrcRequestObj = httpGet(`https://v1.itooi.cn/kuwo/lrc?id=${songId}`, (err, resp, body) => {
|
||||
this._musicLrcRequestObj = httpGet(`http://m.kuwo.cn/newh5/singles/songinfoandlrc?musicId=${songId}`, (err, resp, body) => {
|
||||
this._musicLrcRequestObj = null
|
||||
this._musicLrcPromiseCancelFn = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
reject(err)
|
||||
}
|
||||
// resolve(body)
|
||||
resolve(this.transformLrc(body.data))
|
||||
})
|
||||
const requestObj = httpFatch(`http://m.kuwo.cn/newh5/singles/songinfoandlrc?musicId=${songId}`)
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
return this.transformLrc(body.data)
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { httpFatch } from '../../request'
|
||||
|
||||
const api_messoer = {
|
||||
getMusicUrl(songInfo, type) {
|
||||
const requestObj = httpFatch(`https://v1.itooi.cn/tencent/url?id=${songInfo.strMediaMid}&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(body.msg))
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
getPic(songInfo) {
|
||||
return {
|
||||
promise: Promise.resolve(`https://y.gtimg.cn/music/photo_new/T002R500x500M000${songInfo.albumId}.jpg`),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default api_messoer
|
||||
@@ -1,46 +1,19 @@
|
||||
import { httpGet, cancelHttp } from '../../request'
|
||||
import leaderboard from './leaderboard'
|
||||
import lyric from './lyric'
|
||||
import api_source from '../api-source'
|
||||
|
||||
const tx = {
|
||||
leaderboard,
|
||||
|
||||
getMusicUrl(songInfo, type) {
|
||||
let requestObj
|
||||
let cancelFn
|
||||
const p = new Promise((resolve, reject) => {
|
||||
cancelFn = reject
|
||||
requestObj = httpGet(`https://v1.itooi.cn/tencent/url?id=${songInfo.strMediaMid}&quality=${type.replace(/k$/, '')}&isRedirect=0`, (err, resp, body) => {
|
||||
requestObj = null
|
||||
cancelFn = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
const { promise, cancelHttp } = this.getMusicUrl(songInfo, type)
|
||||
obj.cancelHttp = cancelHttp
|
||||
return promise
|
||||
}
|
||||
body.code === 200 ? resolve({ type, url: body.data }) : reject(new Error(body.msg))
|
||||
})
|
||||
})
|
||||
const obj = {
|
||||
promise: p,
|
||||
cancelHttp() {
|
||||
console.log('cancel')
|
||||
if (!requestObj) return
|
||||
cancelHttp(requestObj)
|
||||
cancelFn(new Error('取消http请求'))
|
||||
requestObj = null
|
||||
cancelFn = null
|
||||
},
|
||||
}
|
||||
return obj
|
||||
return api_source('tx').getMusicUrl(songInfo, type)
|
||||
},
|
||||
getLyric(songInfo) {
|
||||
// let singer = songInfo.singer.indexOf('、') > -1 ? songInfo.singer.split('、')[0] : songInfo.singer
|
||||
return lyric.getLyric(songInfo.songmid)
|
||||
},
|
||||
getPic(songInfo) {
|
||||
return Promise.resolve(`https://y.gtimg.cn/music/photo_new/T002R500x500M000${songInfo.albumId}.jpg`)
|
||||
return api_source('tx').getPic(songInfo)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,19 @@
|
||||
import { httpGet, cancelHttp } from '../../request'
|
||||
import { httpFatch } from '../../request'
|
||||
import { b64DecodeUnicode } from '../../index'
|
||||
|
||||
export default {
|
||||
_musicLrcRequestObj: null,
|
||||
_musicLrcPromiseCancelFn: null,
|
||||
regexps: {
|
||||
matchLrc: /.+"lyric":"([\w=+/]*)".+/,
|
||||
},
|
||||
getLyric(songmid) {
|
||||
if (this._musicLrcRequestObj != null) {
|
||||
cancelHttp(this._musicLrcRequestObj)
|
||||
this._musicLrcPromiseCancelFn(new Error('取消http请求'))
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this._musicLrcPromiseCancelFn = reject
|
||||
this._musicLrcRequestObj = httpGet(`https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?songmid=${songmid}&g_tk=2001461048&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&platform=yqq`, {
|
||||
headers: {
|
||||
Referer: 'https://y.qq.com/portal/player.html',
|
||||
},
|
||||
}, (err, resp, body) => {
|
||||
this._musicLrcRequestObj = null
|
||||
this._musicLrcPromiseCancelFn = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
reject(err)
|
||||
}
|
||||
resolve(b64DecodeUnicode(body.replace(this.regexps.matchLrc, '$1')))
|
||||
})
|
||||
const requestObj = httpFatch(`https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?songmid=${songmid}&g_tk=2001461048&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&platform=yqq`, {
|
||||
headers: {
|
||||
Referer: 'https://y.qq.com/portal/player.html',
|
||||
},
|
||||
})
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
return b64DecodeUnicode(body.replace(this.regexps.matchLrc, '$1'))
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user