原接口已挂,暂时切换到临时接口
This commit is contained in:
@@ -8,6 +8,8 @@ const state = {
|
||||
changePlay: false,
|
||||
}
|
||||
|
||||
let request
|
||||
|
||||
// getters
|
||||
const getters = {
|
||||
list: state => state.list || [],
|
||||
@@ -19,13 +21,12 @@ const getters = {
|
||||
// actions
|
||||
const actions = {
|
||||
getUrl({ commit, state }, { musicInfo, type }) {
|
||||
if (state.cancelFn) state.cancelFn()
|
||||
const { promise, cancelHttp } = music[musicInfo.source].getMusicUrl(musicInfo, type)
|
||||
state.cancelFn = cancelHttp
|
||||
return promise.then(result => {
|
||||
return commit('setUrl', { musicInfo, url: result.url, type })
|
||||
if (request && request.cancelHttp) request.cancelHttp()
|
||||
request = music[musicInfo.source].getMusicUrl(musicInfo, type)
|
||||
return request.promise.then(result => {
|
||||
commit('setUrl', { musicInfo, url: result.url, type })
|
||||
}).finally(() => {
|
||||
state.cancelFn = null
|
||||
request = null
|
||||
})
|
||||
},
|
||||
getPic({ commit, state }, musicInfo) {
|
||||
|
||||
@@ -56,16 +56,18 @@ const kw = {
|
||||
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://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) {
|
||||
console.log(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 === 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 = {
|
||||
@@ -123,14 +125,16 @@ const kw = {
|
||||
}
|
||||
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://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 === 200 ? resolve(body.data) : reject(new Error(body.msg))
|
||||
body.code === 0 ? resolve(body.data) : reject(new Error(body.msg))
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
@@ -8,6 +8,9 @@ export default {
|
||||
let s = (time % 60).toFixed(2)
|
||||
return (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s)
|
||||
},
|
||||
transformLrc({ songinfo, lrclist }) {
|
||||
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)
|
||||
@@ -15,16 +18,16 @@ export default {
|
||||
}
|
||||
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(`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)
|
||||
}
|
||||
// console.log(body.data)
|
||||
// console.log(this.transformLrc(body.data))
|
||||
resolve(body)
|
||||
// resolve(body)
|
||||
resolve(this.transformLrc(body.data))
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
@@ -3,16 +3,58 @@ import request from 'request'
|
||||
import { debugRequest } from './env'
|
||||
// import fs from 'fs'
|
||||
|
||||
const fatchData = (url, method, options, callback) => request(url, {
|
||||
method,
|
||||
headers: options.headers,
|
||||
Origin: options.origin,
|
||||
data: options.data,
|
||||
json: options.format === undefined || options.format === 'json',
|
||||
}, (err, resp, body) => {
|
||||
if (err) return callback(err, null)
|
||||
callback(null, resp, body)
|
||||
})
|
||||
const fatchData = (url, method, options, callback) => {
|
||||
console.log('---start---', url)
|
||||
return request(url, {
|
||||
method,
|
||||
headers: options.headers,
|
||||
Origin: options.origin,
|
||||
data: options.data,
|
||||
// timeout: 5000,
|
||||
json: options.format === undefined || options.format === 'json',
|
||||
}, (err, resp, body) => {
|
||||
if (err) return callback(err, null)
|
||||
console.log('---end---', url)
|
||||
callback(null, resp, body)
|
||||
})
|
||||
}
|
||||
|
||||
export const httpFatch = (url, options = { method: 'get' }) => {
|
||||
let requestObj
|
||||
let cancelFn
|
||||
const p = new Promise((resolve, reject) => {
|
||||
cancelFn = reject
|
||||
debugRequest && console.log(`\n---send request------${url}------------`)
|
||||
requestObj = fatchData(url, options.method, options, (err, resp, body) => {
|
||||
// options.isShowProgress && window.api.hideProgress()
|
||||
debugRequest && console.log(`\n---response------${url}------------`)
|
||||
debugRequest && console.log(JSON.stringify(body))
|
||||
requestObj = null
|
||||
cancelFn = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
if (err.code === 'ETIMEDOUT') {
|
||||
const { promise, cancelHttp } = httpFatch(url, options)
|
||||
obj.cancelHttp = cancelHttp
|
||||
return promise
|
||||
}
|
||||
}
|
||||
resolve(resp)
|
||||
})
|
||||
})
|
||||
const obj = {
|
||||
promise: p,
|
||||
cancelHttp() {
|
||||
console.log('cancel')
|
||||
if (!requestObj) return
|
||||
cancelHttp(requestObj)
|
||||
cancelFn(new Error('取消http请求'))
|
||||
requestObj = null
|
||||
cancelFn = null
|
||||
},
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消请求
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
td.break(style="width: 20%;") {{item.singer}}
|
||||
td.break(style="width: 25%;") {{item.albumName}}
|
||||
td(style="width: 18%;")
|
||||
material-list-buttons(:index="index" :search-btn="true" :play-btn="item.source == 'kw' || item.source == 'tx'" :download-btn="item.source == 'kw' || item.source == 'tx'" :remove-btn="false" @btn-click="handleBtnClick")
|
||||
material-list-buttons(:index="index" :search-btn="true" :play-btn="item.source == 'kw'" :download-btn="item.source == 'kw'" :remove-btn="false" @btn-click="handleBtnClick")
|
||||
//- button.btn-info(type='button' v-if="item._types['128k'] || item._types['192k'] || item._types['320k'] || item._types.flac" @click.stop='openDownloadModal(index)') 下载
|
||||
//- button.btn-secondary(type='button' v-if="item._types['128k'] || item._types['192k'] || item._types['320k']" @click.stop='testPlay(index)') 试听
|
||||
//- button.btn-success(type='button' v-if="(item._types['128k'] || item._types['192k'] || item._types['320k']) && userInfo" @click.stop='showListModal(index)') +
|
||||
@@ -94,7 +94,7 @@ export default {
|
||||
this.clickIndex = index
|
||||
return
|
||||
}
|
||||
(this.source == 'kw' || this.source == 'tx') ? this.testPlay(index) : this.handleSearch(index)
|
||||
(this.source == 'kw') ? this.testPlay(index) : this.handleSearch(index)
|
||||
this.clickTime = 0
|
||||
this.clickIndex = -1
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user