diff --git a/.history/src/renderer/utils/musicSdk/kg/leaderboard_20230610002212.js b/.history/src/renderer/utils/musicSdk/kg/leaderboard_20230610002212.js deleted file mode 100644 index 3bbbf66f..00000000 --- a/.history/src/renderer/utils/musicSdk/kg/leaderboard_20230610002212.js +++ /dev/null @@ -1,210 +0,0 @@ -import { httpFetch } from '../../request' -import { decodeName, formatPlayTime, sizeFormate } from '../../index' -import { formatSingerName } from '../utils' -import { formatSingerList } from './util' - -let boardList = [{ id: 'kg__8888', name: 'TOP500', bangid: '8888' }, { id: 'kg__6666', name: '飙升榜', bangid: '6666' }, { id: 'kg__59703', name: '蜂鸟流行音乐榜', bangid: '59703' }, { id: 'kg__52144', name: '抖音热歌榜', bangid: '52144' }, { id: 'kg__52767', name: '快手热歌榜', bangid: '52767' }, { id: 'kg__24971', name: 'DJ热歌榜', bangid: '24971' }, { id: 'kg__23784', name: '网络红歌榜', bangid: '23784' }, { id: 'kg__44412', name: '说唱先锋榜', bangid: '44412' }, { id: 'kg__31308', name: '内地榜', bangid: '31308' }, { id: 'kg__33160', name: '电音榜', bangid: '33160' }, { id: 'kg__31313', name: '香港地区榜', bangid: '31313' }, { id: 'kg__51341', name: '民谣榜', bangid: '51341' }, { id: 'kg__54848', name: '台湾地区榜', bangid: '54848' }, { id: 'kg__31310', name: '欧美榜', bangid: '31310' }, { id: 'kg__33162', name: 'ACG新歌榜', bangid: '33162' }, { id: 'kg__31311', name: '韩国榜', bangid: '31311' }, { id: 'kg__31312', name: '日本榜', bangid: '31312' }, { id: 'kg__49225', name: '80后热歌榜', bangid: '49225' }, { id: 'kg__49223', name: '90后热歌榜', bangid: '49223' }, { id: 'kg__49224', name: '00后热歌榜', bangid: '49224' }, { id: 'kg__33165', name: '粤语金曲榜', bangid: '33165' }, { id: 'kg__33166', name: '欧美金曲榜', bangid: '33166' }, { id: 'kg__33163', name: '影视金曲榜', bangid: '33163' }, { id: 'kg__51340', name: '伤感榜', bangid: '51340' }, { id: 'kg__35811', name: '会员专享榜', bangid: '35811' }, { id: 'kg__37361', name: '雷达榜', bangid: '37361' }, { id: 'kg__21101', name: '分享榜', bangid: '21101' }, { id: 'kg__46910', name: '综艺新歌榜', bangid: '46910' }, { id: 'kg__30972', name: '酷狗音乐人原创榜', bangid: '30972' }, { id: 'kg__60170', name: '闽南语榜', bangid: '60170' }, { id: 'kg__65234', name: '儿歌榜', bangid: '65234' }, { id: 'kg__4681', name: '美国BillBoard榜', bangid: '4681' }, { id: 'kg__25028', name: 'Beatport电子舞曲榜', bangid: '25028' }, { id: 'kg__4680', name: '英国单曲榜', bangid: '4680' }, { id: 'kg__38623', name: '韩国Melon音乐榜', bangid: '38623' }, { id: 'kg__42807', name: 'joox本地热歌榜', bangid: '42807' }, { id: 'kg__36107', name: '小语种热歌榜', bangid: '36107' }, { id: 'kg__4673', name: '日本公信榜', bangid: '4673' }, { id: 'kg__46868', name: '日本SPACE SHOWER榜', bangid: '46868' }, { id: 'kg__42808', name: 'KKBOX风云榜', bangid: '42808' }, { id: 'kg__60171', name: '越南语榜', bangid: '60171' }, { id: 'kg__60172', name: '泰语榜', bangid: '60172' }, { id: 'kg__59895', name: 'R&B榜', bangid: '59895' }, { id: 'kg__59896', name: '摇滚榜', bangid: '59896' }, { id: 'kg__59897', name: '爵士榜', bangid: '59897' }, { id: 'kg__59898', name: '乡村音乐榜', bangid: '59898' }, { id: 'kg__59900', name: '纯音乐榜', bangid: '59900' }, { id: 'kg__59899', name: '古典榜', bangid: '59899' }, { id: 'kg__22603', name: '5sing音乐榜', bangid: '22603' }, { id: 'kg__21335', name: '繁星音乐榜', bangid: '21335' }, { id: 'kg__33161', name: '古风新歌榜', bangid: '33161' }] - -export default { - listDetailLimit: 100, - list: [ - { - id: 'kgtop500', - name: 'TOP500', - bangid: '8888', - }, - { - id: 'kgwlhgb', - name: '网络榜', - bangid: '23784', - }, - { - id: 'kgbsb', - name: '飙升榜', - bangid: '6666', - }, - { - id: 'kgfxb', - name: '分享榜', - bangid: '21101', - }, - { - id: 'kgcyyb', - name: '纯音乐榜', - bangid: '33164', - }, - { - id: 'kggfjqb', - name: '古风榜', - bangid: '33161', - }, - { - id: 'kgyyjqb', - name: '粤语榜', - bangid: '33165', - }, - { - id: 'kgomjqb', - name: '欧美榜', - bangid: '33166', - }, - { - id: 'kgdyrgb', - name: '电音榜', - bangid: '33160', - }, - { - id: 'kgjdrgb', - name: 'DJ热歌榜', - bangid: '24971', - }, - { - id: 'kghyxgb', - name: '华语新歌榜', - bangid: '31308', - }, - ], - getUrl(p, id, limit) { - return `http://mobilecdnbj.kugou.com/api/v3/rank/song?version=9108&ranktype=1&plat=0&pagesize=${limit}&area_code=1&page=${p}&rankid=${id}&with_res_tag=0&show_portrait_mv=1` - }, - regExps: { - total: /total: '(\d+)',/, - page: /page: '(\d+)',/, - limit: /pagesize: '(\d+)',/, - listData: /global\.features = (\[.+\]);/, - }, - _requestBoardsObj: null, - getBoardsData() { - if (this._requestBoardsObj) this._requestBoardsObj.cancelHttp() - this._requestBoardsObj = httpFetch('http://mobilecdnbj.kugou.com/api/v5/rank/list?version=9108&plat=0&showtype=2&parentid=0&apiver=6&area_code=1&withsong=1') - return this._requestBoardsObj.promise - }, - getData(url) { - const requestDataObj = httpFetch(url) - return requestDataObj.promise - }, - getSinger(singers) { - let arr = [] - singers.forEach(singer => { - arr.push(singer.author_name) - }) - return arr.join('、') - }, - filterData(rawList) { - // 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['320filesize'] !== 0) { - let size = sizeFormate(item['320filesize']) - types.push({ type: '320k', size, hash: item['320hash'] }) - _types['320k'] = { - size, - hash: item['320hash'], - } - } - if (item.sqfilesize !== 0) { - let size = sizeFormate(item.sqfilesize) - types.push({ type: 'flac', size, hash: item.sqhash }) - _types.flac = { - size, - hash: item.sqhash, - } - } - if (item.filesize_high !== 0) { - let size = sizeFormate(item.filesize_high) - types.push({ type: 'flac24bit', size, hash: item.hash_high }) - _types.flac24bit = { - size, - hash: item.hash_high, - } - } - return { - singer: formatSingerName(item.authors, 'author_name'), - singerList: formatSingerList(item.authors, 'author_id', 'author_name'), - name: decodeName(item.songname), - albumName: decodeName(item.remark), - albumId: item.album_id, - songmid: item.audio_id, - source: 'kg', - interval: formatPlayTime(item.duration), - img: null, - lrc: null, - hash: item.hash, - otherSource: null, - types, - _types, - typeUrl: {}, - } - }) - }, - - filterBoardsData(rawList) { - // console.log(rawList) - let list = [] - for (const board of rawList) { - if (board.isvol != 1) continue - list.push({ - id: 'kg__' + board.rankid, - name: board.rankname, - bangid: String(board.rankid), - }) - } - return list - }, - async getBoards(retryNum = 0) { - // if (++retryNum > 3) return Promise.reject(new Error('try max num')) - // let response - // try { - // response = await this.getBoardsData() - // } catch (error) { - // return this.getBoards(retryNum) - // } - // // console.log(response.body) - // if (response.statusCode !== 200 || response.body.errcode !== 0) return this.getBoards(retryNum) - // const list = this.filterBoardsData(response.body.data.info) - // console.log(list) - // // console.log(JSON.stringify(list)) - // this.list = list - // return { - // list, - // source: 'kg', - // } - this.list = boardList - return { - list: boardList, - source: 'kg', - } - }, - async getList(bangid, page, retryNum = 0) { - if (++retryNum > 3) throw new Error('try max num') - const { body } = await this.getData(this.getUrl(page, bangid, this.listDetailLimit)) - - if (body.errcode != 0) return this.getList(bangid, page, retryNum) - - // console.log(body) - let total = body.data.total - let limit = 100 - let listData = this.filterData(body.data.info) - // console.log(listData) - return { - total, - list: listData, - limit, - page, - source: 'kg', - } - }, - getDetailPageUrl(id) { - if (typeof id == 'string') id = id.replace('kg__', '') - return `https://www.kugou.com/yy/rank/home/1-${id}.html` - }, -} diff --git a/.history/src/renderer/utils/musicSdk/kg/leaderboard_20230610020923.js b/.history/src/renderer/utils/musicSdk/kg/leaderboard_20230610020923.js deleted file mode 100644 index 6089e52b..00000000 --- a/.history/src/renderer/utils/musicSdk/kg/leaderboard_20230610020923.js +++ /dev/null @@ -1,209 +0,0 @@ -import { httpFetch } from '../../request' -import { decodeName, formatPlayTime, sizeFormate } from '../../index' -import { formatSingerName, formatSingerList } from '../utils' - -let boardList = [{ id: 'kg__8888', name: 'TOP500', bangid: '8888' }, { id: 'kg__6666', name: '飙升榜', bangid: '6666' }, { id: 'kg__59703', name: '蜂鸟流行音乐榜', bangid: '59703' }, { id: 'kg__52144', name: '抖音热歌榜', bangid: '52144' }, { id: 'kg__52767', name: '快手热歌榜', bangid: '52767' }, { id: 'kg__24971', name: 'DJ热歌榜', bangid: '24971' }, { id: 'kg__23784', name: '网络红歌榜', bangid: '23784' }, { id: 'kg__44412', name: '说唱先锋榜', bangid: '44412' }, { id: 'kg__31308', name: '内地榜', bangid: '31308' }, { id: 'kg__33160', name: '电音榜', bangid: '33160' }, { id: 'kg__31313', name: '香港地区榜', bangid: '31313' }, { id: 'kg__51341', name: '民谣榜', bangid: '51341' }, { id: 'kg__54848', name: '台湾地区榜', bangid: '54848' }, { id: 'kg__31310', name: '欧美榜', bangid: '31310' }, { id: 'kg__33162', name: 'ACG新歌榜', bangid: '33162' }, { id: 'kg__31311', name: '韩国榜', bangid: '31311' }, { id: 'kg__31312', name: '日本榜', bangid: '31312' }, { id: 'kg__49225', name: '80后热歌榜', bangid: '49225' }, { id: 'kg__49223', name: '90后热歌榜', bangid: '49223' }, { id: 'kg__49224', name: '00后热歌榜', bangid: '49224' }, { id: 'kg__33165', name: '粤语金曲榜', bangid: '33165' }, { id: 'kg__33166', name: '欧美金曲榜', bangid: '33166' }, { id: 'kg__33163', name: '影视金曲榜', bangid: '33163' }, { id: 'kg__51340', name: '伤感榜', bangid: '51340' }, { id: 'kg__35811', name: '会员专享榜', bangid: '35811' }, { id: 'kg__37361', name: '雷达榜', bangid: '37361' }, { id: 'kg__21101', name: '分享榜', bangid: '21101' }, { id: 'kg__46910', name: '综艺新歌榜', bangid: '46910' }, { id: 'kg__30972', name: '酷狗音乐人原创榜', bangid: '30972' }, { id: 'kg__60170', name: '闽南语榜', bangid: '60170' }, { id: 'kg__65234', name: '儿歌榜', bangid: '65234' }, { id: 'kg__4681', name: '美国BillBoard榜', bangid: '4681' }, { id: 'kg__25028', name: 'Beatport电子舞曲榜', bangid: '25028' }, { id: 'kg__4680', name: '英国单曲榜', bangid: '4680' }, { id: 'kg__38623', name: '韩国Melon音乐榜', bangid: '38623' }, { id: 'kg__42807', name: 'joox本地热歌榜', bangid: '42807' }, { id: 'kg__36107', name: '小语种热歌榜', bangid: '36107' }, { id: 'kg__4673', name: '日本公信榜', bangid: '4673' }, { id: 'kg__46868', name: '日本SPACE SHOWER榜', bangid: '46868' }, { id: 'kg__42808', name: 'KKBOX风云榜', bangid: '42808' }, { id: 'kg__60171', name: '越南语榜', bangid: '60171' }, { id: 'kg__60172', name: '泰语榜', bangid: '60172' }, { id: 'kg__59895', name: 'R&B榜', bangid: '59895' }, { id: 'kg__59896', name: '摇滚榜', bangid: '59896' }, { id: 'kg__59897', name: '爵士榜', bangid: '59897' }, { id: 'kg__59898', name: '乡村音乐榜', bangid: '59898' }, { id: 'kg__59900', name: '纯音乐榜', bangid: '59900' }, { id: 'kg__59899', name: '古典榜', bangid: '59899' }, { id: 'kg__22603', name: '5sing音乐榜', bangid: '22603' }, { id: 'kg__21335', name: '繁星音乐榜', bangid: '21335' }, { id: 'kg__33161', name: '古风新歌榜', bangid: '33161' }] - -export default { - listDetailLimit: 100, - list: [ - { - id: 'kgtop500', - name: 'TOP500', - bangid: '8888', - }, - { - id: 'kgwlhgb', - name: '网络榜', - bangid: '23784', - }, - { - id: 'kgbsb', - name: '飙升榜', - bangid: '6666', - }, - { - id: 'kgfxb', - name: '分享榜', - bangid: '21101', - }, - { - id: 'kgcyyb', - name: '纯音乐榜', - bangid: '33164', - }, - { - id: 'kggfjqb', - name: '古风榜', - bangid: '33161', - }, - { - id: 'kgyyjqb', - name: '粤语榜', - bangid: '33165', - }, - { - id: 'kgomjqb', - name: '欧美榜', - bangid: '33166', - }, - { - id: 'kgdyrgb', - name: '电音榜', - bangid: '33160', - }, - { - id: 'kgjdrgb', - name: 'DJ热歌榜', - bangid: '24971', - }, - { - id: 'kghyxgb', - name: '华语新歌榜', - bangid: '31308', - }, - ], - getUrl(p, id, limit) { - return `http://mobilecdnbj.kugou.com/api/v3/rank/song?version=9108&ranktype=1&plat=0&pagesize=${limit}&area_code=1&page=${p}&rankid=${id}&with_res_tag=0&show_portrait_mv=1` - }, - regExps: { - total: /total: '(\d+)',/, - page: /page: '(\d+)',/, - limit: /pagesize: '(\d+)',/, - listData: /global\.features = (\[.+\]);/, - }, - _requestBoardsObj: null, - getBoardsData() { - if (this._requestBoardsObj) this._requestBoardsObj.cancelHttp() - this._requestBoardsObj = httpFetch('http://mobilecdnbj.kugou.com/api/v5/rank/list?version=9108&plat=0&showtype=2&parentid=0&apiver=6&area_code=1&withsong=1') - return this._requestBoardsObj.promise - }, - getData(url) { - const requestDataObj = httpFetch(url) - return requestDataObj.promise - }, - getSinger(singers) { - let arr = [] - singers.forEach(singer => { - arr.push(singer.author_name) - }) - return arr.join('、') - }, - filterData(rawList) { - // 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['320filesize'] !== 0) { - let size = sizeFormate(item['320filesize']) - types.push({ type: '320k', size, hash: item['320hash'] }) - _types['320k'] = { - size, - hash: item['320hash'], - } - } - if (item.sqfilesize !== 0) { - let size = sizeFormate(item.sqfilesize) - types.push({ type: 'flac', size, hash: item.sqhash }) - _types.flac = { - size, - hash: item.sqhash, - } - } - if (item.filesize_high !== 0) { - let size = sizeFormate(item.filesize_high) - types.push({ type: 'flac24bit', size, hash: item.hash_high }) - _types.flac24bit = { - size, - hash: item.hash_high, - } - } - return { - singer: formatSingerName(item.authors, 'author_name'), - singerList: formatSingerList(item.authors, 'author_id', 'author_name'), - name: decodeName(item.songname), - albumName: decodeName(item.remark), - albumId: item.album_id, - songmid: item.audio_id, - source: 'kg', - interval: formatPlayTime(item.duration), - img: null, - lrc: null, - hash: item.hash, - otherSource: null, - types, - _types, - typeUrl: {}, - } - }) - }, - - filterBoardsData(rawList) { - // console.log(rawList) - let list = [] - for (const board of rawList) { - if (board.isvol != 1) continue - list.push({ - id: 'kg__' + board.rankid, - name: board.rankname, - bangid: String(board.rankid), - }) - } - return list - }, - async getBoards(retryNum = 0) { - // if (++retryNum > 3) return Promise.reject(new Error('try max num')) - // let response - // try { - // response = await this.getBoardsData() - // } catch (error) { - // return this.getBoards(retryNum) - // } - // // console.log(response.body) - // if (response.statusCode !== 200 || response.body.errcode !== 0) return this.getBoards(retryNum) - // const list = this.filterBoardsData(response.body.data.info) - // console.log(list) - // // console.log(JSON.stringify(list)) - // this.list = list - // return { - // list, - // source: 'kg', - // } - this.list = boardList - return { - list: boardList, - source: 'kg', - } - }, - async getList(bangid, page, retryNum = 0) { - if (++retryNum > 3) throw new Error('try max num') - const { body } = await this.getData(this.getUrl(page, bangid, this.listDetailLimit)) - - if (body.errcode != 0) return this.getList(bangid, page, retryNum) - - // console.log(body) - let total = body.data.total - let limit = 100 - let listData = this.filterData(body.data.info) - // console.log(listData) - return { - total, - list: listData, - limit, - page, - source: 'kg', - } - }, - getDetailPageUrl(id) { - if (typeof id == 'string') id = id.replace('kg__', '') - return `https://www.kugou.com/yy/rank/home/1-${id}.html` - }, -} diff --git a/.history/src/renderer/utils/musicSdk/kg/leaderboard_20230610020958.js b/.history/src/renderer/utils/musicSdk/kg/leaderboard_20230610020958.js deleted file mode 100644 index ea7d2c2b..00000000 --- a/.history/src/renderer/utils/musicSdk/kg/leaderboard_20230610020958.js +++ /dev/null @@ -1,209 +0,0 @@ -import { httpFetch } from '../../request' -import { decodeName, formatPlayTime, sizeFormate } from '../../index' -import { formatSingerName, formatSingerList } from '../utils' - -let boardList = [{ id: 'kg__8888', name: 'TOP500', bangid: '8888' }, { id: 'kg__6666', name: '飙升榜', bangid: '6666' }, { id: 'kg__59703', name: '蜂鸟流行音乐榜', bangid: '59703' }, { id: 'kg__52144', name: '抖音热歌榜', bangid: '52144' }, { id: 'kg__52767', name: '快手热歌榜', bangid: '52767' }, { id: 'kg__24971', name: 'DJ热歌榜', bangid: '24971' }, { id: 'kg__23784', name: '网络红歌榜', bangid: '23784' }, { id: 'kg__44412', name: '说唱先锋榜', bangid: '44412' }, { id: 'kg__31308', name: '内地榜', bangid: '31308' }, { id: 'kg__33160', name: '电音榜', bangid: '33160' }, { id: 'kg__31313', name: '香港地区榜', bangid: '31313' }, { id: 'kg__51341', name: '民谣榜', bangid: '51341' }, { id: 'kg__54848', name: '台湾地区榜', bangid: '54848' }, { id: 'kg__31310', name: '欧美榜', bangid: '31310' }, { id: 'kg__33162', name: 'ACG新歌榜', bangid: '33162' }, { id: 'kg__31311', name: '韩国榜', bangid: '31311' }, { id: 'kg__31312', name: '日本榜', bangid: '31312' }, { id: 'kg__49225', name: '80后热歌榜', bangid: '49225' }, { id: 'kg__49223', name: '90后热歌榜', bangid: '49223' }, { id: 'kg__49224', name: '00后热歌榜', bangid: '49224' }, { id: 'kg__33165', name: '粤语金曲榜', bangid: '33165' }, { id: 'kg__33166', name: '欧美金曲榜', bangid: '33166' }, { id: 'kg__33163', name: '影视金曲榜', bangid: '33163' }, { id: 'kg__51340', name: '伤感榜', bangid: '51340' }, { id: 'kg__35811', name: '会员专享榜', bangid: '35811' }, { id: 'kg__37361', name: '雷达榜', bangid: '37361' }, { id: 'kg__21101', name: '分享榜', bangid: '21101' }, { id: 'kg__46910', name: '综艺新歌榜', bangid: '46910' }, { id: 'kg__30972', name: '酷狗音乐人原创榜', bangid: '30972' }, { id: 'kg__60170', name: '闽南语榜', bangid: '60170' }, { id: 'kg__65234', name: '儿歌榜', bangid: '65234' }, { id: 'kg__4681', name: '美国BillBoard榜', bangid: '4681' }, { id: 'kg__25028', name: 'Beatport电子舞曲榜', bangid: '25028' }, { id: 'kg__4680', name: '英国单曲榜', bangid: '4680' }, { id: 'kg__38623', name: '韩国Melon音乐榜', bangid: '38623' }, { id: 'kg__42807', name: 'joox本地热歌榜', bangid: '42807' }, { id: 'kg__36107', name: '小语种热歌榜', bangid: '36107' }, { id: 'kg__4673', name: '日本公信榜', bangid: '4673' }, { id: 'kg__46868', name: '日本SPACE SHOWER榜', bangid: '46868' }, { id: 'kg__42808', name: 'KKBOX风云榜', bangid: '42808' }, { id: 'kg__60171', name: '越南语榜', bangid: '60171' }, { id: 'kg__60172', name: '泰语榜', bangid: '60172' }, { id: 'kg__59895', name: 'R&B榜', bangid: '59895' }, { id: 'kg__59896', name: '摇滚榜', bangid: '59896' }, { id: 'kg__59897', name: '爵士榜', bangid: '59897' }, { id: 'kg__59898', name: '乡村音乐榜', bangid: '59898' }, { id: 'kg__59900', name: '纯音乐榜', bangid: '59900' }, { id: 'kg__59899', name: '古典榜', bangid: '59899' }, { id: 'kg__22603', name: '5sing音乐榜', bangid: '22603' }, { id: 'kg__21335', name: '繁星音乐榜', bangid: '21335' }, { id: 'kg__33161', name: '古风新歌榜', bangid: '33161' }] - -export default { - listDetailLimit: 100, - list: [ - { - id: 'kgtop500', - name: 'TOP500', - bangid: '8888', - }, - { - id: 'kgwlhgb', - name: '网络榜', - bangid: '23784', - }, - { - id: 'kgbsb', - name: '飙升榜', - bangid: '6666', - }, - { - id: 'kgfxb', - name: '分享榜', - bangid: '21101', - }, - { - id: 'kgcyyb', - name: '纯音乐榜', - bangid: '33164', - }, - { - id: 'kggfjqb', - name: '古风榜', - bangid: '33161', - }, - { - id: 'kgyyjqb', - name: '粤语榜', - bangid: '33165', - }, - { - id: 'kgomjqb', - name: '欧美榜', - bangid: '33166', - }, - { - id: 'kgdyrgb', - name: '电音榜', - bangid: '33160', - }, - { - id: 'kgjdrgb', - name: 'DJ热歌榜', - bangid: '24971', - }, - { - id: 'kghyxgb', - name: '华语新歌榜', - bangid: '31308', - }, - ], - getUrl(p, id, limit) { - return `http://mobilecdnbj.kugou.com/api/v3/rank/song?version=9108&ranktype=1&plat=0&pagesize=${limit}&area_code=1&page=${p}&rankid=${id}&with_res_tag=0&show_portrait_mv=1` - }, - regExps: { - total: /total: '(\d+)',/, - page: /page: '(\d+)',/, - limit: /pagesize: '(\d+)',/, - listData: /global\.features = (\[.+\]);/, - }, - _requestBoardsObj: null, - getBoardsData() { - if (this._requestBoardsObj) this._requestBoardsObj.cancelHttp() - this._requestBoardsObj = httpFetch('http://mobilecdnbj.kugou.com/api/v5/rank/list?version=9108&plat=0&showtype=2&parentid=0&apiver=6&area_code=1&withsong=1') - return this._requestBoardsObj.promise - }, - getData(url) { - const requestDataObj = httpFetch(url) - return requestDataObj.promise - }, - getSinger(singers) { - let arr = [] - singers.forEach(singer => { - arr.push(singer.author_name) - }) - return arr.join('、') - }, - filterData(rawList) { - // 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['320filesize'] !== 0) { - let size = sizeFormate(item['320filesize']) - types.push({ type: '320k', size, hash: item['320hash'] }) - _types['320k'] = { - size, - hash: item['320hash'], - } - } - if (item.sqfilesize !== 0) { - let size = sizeFormate(item.sqfilesize) - types.push({ type: 'flac', size, hash: item.sqhash }) - _types.flac = { - size, - hash: item.sqhash, - } - } - if (item.filesize_high !== 0) { - let size = sizeFormate(item.filesize_high) - types.push({ type: 'flac24bit', size, hash: item.hash_high }) - _types.flac24bit = { - size, - hash: item.hash_high, - } - } - return { - singer: formatSingerName(item.authors, 'author_name'), - singerList: formatSingerList(item.authors, 'author_name', 'author_id', ''), - name: decodeName(item.songname), - albumName: decodeName(item.remark), - albumId: item.album_id, - songmid: item.audio_id, - source: 'kg', - interval: formatPlayTime(item.duration), - img: null, - lrc: null, - hash: item.hash, - otherSource: null, - types, - _types, - typeUrl: {}, - } - }) - }, - - filterBoardsData(rawList) { - // console.log(rawList) - let list = [] - for (const board of rawList) { - if (board.isvol != 1) continue - list.push({ - id: 'kg__' + board.rankid, - name: board.rankname, - bangid: String(board.rankid), - }) - } - return list - }, - async getBoards(retryNum = 0) { - // if (++retryNum > 3) return Promise.reject(new Error('try max num')) - // let response - // try { - // response = await this.getBoardsData() - // } catch (error) { - // return this.getBoards(retryNum) - // } - // // console.log(response.body) - // if (response.statusCode !== 200 || response.body.errcode !== 0) return this.getBoards(retryNum) - // const list = this.filterBoardsData(response.body.data.info) - // console.log(list) - // // console.log(JSON.stringify(list)) - // this.list = list - // return { - // list, - // source: 'kg', - // } - this.list = boardList - return { - list: boardList, - source: 'kg', - } - }, - async getList(bangid, page, retryNum = 0) { - if (++retryNum > 3) throw new Error('try max num') - const { body } = await this.getData(this.getUrl(page, bangid, this.listDetailLimit)) - - if (body.errcode != 0) return this.getList(bangid, page, retryNum) - - // console.log(body) - let total = body.data.total - let limit = 100 - let listData = this.filterData(body.data.info) - // console.log(listData) - return { - total, - list: listData, - limit, - page, - source: 'kg', - } - }, - getDetailPageUrl(id) { - if (typeof id == 'string') id = id.replace('kg__', '') - return `https://www.kugou.com/yy/rank/home/1-${id}.html` - }, -} diff --git a/.history/src/renderer/utils/musicSdk/kg/leaderboard_20230610021001.js b/.history/src/renderer/utils/musicSdk/kg/leaderboard_20230610021001.js deleted file mode 100644 index a9e48d17..00000000 --- a/.history/src/renderer/utils/musicSdk/kg/leaderboard_20230610021001.js +++ /dev/null @@ -1,209 +0,0 @@ -import { httpFetch } from '../../request' -import { decodeName, formatPlayTime, sizeFormate } from '../../index' -import { formatSingerName, formatSingerList } from '../utils' - -let boardList = [{ id: 'kg__8888', name: 'TOP500', bangid: '8888' }, { id: 'kg__6666', name: '飙升榜', bangid: '6666' }, { id: 'kg__59703', name: '蜂鸟流行音乐榜', bangid: '59703' }, { id: 'kg__52144', name: '抖音热歌榜', bangid: '52144' }, { id: 'kg__52767', name: '快手热歌榜', bangid: '52767' }, { id: 'kg__24971', name: 'DJ热歌榜', bangid: '24971' }, { id: 'kg__23784', name: '网络红歌榜', bangid: '23784' }, { id: 'kg__44412', name: '说唱先锋榜', bangid: '44412' }, { id: 'kg__31308', name: '内地榜', bangid: '31308' }, { id: 'kg__33160', name: '电音榜', bangid: '33160' }, { id: 'kg__31313', name: '香港地区榜', bangid: '31313' }, { id: 'kg__51341', name: '民谣榜', bangid: '51341' }, { id: 'kg__54848', name: '台湾地区榜', bangid: '54848' }, { id: 'kg__31310', name: '欧美榜', bangid: '31310' }, { id: 'kg__33162', name: 'ACG新歌榜', bangid: '33162' }, { id: 'kg__31311', name: '韩国榜', bangid: '31311' }, { id: 'kg__31312', name: '日本榜', bangid: '31312' }, { id: 'kg__49225', name: '80后热歌榜', bangid: '49225' }, { id: 'kg__49223', name: '90后热歌榜', bangid: '49223' }, { id: 'kg__49224', name: '00后热歌榜', bangid: '49224' }, { id: 'kg__33165', name: '粤语金曲榜', bangid: '33165' }, { id: 'kg__33166', name: '欧美金曲榜', bangid: '33166' }, { id: 'kg__33163', name: '影视金曲榜', bangid: '33163' }, { id: 'kg__51340', name: '伤感榜', bangid: '51340' }, { id: 'kg__35811', name: '会员专享榜', bangid: '35811' }, { id: 'kg__37361', name: '雷达榜', bangid: '37361' }, { id: 'kg__21101', name: '分享榜', bangid: '21101' }, { id: 'kg__46910', name: '综艺新歌榜', bangid: '46910' }, { id: 'kg__30972', name: '酷狗音乐人原创榜', bangid: '30972' }, { id: 'kg__60170', name: '闽南语榜', bangid: '60170' }, { id: 'kg__65234', name: '儿歌榜', bangid: '65234' }, { id: 'kg__4681', name: '美国BillBoard榜', bangid: '4681' }, { id: 'kg__25028', name: 'Beatport电子舞曲榜', bangid: '25028' }, { id: 'kg__4680', name: '英国单曲榜', bangid: '4680' }, { id: 'kg__38623', name: '韩国Melon音乐榜', bangid: '38623' }, { id: 'kg__42807', name: 'joox本地热歌榜', bangid: '42807' }, { id: 'kg__36107', name: '小语种热歌榜', bangid: '36107' }, { id: 'kg__4673', name: '日本公信榜', bangid: '4673' }, { id: 'kg__46868', name: '日本SPACE SHOWER榜', bangid: '46868' }, { id: 'kg__42808', name: 'KKBOX风云榜', bangid: '42808' }, { id: 'kg__60171', name: '越南语榜', bangid: '60171' }, { id: 'kg__60172', name: '泰语榜', bangid: '60172' }, { id: 'kg__59895', name: 'R&B榜', bangid: '59895' }, { id: 'kg__59896', name: '摇滚榜', bangid: '59896' }, { id: 'kg__59897', name: '爵士榜', bangid: '59897' }, { id: 'kg__59898', name: '乡村音乐榜', bangid: '59898' }, { id: 'kg__59900', name: '纯音乐榜', bangid: '59900' }, { id: 'kg__59899', name: '古典榜', bangid: '59899' }, { id: 'kg__22603', name: '5sing音乐榜', bangid: '22603' }, { id: 'kg__21335', name: '繁星音乐榜', bangid: '21335' }, { id: 'kg__33161', name: '古风新歌榜', bangid: '33161' }] - -export default { - listDetailLimit: 100, - list: [ - { - id: 'kgtop500', - name: 'TOP500', - bangid: '8888', - }, - { - id: 'kgwlhgb', - name: '网络榜', - bangid: '23784', - }, - { - id: 'kgbsb', - name: '飙升榜', - bangid: '6666', - }, - { - id: 'kgfxb', - name: '分享榜', - bangid: '21101', - }, - { - id: 'kgcyyb', - name: '纯音乐榜', - bangid: '33164', - }, - { - id: 'kggfjqb', - name: '古风榜', - bangid: '33161', - }, - { - id: 'kgyyjqb', - name: '粤语榜', - bangid: '33165', - }, - { - id: 'kgomjqb', - name: '欧美榜', - bangid: '33166', - }, - { - id: 'kgdyrgb', - name: '电音榜', - bangid: '33160', - }, - { - id: 'kgjdrgb', - name: 'DJ热歌榜', - bangid: '24971', - }, - { - id: 'kghyxgb', - name: '华语新歌榜', - bangid: '31308', - }, - ], - getUrl(p, id, limit) { - return `http://mobilecdnbj.kugou.com/api/v3/rank/song?version=9108&ranktype=1&plat=0&pagesize=${limit}&area_code=1&page=${p}&rankid=${id}&with_res_tag=0&show_portrait_mv=1` - }, - regExps: { - total: /total: '(\d+)',/, - page: /page: '(\d+)',/, - limit: /pagesize: '(\d+)',/, - listData: /global\.features = (\[.+\]);/, - }, - _requestBoardsObj: null, - getBoardsData() { - if (this._requestBoardsObj) this._requestBoardsObj.cancelHttp() - this._requestBoardsObj = httpFetch('http://mobilecdnbj.kugou.com/api/v5/rank/list?version=9108&plat=0&showtype=2&parentid=0&apiver=6&area_code=1&withsong=1') - return this._requestBoardsObj.promise - }, - getData(url) { - const requestDataObj = httpFetch(url) - return requestDataObj.promise - }, - getSinger(singers) { - let arr = [] - singers.forEach(singer => { - arr.push(singer.author_name) - }) - return arr.join('、') - }, - filterData(rawList) { - // 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['320filesize'] !== 0) { - let size = sizeFormate(item['320filesize']) - types.push({ type: '320k', size, hash: item['320hash'] }) - _types['320k'] = { - size, - hash: item['320hash'], - } - } - if (item.sqfilesize !== 0) { - let size = sizeFormate(item.sqfilesize) - types.push({ type: 'flac', size, hash: item.sqhash }) - _types.flac = { - size, - hash: item.sqhash, - } - } - if (item.filesize_high !== 0) { - let size = sizeFormate(item.filesize_high) - types.push({ type: 'flac24bit', size, hash: item.hash_high }) - _types.flac24bit = { - size, - hash: item.hash_high, - } - } - return { - singer: formatSingerName(item.authors, 'author_name'), - singerList: formatSingerList(item.authors, 'author_name', 'author_id'), - name: decodeName(item.songname), - albumName: decodeName(item.remark), - albumId: item.album_id, - songmid: item.audio_id, - source: 'kg', - interval: formatPlayTime(item.duration), - img: null, - lrc: null, - hash: item.hash, - otherSource: null, - types, - _types, - typeUrl: {}, - } - }) - }, - - filterBoardsData(rawList) { - // console.log(rawList) - let list = [] - for (const board of rawList) { - if (board.isvol != 1) continue - list.push({ - id: 'kg__' + board.rankid, - name: board.rankname, - bangid: String(board.rankid), - }) - } - return list - }, - async getBoards(retryNum = 0) { - // if (++retryNum > 3) return Promise.reject(new Error('try max num')) - // let response - // try { - // response = await this.getBoardsData() - // } catch (error) { - // return this.getBoards(retryNum) - // } - // // console.log(response.body) - // if (response.statusCode !== 200 || response.body.errcode !== 0) return this.getBoards(retryNum) - // const list = this.filterBoardsData(response.body.data.info) - // console.log(list) - // // console.log(JSON.stringify(list)) - // this.list = list - // return { - // list, - // source: 'kg', - // } - this.list = boardList - return { - list: boardList, - source: 'kg', - } - }, - async getList(bangid, page, retryNum = 0) { - if (++retryNum > 3) throw new Error('try max num') - const { body } = await this.getData(this.getUrl(page, bangid, this.listDetailLimit)) - - if (body.errcode != 0) return this.getList(bangid, page, retryNum) - - // console.log(body) - let total = body.data.total - let limit = 100 - let listData = this.filterData(body.data.info) - // console.log(listData) - return { - total, - list: listData, - limit, - page, - source: 'kg', - } - }, - getDetailPageUrl(id) { - if (typeof id == 'string') id = id.replace('kg__', '') - return `https://www.kugou.com/yy/rank/home/1-${id}.html` - }, -} diff --git a/.history/src/renderer/utils/musicSdk/kg/musicSearch_20230610002212.js b/.history/src/renderer/utils/musicSdk/kg/musicSearch_20230610002212.js deleted file mode 100644 index 1b76545c..00000000 --- a/.history/src/renderer/utils/musicSdk/kg/musicSearch_20230610002212.js +++ /dev/null @@ -1,109 +0,0 @@ -import { httpFetch } from '../../request' -import { decodeName, formatPlayTime, sizeFormate } from '../../index' -import { formatSingerName } from '../utils' -import { formatSingerList } from './util' - -export default { - limit: 30, - total: 0, - page: 0, - allPage: 1, - musicSearch(str, page, limit) { - const searchRequest = httpFetch(`https://songsearch.kugou.com/song_search_v2?keyword=${encodeURIComponent(str)}&page=${page}&pagesize=${limit}&userid=0&clientver=&platform=WebFilter&filter=2&iscorrection=1&privilege_filter=0`) - return searchRequest.promise.then(({ body }) => body) - }, - filterData(rawData) { - const types = [] - const _types = {} - if (rawData.FileSize !== 0) { - let size = sizeFormate(rawData.FileSize) - types.push({ type: '128k', size, hash: rawData.FileHash }) - _types['128k'] = { - size, - hash: rawData.FileHash, - } - } - if (rawData.HQFileSize !== 0) { - let size = sizeFormate(rawData.HQFileSize) - types.push({ type: '320k', size, hash: rawData.HQFileHash }) - _types['320k'] = { - size, - hash: rawData.HQFileHash, - } - } - if (rawData.SQFileSize !== 0) { - let size = sizeFormate(rawData.SQFileSize) - types.push({ type: 'flac', size, hash: rawData.SQFileHash }) - _types.flac = { - size, - hash: rawData.SQFileHash, - } - } - if (rawData.ResFileSize !== 0) { - let size = sizeFormate(rawData.ResFileSize) - types.push({ type: 'flac24bit', size, hash: rawData.ResFileHash }) - _types.flac24bit = { - size, - hash: rawData.ResFileHash, - } - } - return { - singer: decodeName(formatSingerName(rawData.Singers, 'name')), - singerList: formatSingerList(rawData.Singers), - name: decodeName(rawData.SongName), - albumName: decodeName(rawData.AlbumName), - albumId: rawData.AlbumID, - songmid: rawData.Audioid, - source: 'kg', - interval: formatPlayTime(rawData.Duration), - _interval: rawData.Duration, - img: null, - lrc: null, - otherSource: null, - hash: rawData.FileHash, - types, - _types, - typeUrl: {}, - } - }, - handleResult(rawData) { - let ids = new Set() - const list = [] - rawData.forEach(item => { - const key = item.Audioid + item.FileHash - if (ids.has(key)) return - ids.add(key) - list.push(this.filterData(item)) - for (const childItem of item.Grp) { - const key = item.Audioid + item.FileHash - if (ids.has(key)) continue - ids.add(key) - list.push(this.filterData(childItem)) - } - }) - return list - }, - search(str, page = 1, limit, retryNum = 0) { - if (++retryNum > 3) return Promise.reject(new Error('try max num')) - if (limit == null) limit = this.limit - // http://newlyric.kuwo.cn/newlyric.lrc?62355680 - return this.musicSearch(str, page, limit).then(result => { - if (!result || result.error_code !== 0) return this.search(str, page, limit, retryNum) - let list = this.handleResult(result.data.lists) - - if (list == null) return this.search(str, page, limit, retryNum) - - this.total = result.data.total - this.page = page - this.allPage = Math.ceil(this.total / limit) - - return Promise.resolve({ - list, - allPage: this.allPage, - limit, - total: this.total, - source: 'kg', - }) - }) - }, -} diff --git a/.history/src/renderer/utils/musicSdk/kg/musicSearch_20230610021152.js b/.history/src/renderer/utils/musicSdk/kg/musicSearch_20230610021152.js deleted file mode 100644 index ebc9e209..00000000 --- a/.history/src/renderer/utils/musicSdk/kg/musicSearch_20230610021152.js +++ /dev/null @@ -1,108 +0,0 @@ -import { httpFetch } from '../../request' -import { decodeName, formatPlayTime, sizeFormate } from '../../index' -import { formatSingerName, formatSingerList } from '../utils' - -export default { - limit: 30, - total: 0, - page: 0, - allPage: 1, - musicSearch(str, page, limit) { - const searchRequest = httpFetch(`https://songsearch.kugou.com/song_search_v2?keyword=${encodeURIComponent(str)}&page=${page}&pagesize=${limit}&userid=0&clientver=&platform=WebFilter&filter=2&iscorrection=1&privilege_filter=0`) - return searchRequest.promise.then(({ body }) => body) - }, - filterData(rawData) { - const types = [] - const _types = {} - if (rawData.FileSize !== 0) { - let size = sizeFormate(rawData.FileSize) - types.push({ type: '128k', size, hash: rawData.FileHash }) - _types['128k'] = { - size, - hash: rawData.FileHash, - } - } - if (rawData.HQFileSize !== 0) { - let size = sizeFormate(rawData.HQFileSize) - types.push({ type: '320k', size, hash: rawData.HQFileHash }) - _types['320k'] = { - size, - hash: rawData.HQFileHash, - } - } - if (rawData.SQFileSize !== 0) { - let size = sizeFormate(rawData.SQFileSize) - types.push({ type: 'flac', size, hash: rawData.SQFileHash }) - _types.flac = { - size, - hash: rawData.SQFileHash, - } - } - if (rawData.ResFileSize !== 0) { - let size = sizeFormate(rawData.ResFileSize) - types.push({ type: 'flac24bit', size, hash: rawData.ResFileHash }) - _types.flac24bit = { - size, - hash: rawData.ResFileHash, - } - } - return { - singer: decodeName(formatSingerName(rawData.Singers, 'name')), - singerList: formatSingerList(rawData.Singers), - name: decodeName(rawData.SongName), - albumName: decodeName(rawData.AlbumName), - albumId: rawData.AlbumID, - songmid: rawData.Audioid, - source: 'kg', - interval: formatPlayTime(rawData.Duration), - _interval: rawData.Duration, - img: null, - lrc: null, - otherSource: null, - hash: rawData.FileHash, - types, - _types, - typeUrl: {}, - } - }, - handleResult(rawData) { - let ids = new Set() - const list = [] - rawData.forEach(item => { - const key = item.Audioid + item.FileHash - if (ids.has(key)) return - ids.add(key) - list.push(this.filterData(item)) - for (const childItem of item.Grp) { - const key = item.Audioid + item.FileHash - if (ids.has(key)) continue - ids.add(key) - list.push(this.filterData(childItem)) - } - }) - return list - }, - search(str, page = 1, limit, retryNum = 0) { - if (++retryNum > 3) return Promise.reject(new Error('try max num')) - if (limit == null) limit = this.limit - // http://newlyric.kuwo.cn/newlyric.lrc?62355680 - return this.musicSearch(str, page, limit).then(result => { - if (!result || result.error_code !== 0) return this.search(str, page, limit, retryNum) - let list = this.handleResult(result.data.lists) - - if (list == null) return this.search(str, page, limit, retryNum) - - this.total = result.data.total - this.page = page - this.allPage = Math.ceil(this.total / limit) - - return Promise.resolve({ - list, - allPage: this.allPage, - limit, - total: this.total, - source: 'kg', - }) - }) - }, -} diff --git a/.history/src/renderer/utils/musicSdk/kg/musicSearch_20230610021213.js b/.history/src/renderer/utils/musicSdk/kg/musicSearch_20230610021213.js deleted file mode 100644 index 23dfe8d7..00000000 --- a/.history/src/renderer/utils/musicSdk/kg/musicSearch_20230610021213.js +++ /dev/null @@ -1,108 +0,0 @@ -import { httpFetch } from '../../request' -import { decodeName, formatPlayTime, sizeFormate } from '../../index' -import { formatSingerName, formatSingerList } from '../utils' - -export default { - limit: 30, - total: 0, - page: 0, - allPage: 1, - musicSearch(str, page, limit) { - const searchRequest = httpFetch(`https://songsearch.kugou.com/song_search_v2?keyword=${encodeURIComponent(str)}&page=${page}&pagesize=${limit}&userid=0&clientver=&platform=WebFilter&filter=2&iscorrection=1&privilege_filter=0`) - return searchRequest.promise.then(({ body }) => body) - }, - filterData(rawData) { - const types = [] - const _types = {} - if (rawData.FileSize !== 0) { - let size = sizeFormate(rawData.FileSize) - types.push({ type: '128k', size, hash: rawData.FileHash }) - _types['128k'] = { - size, - hash: rawData.FileHash, - } - } - if (rawData.HQFileSize !== 0) { - let size = sizeFormate(rawData.HQFileSize) - types.push({ type: '320k', size, hash: rawData.HQFileHash }) - _types['320k'] = { - size, - hash: rawData.HQFileHash, - } - } - if (rawData.SQFileSize !== 0) { - let size = sizeFormate(rawData.SQFileSize) - types.push({ type: 'flac', size, hash: rawData.SQFileHash }) - _types.flac = { - size, - hash: rawData.SQFileHash, - } - } - if (rawData.ResFileSize !== 0) { - let size = sizeFormate(rawData.ResFileSize) - types.push({ type: 'flac24bit', size, hash: rawData.ResFileHash }) - _types.flac24bit = { - size, - hash: rawData.ResFileHash, - } - } - return { - singer: decodeName(formatSingerName(rawData.Singers, 'name')), - singerList: formatSingerList(rawData.Singers), - name: decodeName(rawData.SongName), - albumName: decodeName(rawData.AlbumName, 'name', 'id'), - albumId: rawData.AlbumID, - songmid: rawData.Audioid, - source: 'kg', - interval: formatPlayTime(rawData.Duration), - _interval: rawData.Duration, - img: null, - lrc: null, - otherSource: null, - hash: rawData.FileHash, - types, - _types, - typeUrl: {}, - } - }, - handleResult(rawData) { - let ids = new Set() - const list = [] - rawData.forEach(item => { - const key = item.Audioid + item.FileHash - if (ids.has(key)) return - ids.add(key) - list.push(this.filterData(item)) - for (const childItem of item.Grp) { - const key = item.Audioid + item.FileHash - if (ids.has(key)) continue - ids.add(key) - list.push(this.filterData(childItem)) - } - }) - return list - }, - search(str, page = 1, limit, retryNum = 0) { - if (++retryNum > 3) return Promise.reject(new Error('try max num')) - if (limit == null) limit = this.limit - // http://newlyric.kuwo.cn/newlyric.lrc?62355680 - return this.musicSearch(str, page, limit).then(result => { - if (!result || result.error_code !== 0) return this.search(str, page, limit, retryNum) - let list = this.handleResult(result.data.lists) - - if (list == null) return this.search(str, page, limit, retryNum) - - this.total = result.data.total - this.page = page - this.allPage = Math.ceil(this.total / limit) - - return Promise.resolve({ - list, - allPage: this.allPage, - limit, - total: this.total, - source: 'kg', - }) - }) - }, -} diff --git a/.history/src/renderer/utils/musicSdk/kg/musicSearch_20230610021218.js b/.history/src/renderer/utils/musicSdk/kg/musicSearch_20230610021218.js deleted file mode 100644 index ebc9e209..00000000 --- a/.history/src/renderer/utils/musicSdk/kg/musicSearch_20230610021218.js +++ /dev/null @@ -1,108 +0,0 @@ -import { httpFetch } from '../../request' -import { decodeName, formatPlayTime, sizeFormate } from '../../index' -import { formatSingerName, formatSingerList } from '../utils' - -export default { - limit: 30, - total: 0, - page: 0, - allPage: 1, - musicSearch(str, page, limit) { - const searchRequest = httpFetch(`https://songsearch.kugou.com/song_search_v2?keyword=${encodeURIComponent(str)}&page=${page}&pagesize=${limit}&userid=0&clientver=&platform=WebFilter&filter=2&iscorrection=1&privilege_filter=0`) - return searchRequest.promise.then(({ body }) => body) - }, - filterData(rawData) { - const types = [] - const _types = {} - if (rawData.FileSize !== 0) { - let size = sizeFormate(rawData.FileSize) - types.push({ type: '128k', size, hash: rawData.FileHash }) - _types['128k'] = { - size, - hash: rawData.FileHash, - } - } - if (rawData.HQFileSize !== 0) { - let size = sizeFormate(rawData.HQFileSize) - types.push({ type: '320k', size, hash: rawData.HQFileHash }) - _types['320k'] = { - size, - hash: rawData.HQFileHash, - } - } - if (rawData.SQFileSize !== 0) { - let size = sizeFormate(rawData.SQFileSize) - types.push({ type: 'flac', size, hash: rawData.SQFileHash }) - _types.flac = { - size, - hash: rawData.SQFileHash, - } - } - if (rawData.ResFileSize !== 0) { - let size = sizeFormate(rawData.ResFileSize) - types.push({ type: 'flac24bit', size, hash: rawData.ResFileHash }) - _types.flac24bit = { - size, - hash: rawData.ResFileHash, - } - } - return { - singer: decodeName(formatSingerName(rawData.Singers, 'name')), - singerList: formatSingerList(rawData.Singers), - name: decodeName(rawData.SongName), - albumName: decodeName(rawData.AlbumName), - albumId: rawData.AlbumID, - songmid: rawData.Audioid, - source: 'kg', - interval: formatPlayTime(rawData.Duration), - _interval: rawData.Duration, - img: null, - lrc: null, - otherSource: null, - hash: rawData.FileHash, - types, - _types, - typeUrl: {}, - } - }, - handleResult(rawData) { - let ids = new Set() - const list = [] - rawData.forEach(item => { - const key = item.Audioid + item.FileHash - if (ids.has(key)) return - ids.add(key) - list.push(this.filterData(item)) - for (const childItem of item.Grp) { - const key = item.Audioid + item.FileHash - if (ids.has(key)) continue - ids.add(key) - list.push(this.filterData(childItem)) - } - }) - return list - }, - search(str, page = 1, limit, retryNum = 0) { - if (++retryNum > 3) return Promise.reject(new Error('try max num')) - if (limit == null) limit = this.limit - // http://newlyric.kuwo.cn/newlyric.lrc?62355680 - return this.musicSearch(str, page, limit).then(result => { - if (!result || result.error_code !== 0) return this.search(str, page, limit, retryNum) - let list = this.handleResult(result.data.lists) - - if (list == null) return this.search(str, page, limit, retryNum) - - this.total = result.data.total - this.page = page - this.allPage = Math.ceil(this.total / limit) - - return Promise.resolve({ - list, - allPage: this.allPage, - limit, - total: this.total, - source: 'kg', - }) - }) - }, -} diff --git a/.history/src/renderer/utils/musicSdk/kg/util_20230610002212.js b/.history/src/renderer/utils/musicSdk/kg/util_20230610002212.js deleted file mode 100644 index 7ea15f58..00000000 --- a/.history/src/renderer/utils/musicSdk/kg/util_20230610002212.js +++ /dev/null @@ -1,77 +0,0 @@ -import { inflate } from 'zlib' -import { toMD5 } from '../utils' -import { httpFetch } from '../../request' - -// https://github.com/lyswhut/lx-music-desktop/issues/296#issuecomment-683285784 -const enc_key = Buffer.from([0x40, 0x47, 0x61, 0x77, 0x5e, 0x32, 0x74, 0x47, 0x51, 0x36, 0x31, 0x2d, 0xce, 0xd2, 0x6e, 0x69], 'binary') -export const decodeLyric = str => new Promise((resolve, reject) => { - if (!str.length) return - const buf_str = Buffer.from(str, 'base64').slice(4) - for (let i = 0, len = buf_str.length; i < len; i++) { - buf_str[i] = buf_str[i] ^ enc_key[i % 16] - } - inflate(buf_str, (err, result) => { - if (err) return reject(err) - resolve(result.toString()) - }) -}) - -// s.content[0].lyricContent.forEach(([str]) => { -// console.log(str) -// }) - -/** - * 签名 - * @param {*} params - * @param {*} apiver - */ -export const signatureParams = (params, apiver = 9) => { - let keyparam = 'OIlwieks28dk2k092lksi2UIkp' - if (apiver === 5) keyparam = 'NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt' - let param_list = params.split('&') - param_list.sort() - let sign_params = `${keyparam}${param_list.join('')}${keyparam}` - return toMD5(sign_params) -} - -/** - * 创建一个适用于KG的Http请求 - * @param {*} url - * @param {*} options - * @param {*} retryNum - */ -export const createHttpFetch = async(url, options, retryNum = 0) => { - if (retryNum > 2) throw new Error('try max num') - let result - try { - result = await httpFetch(url, options).promise - } catch (err) { - console.log(err) - return createHttpFetch(url, options, ++retryNum) - } - // console.log(result.statusCode, result.body) - if (result.statusCode !== 200 || - ( - result.body.error_code ?? - result.body.errcode ?? - result.body.err_code) != 0 - ) return createHttpFetch(url, options, ++retryNum) - if (result.body.data) return result.body.data - if (Array.isArray(result.body.info)) return result.body - return result.body.info -} - -/** - * 处理歌手列表 - * @param {Array} rawList - */ -export const formatSingerList = (rawList, keyID = 'id', keyName = 'name') => { - let returnList = [] - rawList.forEach((s) => { - returnList.push({ - name: s[keyName], - id: String(s[keyID]), - }) - }) - return returnList -} diff --git a/.history/src/renderer/utils/musicSdk/kg/util_20230610021326.js b/.history/src/renderer/utils/musicSdk/kg/util_20230610021326.js deleted file mode 100644 index 955bac98..00000000 --- a/.history/src/renderer/utils/musicSdk/kg/util_20230610021326.js +++ /dev/null @@ -1,62 +0,0 @@ -import { inflate } from 'zlib' -import { toMD5 } from '../utils' -import { httpFetch } from '../../request' - -// https://github.com/lyswhut/lx-music-desktop/issues/296#issuecomment-683285784 -const enc_key = Buffer.from([0x40, 0x47, 0x61, 0x77, 0x5e, 0x32, 0x74, 0x47, 0x51, 0x36, 0x31, 0x2d, 0xce, 0xd2, 0x6e, 0x69], 'binary') -export const decodeLyric = str => new Promise((resolve, reject) => { - if (!str.length) return - const buf_str = Buffer.from(str, 'base64').slice(4) - for (let i = 0, len = buf_str.length; i < len; i++) { - buf_str[i] = buf_str[i] ^ enc_key[i % 16] - } - inflate(buf_str, (err, result) => { - if (err) return reject(err) - resolve(result.toString()) - }) -}) - -// s.content[0].lyricContent.forEach(([str]) => { -// console.log(str) -// }) - -/** - * 签名 - * @param {*} params - * @param {*} apiver - */ -export const signatureParams = (params, apiver = 9) => { - let keyparam = 'OIlwieks28dk2k092lksi2UIkp' - if (apiver === 5) keyparam = 'NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt' - let param_list = params.split('&') - param_list.sort() - let sign_params = `${keyparam}${param_list.join('')}${keyparam}` - return toMD5(sign_params) -} - -/** - * 创建一个适用于KG的Http请求 - * @param {*} url - * @param {*} options - * @param {*} retryNum - */ -export const createHttpFetch = async(url, options, retryNum = 0) => { - if (retryNum > 2) throw new Error('try max num') - let result - try { - result = await httpFetch(url, options).promise - } catch (err) { - console.log(err) - return createHttpFetch(url, options, ++retryNum) - } - // console.log(result.statusCode, result.body) - if (result.statusCode !== 200 || - ( - result.body.error_code ?? - result.body.errcode ?? - result.body.err_code) != 0 - ) return createHttpFetch(url, options, ++retryNum) - if (result.body.data) return result.body.data - if (Array.isArray(result.body.info)) return result.body - return result.body.info -} diff --git a/.history/src/renderer/utils/musicSdk/utils_20230610020526.js b/.history/src/renderer/utils/musicSdk/utils_20230610020526.js deleted file mode 100644 index d91252f3..00000000 --- a/.history/src/renderer/utils/musicSdk/utils_20230610020526.js +++ /dev/null @@ -1,66 +0,0 @@ -import crypto from 'crypto' -import dns from 'dns' -import { decodeName } from '@common/utils/common' - -export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex') - - -const ipMap = new Map() -export const getHostIp = hostname => { - const result = ipMap.get(hostname) - if (typeof result === 'object') return result - if (result === true) return - ipMap.set(hostname, true) - // console.log(hostname) - dns.lookup(hostname, { - // family: 4, - all: false, - }, (err, address, family) => { - if (err) return console.log(err) - // console.log(address, family) - ipMap.set(hostname, { address, family }) - }) -} - -export const dnsLookup = (hostname, options, callback) => { - const result = getHostIp(hostname) - if (result) return callback(null, result.address, result.family) - - dns.lookup(hostname, options, callback) -} - - -/** - * 格式化歌手 - * @param singers 歌手数组 - * @param nameKey 歌手名键值 - * @param join 歌手分割字符 - */ -export const formatSingerName = (singers, nameKey = 'name', join = '、') => { - if (Array.isArray(singers)) { - const singer = [] - singers.forEach(item => { - let name = item[nameKey] - if (!name) return - singer.push(name) - }) - return decodeName(singer.join(join)) - } - return decodeName(String(singers ?? '')) -} - -/** - * 处理歌手列表 - * @param singers 歌手数组 - */ -export const formatSingerList = (singers, nameKey = 'name', idKey = 'id', midKey = 'mid') => { - const list = [] - singers.forEach((s) => { - list.push({ - name: s[nameKey], - id: s[idKey], - mid: s[midKey], - }) - }) - return list -} diff --git a/.history/src/renderer/utils/musicSdk/utils_20230610021030.js b/.history/src/renderer/utils/musicSdk/utils_20230610021030.js deleted file mode 100644 index 79365df3..00000000 --- a/.history/src/renderer/utils/musicSdk/utils_20230610021030.js +++ /dev/null @@ -1,66 +0,0 @@ -import crypto from 'crypto' -import dns from 'dns' -import { decodeName } from '@common/utils/common' - -export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex') - - -const ipMap = new Map() -export const getHostIp = hostname => { - const result = ipMap.get(hostname) - if (typeof result === 'object') return result - if (result === true) return - ipMap.set(hostname, true) - // console.log(hostname) - dns.lookup(hostname, { - // family: 4, - all: false, - }, (err, address, family) => { - if (err) return console.log(err) - // console.log(address, family) - ipMap.set(hostname, { address, family }) - }) -} - -export const dnsLookup = (hostname, options, callback) => { - const result = getHostIp(hostname) - if (result) return callback(null, result.address, result.family) - - dns.lookup(hostname, options, callback) -} - - -/** - * 格式化歌手 - * @param singers 歌手数组 - * @param nameKey 歌手名键值 - * @param join 歌手分割字符 - */ -export const formatSingerName = (singers, nameKey = 'name', join = '、') => { - if (Array.isArray(singers)) { - const singer = [] - singers.forEach(item => { - let name = item[nameKey] - if (!name) return - singer.push(name) - }) - return decodeName(singer.join(join)) - } - return decodeName(String(singers ?? '')) -} - -/** - * 处理歌手列表 - * @param singers 歌手数组 - */ -export const formatSingerList = (singers, nameKey = 'name', idKey = 'id', midKey = 'mid') => { - const list = [] - singers.forEach((s) => { - list.push({ - name: s[nameKey], - id: s[idKey], - mid: s[midKey] ?? null, - }) - }) - return list -} diff --git a/.history/src/renderer/utils/musicSdk/utils_20230610021122.js b/.history/src/renderer/utils/musicSdk/utils_20230610021122.js deleted file mode 100644 index 79365df3..00000000 --- a/.history/src/renderer/utils/musicSdk/utils_20230610021122.js +++ /dev/null @@ -1,66 +0,0 @@ -import crypto from 'crypto' -import dns from 'dns' -import { decodeName } from '@common/utils/common' - -export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex') - - -const ipMap = new Map() -export const getHostIp = hostname => { - const result = ipMap.get(hostname) - if (typeof result === 'object') return result - if (result === true) return - ipMap.set(hostname, true) - // console.log(hostname) - dns.lookup(hostname, { - // family: 4, - all: false, - }, (err, address, family) => { - if (err) return console.log(err) - // console.log(address, family) - ipMap.set(hostname, { address, family }) - }) -} - -export const dnsLookup = (hostname, options, callback) => { - const result = getHostIp(hostname) - if (result) return callback(null, result.address, result.family) - - dns.lookup(hostname, options, callback) -} - - -/** - * 格式化歌手 - * @param singers 歌手数组 - * @param nameKey 歌手名键值 - * @param join 歌手分割字符 - */ -export const formatSingerName = (singers, nameKey = 'name', join = '、') => { - if (Array.isArray(singers)) { - const singer = [] - singers.forEach(item => { - let name = item[nameKey] - if (!name) return - singer.push(name) - }) - return decodeName(singer.join(join)) - } - return decodeName(String(singers ?? '')) -} - -/** - * 处理歌手列表 - * @param singers 歌手数组 - */ -export const formatSingerList = (singers, nameKey = 'name', idKey = 'id', midKey = 'mid') => { - const list = [] - singers.forEach((s) => { - list.push({ - name: s[nameKey], - id: s[idKey], - mid: s[midKey] ?? null, - }) - }) - return list -} diff --git a/.history/src/renderer/utils/musicSdk/utils_20230610021630.js b/.history/src/renderer/utils/musicSdk/utils_20230610021630.js deleted file mode 100644 index 23b09350..00000000 --- a/.history/src/renderer/utils/musicSdk/utils_20230610021630.js +++ /dev/null @@ -1,68 +0,0 @@ -import crypto from 'crypto' -import dns from 'dns' -import { decodeName } from '@common/utils/common' - -export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex') - - -const ipMap = new Map() -export const getHostIp = hostname => { - const result = ipMap.get(hostname) - if (typeof result === 'object') return result - if (result === true) return - ipMap.set(hostname, true) - // console.log(hostname) - dns.lookup(hostname, { - // family: 4, - all: false, - }, (err, address, family) => { - if (err) return console.log(err) - // console.log(address, family) - ipMap.set(hostname, { address, family }) - }) -} - -export const dnsLookup = (hostname, options, callback) => { - const result = getHostIp(hostname) - if (result) return callback(null, result.address, result.family) - - dns.lookup(hostname, options, callback) -} - - -/** - * 格式化歌手 - * @param singers 歌手数组 - * @param nameKey 歌手名键值 - * @param join 歌手分割字符 - */ -export const formatSingerName = (singers, nameKey = 'name', join = '、') => { - if (Array.isArray(singers)) { - const singer = [] - singers.forEach(item => { - let name = item[nameKey] - if (!name) return - singer.push(name) - }) - return decodeName(singer.join(join)) - } - return decodeName(String(singers ?? '')) -} - -/** - * 处理歌手列表 - * @param singers 歌手数组 - */ -export const formatSingerList = (singers, nameKey = 'name', idKey = 'id', midKey = 'mid') => { - const list = [] - singers.forEach((s) => { - let info = {} - if (name) info.name = name - list.push({ - name: s[nameKey], - id: s[idKey], - mid: s[midKey] ?? null, - }) - }) - return list -} diff --git a/.history/src/renderer/utils/musicSdk/utils_20230610021642.js b/.history/src/renderer/utils/musicSdk/utils_20230610021642.js deleted file mode 100644 index 8519c8bf..00000000 --- a/.history/src/renderer/utils/musicSdk/utils_20230610021642.js +++ /dev/null @@ -1,70 +0,0 @@ -import crypto from 'crypto' -import dns from 'dns' -import { decodeName } from '@common/utils/common' - -export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex') - - -const ipMap = new Map() -export const getHostIp = hostname => { - const result = ipMap.get(hostname) - if (typeof result === 'object') return result - if (result === true) return - ipMap.set(hostname, true) - // console.log(hostname) - dns.lookup(hostname, { - // family: 4, - all: false, - }, (err, address, family) => { - if (err) return console.log(err) - // console.log(address, family) - ipMap.set(hostname, { address, family }) - }) -} - -export const dnsLookup = (hostname, options, callback) => { - const result = getHostIp(hostname) - if (result) return callback(null, result.address, result.family) - - dns.lookup(hostname, options, callback) -} - - -/** - * 格式化歌手 - * @param singers 歌手数组 - * @param nameKey 歌手名键值 - * @param join 歌手分割字符 - */ -export const formatSingerName = (singers, nameKey = 'name', join = '、') => { - if (Array.isArray(singers)) { - const singer = [] - singers.forEach(item => { - let name = item[nameKey] - if (!name) return - singer.push(name) - }) - return decodeName(singer.join(join)) - } - return decodeName(String(singers ?? '')) -} - -/** - * 处理歌手列表 - * @param singers 歌手数组 - */ -export const formatSingerList = (singers, nameKey = 'name', idKey = 'id', midKey = 'mid') => { - const list = [] - singers.forEach((s) => { - const name = s[nameKey], - - let info = {} - if (name) info.name = name - list.push({ - - id: s[idKey], - mid: s[midKey] ?? null, - }) - }) - return list -} diff --git a/.history/src/renderer/utils/musicSdk/utils_20230610021705.js b/.history/src/renderer/utils/musicSdk/utils_20230610021705.js deleted file mode 100644 index 967c1b7a..00000000 --- a/.history/src/renderer/utils/musicSdk/utils_20230610021705.js +++ /dev/null @@ -1,72 +0,0 @@ -import crypto from 'crypto' -import dns from 'dns' -import { decodeName } from '@common/utils/common' - -export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex') - - -const ipMap = new Map() -export const getHostIp = hostname => { - const result = ipMap.get(hostname) - if (typeof result === 'object') return result - if (result === true) return - ipMap.set(hostname, true) - // console.log(hostname) - dns.lookup(hostname, { - // family: 4, - all: false, - }, (err, address, family) => { - if (err) return console.log(err) - // console.log(address, family) - ipMap.set(hostname, { address, family }) - }) -} - -export const dnsLookup = (hostname, options, callback) => { - const result = getHostIp(hostname) - if (result) return callback(null, result.address, result.family) - - dns.lookup(hostname, options, callback) -} - - -/** - * 格式化歌手 - * @param singers 歌手数组 - * @param nameKey 歌手名键值 - * @param join 歌手分割字符 - */ -export const formatSingerName = (singers, nameKey = 'name', join = '、') => { - if (Array.isArray(singers)) { - const singer = [] - singers.forEach(item => { - let name = item[nameKey] - if (!name) return - singer.push(name) - }) - return decodeName(singer.join(join)) - } - return decodeName(String(singers ?? '')) -} - -/** - * 处理歌手列表 - * @param singers 歌手数组 - */ -export const formatSingerList = (singers, nameKey = 'name', idKey = 'id', midKey = 'mid') => { - const list = [] - singers.forEach((s) => { - const name = s[nameKey] - const id = s[idKey] - const mid = s[midKey] - - let info = {} - if (name) info.name = name - list.push({ - - id: s[idKey], - mid: s[midKey] ?? null, - }) - }) - return list -} diff --git a/.history/src/renderer/utils/musicSdk/utils_20230610021808.js b/.history/src/renderer/utils/musicSdk/utils_20230610021808.js deleted file mode 100644 index a5cc6b9d..00000000 --- a/.history/src/renderer/utils/musicSdk/utils_20230610021808.js +++ /dev/null @@ -1,71 +0,0 @@ -import crypto from 'crypto' -import dns from 'dns' -import { decodeName } from '@common/utils/common' - -export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex') - - -const ipMap = new Map() -export const getHostIp = hostname => { - const result = ipMap.get(hostname) - if (typeof result === 'object') return result - if (result === true) return - ipMap.set(hostname, true) - // console.log(hostname) - dns.lookup(hostname, { - // family: 4, - all: false, - }, (err, address, family) => { - if (err) return console.log(err) - // console.log(address, family) - ipMap.set(hostname, { address, family }) - }) -} - -export const dnsLookup = (hostname, options, callback) => { - const result = getHostIp(hostname) - if (result) return callback(null, result.address, result.family) - - dns.lookup(hostname, options, callback) -} - - -/** - * 格式化歌手 - * @param singers 歌手数组 - * @param nameKey 歌手名键值 - * @param join 歌手分割字符 - */ -export const formatSingerName = (singers, nameKey = 'name', join = '、') => { - if (Array.isArray(singers)) { - const singer = [] - singers.forEach(item => { - let name = item[nameKey] - if (!name) return - singer.push(name) - }) - return decodeName(singer.join(join)) - } - return decodeName(String(singers ?? '')) -} - -/** - * 处理歌手列表 - * @param singers 歌手数组 - */ -export const formatSingerList = (singers, nameKey = 'name', idKey = 'id', midKey = 'mid') => { - const list = [] - singers.forEach((s) => { - const name = s[nameKey] - const id = s[idKey] - const mid = s[midKey] - - const info = {} - if (name) info.name = name - if (id) info.id = id - if (mid) info.mid = mid - - list.push(info) - }) - return list -} diff --git a/.history/src/renderer/utils/musicSdk/utils_20230610021832.js b/.history/src/renderer/utils/musicSdk/utils_20230610021832.js deleted file mode 100644 index 65738de2..00000000 --- a/.history/src/renderer/utils/musicSdk/utils_20230610021832.js +++ /dev/null @@ -1,72 +0,0 @@ -import crypto from 'crypto' -import dns from 'dns' -import { decodeName } from '@common/utils/common' - -export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex') - - -const ipMap = new Map() -export const getHostIp = hostname => { - const result = ipMap.get(hostname) - if (typeof result === 'object') return result - if (result === true) return - ipMap.set(hostname, true) - // console.log(hostname) - dns.lookup(hostname, { - // family: 4, - all: false, - }, (err, address, family) => { - if (err) return console.log(err) - // console.log(address, family) - ipMap.set(hostname, { address, family }) - }) -} - -export const dnsLookup = (hostname, options, callback) => { - const result = getHostIp(hostname) - if (result) return callback(null, result.address, result.family) - - dns.lookup(hostname, options, callback) -} - - -/** - * 格式化歌手 - * @param singers 歌手数组 - * @param nameKey 歌手名键值 - * @param join 歌手分割字符 - */ -export const formatSingerName = (singers, nameKey = 'name', join = '、') => { - if (Array.isArray(singers)) { - const singer = [] - singers.forEach(item => { - let name = item[nameKey] - if (!name) return - singer.push(name) - }) - return decodeName(singer.join(join)) - } - return decodeName(String(singers ?? '')) -} - - -/** - * 处理歌手列表 - * @param singers 歌手数组 - */ -export const formatSingerList = (singers, nameKey = 'name', idKey = 'id', midKey = 'mid') => { - const list = [] - singers.forEach((s) => { - const name = s[nameKey] - const id = s[idKey] - const mid = s[midKey] - - const info = {} - if (name) info.name = name - if (id) info.id = id - if (mid) info.mid = mid - - list.push(info) - }) - return list -} diff --git a/.history/src/renderer/utils/musicSdk/utils_20230610021834.js b/.history/src/renderer/utils/musicSdk/utils_20230610021834.js deleted file mode 100644 index a5cc6b9d..00000000 --- a/.history/src/renderer/utils/musicSdk/utils_20230610021834.js +++ /dev/null @@ -1,71 +0,0 @@ -import crypto from 'crypto' -import dns from 'dns' -import { decodeName } from '@common/utils/common' - -export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex') - - -const ipMap = new Map() -export const getHostIp = hostname => { - const result = ipMap.get(hostname) - if (typeof result === 'object') return result - if (result === true) return - ipMap.set(hostname, true) - // console.log(hostname) - dns.lookup(hostname, { - // family: 4, - all: false, - }, (err, address, family) => { - if (err) return console.log(err) - // console.log(address, family) - ipMap.set(hostname, { address, family }) - }) -} - -export const dnsLookup = (hostname, options, callback) => { - const result = getHostIp(hostname) - if (result) return callback(null, result.address, result.family) - - dns.lookup(hostname, options, callback) -} - - -/** - * 格式化歌手 - * @param singers 歌手数组 - * @param nameKey 歌手名键值 - * @param join 歌手分割字符 - */ -export const formatSingerName = (singers, nameKey = 'name', join = '、') => { - if (Array.isArray(singers)) { - const singer = [] - singers.forEach(item => { - let name = item[nameKey] - if (!name) return - singer.push(name) - }) - return decodeName(singer.join(join)) - } - return decodeName(String(singers ?? '')) -} - -/** - * 处理歌手列表 - * @param singers 歌手数组 - */ -export const formatSingerList = (singers, nameKey = 'name', idKey = 'id', midKey = 'mid') => { - const list = [] - singers.forEach((s) => { - const name = s[nameKey] - const id = s[idKey] - const mid = s[midKey] - - const info = {} - if (name) info.name = name - if (id) info.id = id - if (mid) info.mid = mid - - list.push(info) - }) - return list -}