From bccadcf13d3a2fa48cb4983f9e0fe0e22fad6748 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sat, 17 Aug 2019 02:22:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E6=92=AD=E6=94=BEQQ=E9=9F=B3=E4=B9=90=E6=8E=92=E8=A1=8C?= =?UTF-8?q?=E6=A6=9C=E9=9F=B3=E4=B9=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 16 +++++++ package-lock.json | 22 ++++++++++ package.json | 3 +- publish/changeLog.md | 14 ++++++- publish/index.js | 8 ++-- publish/version.json | 11 +++-- src/renderer/components/core/Player.vue | 5 ++- src/renderer/store/modules/download.js | 2 +- src/renderer/store/modules/player.js | 9 +++- src/renderer/utils/music/kg/leaderboard.js | 10 ++--- src/renderer/utils/music/kw/index.js | 48 ++++++++++++++------- src/renderer/utils/music/kw/leaderboard.js | 20 ++++----- src/renderer/utils/music/kw/lyric.js | 10 ++--- src/renderer/utils/music/kw/musicSearch.js | 10 ++--- src/renderer/utils/music/kw/tempSearch.js | 14 +++---- src/renderer/utils/music/tx/index.js | 40 ++++++++++++++++++ src/renderer/utils/music/tx/leaderboard.js | 12 +++--- src/renderer/utils/music/tx/lyric.js | 32 ++++++++++++++ src/renderer/utils/music/wy/leaderboard.js | 10 ++--- src/renderer/utils/request.js | 49 +++++++--------------- src/renderer/views/Leaderboard.vue | 4 +- 21 files changed, 241 insertions(+), 108 deletions(-) create mode 100644 src/renderer/utils/music/tx/lyric.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 2777672d..1afe9752 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,22 @@ Project versioning adheres to [Semantic Versioning](http://semver.org/). Commit convention is based on [Conventional Commits](http://conventionalcommits.org). Change log format is based on [Keep a Changelog](http://keepachangelog.com/). +## [0.1.1](https://github.com/lyswhut/lx-music-desktop/compare/v0.1.0...v0.1.1) - 2019-08-17 + +### 新增 + +- QQ音乐排行榜直接试听与下载(该接口貌似不太稳定,且用且珍惜!) + +### 优化 + +- 优化http请求机制 +- 更新关于本软件说明 + +### 修复 + +- 修复当上一个歌曲链接正在获取时切换歌曲请求不会取消的问题 +- 修复切换歌曲时仍然播放上一首歌曲的问题 + ## [0.1.0] - 2019-8-16 * 0.1.0版本发布 diff --git a/package-lock.json b/package-lock.json index fdb079f7..189b0d23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3404,6 +3404,16 @@ "upper-case-first": "^1.1.0" } }, + "changelog-parser": { + "version": "2.8.0", + "resolved": "https://registry.npm.taobao.org/changelog-parser/download/changelog-parser-2.8.0.tgz", + "integrity": "sha1-wUKT4+j6t5eRPHIt6WVIAZhlAQg=", + "dev": true, + "requires": { + "line-reader": "^0.2.4", + "remove-markdown": "^0.2.2" + } + }, "character-parser": { "version": "2.2.0", "resolved": "https://registry.npm.taobao.org/character-parser/download/character-parser-2.2.0.tgz", @@ -8487,6 +8497,12 @@ "type-check": "~0.3.2" } }, + "line-reader": { + "version": "0.2.4", + "resolved": "https://registry.npm.taobao.org/line-reader/download/line-reader-0.2.4.tgz", + "integrity": "sha1-xDkrWH3qOFgMlnhXDm6OSfzlJiI=", + "dev": true + }, "linkify-it": { "version": "2.2.0", "resolved": "https://registry.npm.taobao.org/linkify-it/download/linkify-it-2.2.0.tgz", @@ -11288,6 +11304,12 @@ "integrity": "sha1-VNvzd+UUQKypCkzSdGANP/LYiKk=", "dev": true }, + "remove-markdown": { + "version": "0.2.2", + "resolved": "https://registry.npm.taobao.org/remove-markdown/download/remove-markdown-0.2.2.tgz", + "integrity": "sha1-ZrDO66n7d8qWNrsbAwfOIaMqEqY=", + "dev": true + }, "remove-trailing-separator": { "version": "1.1.0", "resolved": "https://registry.npm.taobao.org/remove-trailing-separator/download/remove-trailing-separator-1.1.0.tgz", diff --git a/package.json b/package.json index bf0602dd..64ffdfed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lx-music-desktop", - "version": "0.1.0", + "version": "0.1.1", "description": "一个免费的音乐下载助手", "main": "./dist/electron/main.js", "scripts": { @@ -75,6 +75,7 @@ "babel-preset-minify": "^0.5.0", "cfonts": "^2.4.4", "chalk": "^2.4.2", + "changelog-parser": "^2.8.0", "copy-webpack-plugin": "^5.0.4", "core-js": "^3.2.1", "cos-nodejs-sdk-v5": "^2.5.11", diff --git a/publish/changeLog.md b/publish/changeLog.md index 12eb4d3b..1bfc1850 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1 +1,13 @@ -* 0.1.0版本发布 +### 新增 + +- QQ音乐排行榜直接试听与下载(该接口貌似不太稳定,且用且珍惜!) + +### 优化 + +- 优化http请求机制 +- 更新关于本软件说明 + +### 修复 + +- 修复当上一个歌曲链接正在获取时切换歌曲请求不会取消的问题 +- 修复切换歌曲时仍然播放上一首歌曲的问题 diff --git a/publish/index.js b/publish/index.js index 0a88c266..aa2e9e65 100644 --- a/publish/index.js +++ b/publish/index.js @@ -2,11 +2,11 @@ const fs = require('fs') const path = require('path') const chalk = require('chalk') const clearAssets = require('./utils/clearAssets') -const packAssets = require('./utils/packAssets') -const compileAssets = require('./utils/compileAssets') +// const packAssets = require('./utils/packAssets') +// const compileAssets = require('./utils/compileAssets') const updateVersionFile = require('./utils/updateChangeLog') -const copyFile = require('./utils/copyFile') -const githubRelease = require('./utils/githubRelease') +// const copyFile = require('./utils/copyFile') +// const githubRelease = require('./utils/githubRelease') const { parseArgv } = require('./utils') const run = async() => { diff --git a/publish/version.json b/publish/version.json index 14b92d11..16921aee 100644 --- a/publish/version.json +++ b/publish/version.json @@ -1,5 +1,10 @@ { - "version": "0.1.0", - "desc": "0.1.0版本发布", - "history": [] + "version": "0.1.1", + "desc": "

新增

\n\n

优化

\n\n

修复

\n\n", + "history": [ + { + "version": "0.1.0", + "desc": "0.1.0版本发布" + } + ] } diff --git a/src/renderer/components/core/Player.vue b/src/renderer/components/core/Player.vue index 8be2f536..50d4c037 100644 --- a/src/renderer/components/core/Player.vue +++ b/src/renderer/components/core/Player.vue @@ -98,6 +98,8 @@ export default { watch: { changePlay(n) { if (!n) return + // console.log('changePlay') + this.handleRemoveMusic() this.resetChangePlay() if (this.playIndex < 0) return this.stopPlay() @@ -112,7 +114,7 @@ export default { ? n.findIndex(s => s.musicInfo.songmid === this.musicInfo.songmid) : n.findIndex(s => s.songmid === this.musicInfo.songmid) if (index < 0) { - this.handleRemoveMusic() + this.fixPlayIndex(this.playIndex - 1) if (n.length) this.handleNext() } else { this.fixPlayIndex(index) @@ -362,7 +364,6 @@ export default { this.musicInfo.url = null this.nowPlayTime = 0 this.maxPlayTime = 0 - this.fixPlayIndex(this.playIndex - 1) }, sendProgressEvent(status, mode) { // console.log(status) diff --git a/src/renderer/store/modules/download.js b/src/renderer/store/modules/download.js index f441f65e..c1b45efa 100644 --- a/src/renderer/store/modules/download.js +++ b/src/renderer/store/modules/download.js @@ -41,7 +41,7 @@ const getExt = type => { const checkList = (list, musicInfo, type) => list.some(s => s.musicInfo.songmid === musicInfo.songmid && s.type === type) const refreshUrl = downloadInfo => { - return music[downloadInfo.musicInfo.source].getMusicUrl(downloadInfo.musicInfo, downloadInfo.type) + return music[downloadInfo.musicInfo.source].getMusicUrl(downloadInfo.musicInfo, downloadInfo.type).promise } // actions diff --git a/src/renderer/store/modules/player.js b/src/renderer/store/modules/player.js index c1a51a92..bf1dcac5 100644 --- a/src/renderer/store/modules/player.js +++ b/src/renderer/store/modules/player.js @@ -19,7 +19,14 @@ const getters = { // actions const actions = { getUrl({ commit, state }, { musicInfo, type }) { - return music[musicInfo.source].getMusicUrl(musicInfo, type).then(result => commit('setUrl', { musicInfo, url: result.url, 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 }) + }).finally(() => { + state.cancelFn = null + }) }, getPic({ commit, state }, musicInfo) { return music[musicInfo.source].getPic(musicInfo).then(url => commit('getPic', { musicInfo, url })) diff --git a/src/renderer/utils/music/kg/leaderboard.js b/src/renderer/utils/music/kg/leaderboard.js index 748967d7..2913b5d4 100644 --- a/src/renderer/utils/music/kg/leaderboard.js +++ b/src/renderer/utils/music/kg/leaderboard.js @@ -68,17 +68,17 @@ export default { limit: /pagesize: '(\d+)',/, listData: /global\.features = (\[.+\]);/, }, - _cancelIndex: null, + _requestObj: null, _cancelPromiseCancelFn: null, getData(url) { - if (this._cancelIndex != null) { - cancelHttp(this._cancelIndex) + if (this._requestObj != null) { + cancelHttp(this._requestObj) this._cancelPromiseCancelFn(new Error('取消http请求')) } return new Promise((resolve, reject) => { this._cancelPromiseCancelFn = reject - this._cancelIndex = httpGet(url, (err, resp, body) => { - this._cancelIndex = null + this._requestObj = httpGet(url, (err, resp, body) => { + this._requestObj = null this._cancelPromiseCancelFn = null if (err) { console.log(err) diff --git a/src/renderer/utils/music/kw/index.js b/src/renderer/utils/music/kw/index.js index c46b2e50..a58e51ee 100644 --- a/src/renderer/utils/music/kw/index.js +++ b/src/renderer/utils/music/kw/index.js @@ -6,9 +6,9 @@ import leaderboard from './leaderboard' import lyric from './lyric' const kw = { - _musicInfoIndex: null, + _musicInfoRequestObj: null, _musicInfoPromiseCancelFn: null, - _musicPicIndex: null, + _musicPicRequestObj: null, _musicPicPromiseCancelFn: null, // context: null, @@ -52,26 +52,45 @@ const kw = { }, getMusicUrl(songInfo, type) { - return new Promise((resolve, reject) => { - httpGet(`https://v1.itooi.cn/kuwo/url?id=${songInfo.songmid}&quality=${type.replace(/k$/, '')}&isRedirect=0`, (err, resp, body) => { + 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 = null + cancelFn = null if (err) { console.log(err) - return this.getMusicUrl(songInfo, type) + 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 }, getMusicInfo(songInfo) { - if (this._musicInfoIndex != null) { - cancelHttp(this._musicInfoIndex) + if (this._musicInfoRequestObj != null) { + cancelHttp(this._musicInfoRequestObj) this._musicInfoPromiseCancelFn(new Error('取消http请求')) } return new Promise((resolve, reject) => { this._musicInfoPromiseCancelFn = reject - this._musicInfoIndex = httpGet(`http://www.kuwo.cn/api/www/music/musicInfo?mid=${songInfo.songmid}`, (err, resp, body) => { - this._musicInfoIndex = null + this._musicInfoRequestObj = httpGet(`http://www.kuwo.cn/api/www/music/musicInfo?mid=${songInfo.songmid}`, (err, resp, body) => { + this._musicInfoRequestObj = null this._musicInfoPromiseCancelFn = null if (err) { console.log(err) @@ -86,7 +105,7 @@ const kw = { let tasks = [] let songId = musicInfo.songmid musicInfo.types.forEach(type => { - tasks.push(kw.getMusicUrl(songId, type.type)) + tasks.push(kw.getMusicUrl(songId, type.type).promise) }) Promise.all(tasks).then(urlInfo => { let typeUrl = {} @@ -98,20 +117,19 @@ const kw = { }, getPic(songInfo) { - if (this._musicPicIndex != null) { - cancelHttp(this._musicPicIndex) + if (this._musicPicRequestObj != null) { + cancelHttp(this._musicPicRequestObj) this._musicPicPromiseCancelFn(new Error('取消http请求')) } return new Promise((resolve, reject) => { this._musicPicPromiseCancelFn = reject - this._musicPicIndex = httpGet(`https://v1.itooi.cn/kuwo/pic?id=${songInfo.songmid}&isRedirect=0`, (err, resp, body) => { - this._musicPicIndex = null + this._musicPicRequestObj = httpGet(`https://v1.itooi.cn/kuwo/pic?id=${songInfo.songmid}&isRedirect=0`, (err, resp, body) => { + this._musicPicRequestObj = null this._musicPicPromiseCancelFn = null if (err) { console.log(err) reject(err) } - console.log(body) body.code === 200 ? resolve(body.data) : reject(new Error(body.msg)) }) }) diff --git a/src/renderer/utils/music/kw/leaderboard.js b/src/renderer/utils/music/kw/leaderboard.js index ec376a07..ba4c2792 100644 --- a/src/renderer/utils/music/kw/leaderboard.js +++ b/src/renderer/utils/music/kw/leaderboard.js @@ -65,19 +65,19 @@ export default { }, limit: 30, - _cancelIndex: null, + _cancelRequestObj: null, _cancelPromiseCancelFn: null, - _cancelIndex2: null, + _cancelRequestObj2: null, _cancelPromiseCancelFn2: null, getData(url) { - if (this._cancelIndex != null) { - cancelHttp(this._cancelIndex) + if (this._cancelRequestObj != null) { + cancelHttp(this._cancelRequestObj) this._cancelPromiseCancelFn(new Error('取消http请求')) } return new Promise((resolve, reject) => { this._cancelPromiseCancelFn = reject - this._cancelIndex = httpGet(url, (err, resp, body) => { - this._cancelIndex = null + this._cancelRequestObj = httpGet(url, (err, resp, body) => { + this._cancelRequestObj = null this._cancelPromiseCancelFn = null if (err) { console.log(err) @@ -88,14 +88,14 @@ export default { }) }, getData2(url) { - if (this._cancelIndex2 != null) { - cancelHttp(this._cancelIndex2) + if (this._cancelRequestObj2 != null) { + cancelHttp(this._cancelRequestObj2) this._cancelPromiseCancelFn2(new Error('取消http请求')) } return new Promise((resolve, reject) => { this._cancelPromiseCancelFn2 = reject - this._cancelIndex2 = httpGet(url, (err, resp, body) => { - this._cancelIndex2 = null + this._cancelRequestObj2 = httpGet(url, (err, resp, body) => { + this._cancelRequestObj2 = null this._cancelPromiseCancelFn2 = null if (err) { console.log(err) diff --git a/src/renderer/utils/music/kw/lyric.js b/src/renderer/utils/music/kw/lyric.js index 63ccfa07..e806238d 100644 --- a/src/renderer/utils/music/kw/lyric.js +++ b/src/renderer/utils/music/kw/lyric.js @@ -1,7 +1,7 @@ import { httpGet, cancelHttp } from '../../request' export default { - _musicLrcIndex: null, + _musicLrcRequestObj: null, _musicLrcPromiseCancelFn: null, formatTime(time) { let m = parseInt(time / 60) @@ -9,14 +9,14 @@ export default { return (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s) }, getLyric(songId) { - if (this._musicLrcIndex != null) { - cancelHttp(this._musicLrcIndex) + if (this._musicLrcRequestObj != null) { + cancelHttp(this._musicLrcRequestObj) this._musicLrcPromiseCancelFn(new Error('取消http请求')) } return new Promise((resolve, reject) => { this._musicLrcPromiseCancelFn = reject - this._musicLrcIndex = httpGet(`https://v1.itooi.cn/kuwo/lrc?id=${songId}`, (err, resp, body) => { - this._musicLrcIndex = null + this._musicLrcRequestObj = httpGet(`https://v1.itooi.cn/kuwo/lrc?id=${songId}`, (err, resp, body) => { + this._musicLrcRequestObj = null this._musicLrcPromiseCancelFn = null if (err) { console.log(err) diff --git a/src/renderer/utils/music/kw/musicSearch.js b/src/renderer/utils/music/kw/musicSearch.js index 81e72919..39fae3ff 100644 --- a/src/renderer/utils/music/kw/musicSearch.js +++ b/src/renderer/utils/music/kw/musicSearch.js @@ -9,7 +9,7 @@ export default { regExps: { mInfo: /bitrate:(\d+),format:(\w+),size:([\w.]+)/, }, - _musicSearchIndex: null, + _musicSearchRequestObj: null, _musicSearchPromiseCancelFn: null, limit: 30, total: 0, @@ -17,14 +17,14 @@ export default { allPage: 1, // cancelFn: null, musicSearch(str, page) { - if (this._musicSearchIndex != null) { - cancelHttp(this._musicSearchIndex) + if (this._musicSearchRequestObj != null) { + cancelHttp(this._musicSearchRequestObj) this._musicSearchPromiseCancelFn(new Error('取消http请求')) } return new Promise((resolve, reject) => { this._musicSearchPromiseCancelFn = reject - this._musicSearchIndex = httpGet(`http://search.kuwo.cn/r.s?client=kt&all=${encodeURIComponent(str)}&pn=${page - 1}&rn=${this.limit}&uid=794762570&ver=kwplayer_ar_9.2.2.1&vipver=1&show_copyright_off=1&newver=1&ft=music&cluster=0&strategy=2012&encoding=utf8&rformat=json&vermerge=1&mobi=1&issubtitle=1`, (err, resp, body) => { - this._musicSearchIndex = null + this._musicSearchRequestObj = httpGet(`http://search.kuwo.cn/r.s?client=kt&all=${encodeURIComponent(str)}&pn=${page - 1}&rn=${this.limit}&uid=794762570&ver=kwplayer_ar_9.2.2.1&vipver=1&show_copyright_off=1&newver=1&ft=music&cluster=0&strategy=2012&encoding=utf8&rformat=json&vermerge=1&mobi=1&issubtitle=1`, (err, resp, body) => { + this._musicSearchRequestObj = null this._musicSearchPromiseCancelFn = null if (err) { console.log(err) diff --git a/src/renderer/utils/music/kw/tempSearch.js b/src/renderer/utils/music/kw/tempSearch.js index 1402dc36..1d82e0ae 100644 --- a/src/renderer/utils/music/kw/tempSearch.js +++ b/src/renderer/utils/music/kw/tempSearch.js @@ -5,17 +5,17 @@ export default { regExps: { relWord: /RELWORD=(.+)/, }, - _musicTempSearchIndex: null, + _musicTempSearchRequestObj: null, _musicTempSearchPromiseCancelFn: null, tempSearch(str) { - if (this._musicTempSearchIndex != null) { - cancelHttp(this._musicTempSearchIndex) + if (this._musicTempSearchRequestObj != null) { + cancelHttp(this._musicTempSearchRequestObj) this._musicTempSearchPromiseCancelFn(new Error('取消http请求')) } return new Promise((resolve, reject) => { this._musicTempSearchPromiseCancelFn = reject - this._musicTempSearchIndex = httpGet(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`, (err, resp, body) => { - this._musicTempSearchIndex = null + this._musicTempSearchRequestObj = httpGet(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`, (err, resp, body) => { + this._musicTempSearchRequestObj = null this._musicTempSearchPromiseCancelFn = null if (err) { console.log(err) @@ -32,8 +32,8 @@ export default { }) }, cancelTempSearch() { - if (this._musicTempSearchIndex != null) { - cancelHttp(this._musicTempSearchIndex) + if (this._musicTempSearchRequestObj != null) { + cancelHttp(this._musicTempSearchRequestObj) this._musicTempSearchPromiseCancelFn(new Error('取消http请求')) } }, diff --git a/src/renderer/utils/music/tx/index.js b/src/renderer/utils/music/tx/index.js index fa5e44b0..62667f9e 100644 --- a/src/renderer/utils/music/tx/index.js +++ b/src/renderer/utils/music/tx/index.js @@ -1,7 +1,47 @@ +import { httpGet, cancelHttp } from '../../request' import leaderboard from './leaderboard' +import lyric from './lyric' 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 + }, + 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`) + }, } export default tx diff --git a/src/renderer/utils/music/tx/leaderboard.js b/src/renderer/utils/music/tx/leaderboard.js index 11865b8f..4e2961c9 100644 --- a/src/renderer/utils/music/tx/leaderboard.js +++ b/src/renderer/utils/music/tx/leaderboard.js @@ -83,17 +83,17 @@ export default { }, periods: {}, periodUrl: 'https://c.y.qq.com/node/pc/wk_v15/top.html', - _cancelIndex: null, + _cancelRequestObj: null, _cancelPromiseCancelFn: null, getData(url) { - if (this._cancelIndex != null) { - cancelHttp(this._cancelIndex) + if (this._cancelRequestObj != null) { + cancelHttp(this._cancelRequestObj) this._cancelPromiseCancelFn(new Error('取消http请求')) } return new Promise((resolve, reject) => { this._cancelPromiseCancelFn = reject - this._cancelIndex = httpGet(url, (err, resp, body) => { - this._cancelIndex = null + this._cancelRequestObj = httpGet(url, (err, resp, body) => { + this._cancelRequestObj = null this._cancelPromiseCancelFn = null if (err) { console.log(err) @@ -143,7 +143,7 @@ export default { size, } } - types.reverse() + // types.reverse() return { singer: this.getSinger(item.singer), name: item.title, diff --git a/src/renderer/utils/music/tx/lyric.js b/src/renderer/utils/music/tx/lyric.js new file mode 100644 index 00000000..9af8ba4b --- /dev/null +++ b/src/renderer/utils/music/tx/lyric.js @@ -0,0 +1,32 @@ +import { httpGet, cancelHttp } 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'))) + }) + }) + }, +} diff --git a/src/renderer/utils/music/wy/leaderboard.js b/src/renderer/utils/music/wy/leaderboard.js index fd79e71a..1f005b8f 100644 --- a/src/renderer/utils/music/wy/leaderboard.js +++ b/src/renderer/utils/music/wy/leaderboard.js @@ -61,17 +61,17 @@ export default { regExps: { list: /