更新API
This commit is contained in:
parent
200ca1eeda
commit
784964d1cb
@ -5,6 +5,17 @@ export * from '@common/utils/nodejs'
|
|||||||
export * from '@common/utils/common'
|
export * from '@common/utils/common'
|
||||||
export * from '@common/utils/tools'
|
export * from '@common/utils/tools'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化播放数量
|
||||||
|
* @param {*} num 数字
|
||||||
|
*/
|
||||||
|
export const formatPlayCount = (num: number): { count: number, lang: string } => {
|
||||||
|
if (num > 100000000) return {count: parseInt((num / 10000000).toString()) / 10, lang: 'play_count_billion'}
|
||||||
|
if (num > 10000) return {count: parseInt((num / 1000).toString()) / 10, lang: 'play_count_million'}
|
||||||
|
return { count: num, lang: 'play_count_none' }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 时间格式化
|
* 时间格式化
|
||||||
*/
|
*/
|
||||||
|
|||||||
63
src/renderer/utils/musicSdk/kg/album.js
Normal file
63
src/renderer/utils/musicSdk/kg/album.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import { getMusicInfosByList } from './musicInfo'
|
||||||
|
import { createHttpFetch } from './util'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
/**
|
||||||
|
* 通过AlbumId获取专辑信息
|
||||||
|
* @param {*} id
|
||||||
|
*/
|
||||||
|
async getAlbumInfo(id) {
|
||||||
|
const albumInfoRequest = await createHttpFetch('http://kmrserviceretry.kugou.com/container/v1/album?dfid=1tT5He3kxrNC4D29ad1MMb6F&mid=22945702112173152889429073101964063697&userid=0&appid=1005&clientver=11589', {
|
||||||
|
method: 'POST',
|
||||||
|
body: {
|
||||||
|
appid: 1005,
|
||||||
|
clienttime: 1681833686,
|
||||||
|
clientver: 11589,
|
||||||
|
data: [{ album_id: id }],
|
||||||
|
fields: 'language,grade_count,intro,mix_intro,heat,category,sizable_cover,cover,album_name,type,quality,publish_company,grade,special_tag,author_name,publish_date,language_id,album_id,exclusive,is_publish,trans_param,authors,album_tag',
|
||||||
|
isBuy: 0,
|
||||||
|
key: 'e6f3306ff7e2afb494e89fbbda0becbf',
|
||||||
|
mid: '22945702112173152889429073101964063697',
|
||||||
|
show_album_tag: 0,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (!albumInfoRequest) return Promise.reject(new Error('get album info failed.'))
|
||||||
|
const albumInfo = albumInfoRequest[0]
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: albumInfo.album_name,
|
||||||
|
image: albumInfo.sizable_cover.replace('{size}', 240),
|
||||||
|
desc: albumInfo.intro,
|
||||||
|
authorName: albumInfo.author_name,
|
||||||
|
// play_count: this.formatPlayCount(info.count),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 通过AlbumId获取专辑
|
||||||
|
* @param {*} id
|
||||||
|
* @param {*} page
|
||||||
|
*/
|
||||||
|
async getAlbumDetail(id, page = 1, limit = 200) {
|
||||||
|
const info = await this.getAlbumInfo(id)
|
||||||
|
|
||||||
|
const albumList = await createHttpFetch(`http://mobiles.kugou.com/api/v3/album/song?version=9108&albumid=${id}&plat=0&pagesize=${limit}&area_code=0&page=${page}&with_res_tag=0`)
|
||||||
|
if (!albumList.info) return Promise.reject(new Error('Get album list failed.'))
|
||||||
|
|
||||||
|
let result = await getMusicInfosByList(albumList.info)
|
||||||
|
|
||||||
|
return {
|
||||||
|
list: result || [],
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
total: albumList.total,
|
||||||
|
source: 'kg',
|
||||||
|
info: {
|
||||||
|
name: info.name,
|
||||||
|
img: info.image,
|
||||||
|
desc: info.desc,
|
||||||
|
author: info.authorName,
|
||||||
|
// play_count: this.formatPlayCount(info.count),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
@ -6,8 +6,10 @@ import pic from './pic'
|
|||||||
import lyric from './lyric'
|
import lyric from './lyric'
|
||||||
import hotSearch from './hotSearch'
|
import hotSearch from './hotSearch'
|
||||||
import comment from './comment'
|
import comment from './comment'
|
||||||
|
import tipSearch from './tipSearch'
|
||||||
|
|
||||||
const kg = {
|
const kg = {
|
||||||
|
tipSearch,
|
||||||
leaderboard,
|
leaderboard,
|
||||||
songList,
|
songList,
|
||||||
musicSearch,
|
musicSearch,
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import { decodeName, formatPlayTime, sizeFormate } from '../../index'
|
import { decodeName, formatPlayTime, sizeFormate } from '../../index'
|
||||||
|
import { formatSingerName } 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' }]
|
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' }]
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ export default {
|
|||||||
list: [
|
list: [
|
||||||
{
|
{
|
||||||
id: 'kgtop500',
|
id: 'kgtop500',
|
||||||
name: '酷狗TOP500',
|
name: 'TOP500',
|
||||||
bangid: '8888',
|
bangid: '8888',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -126,7 +127,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
singer: decodeName(this.getSinger(item.authors)),
|
singer: formatSingerName(item.authors, 'author_name'),
|
||||||
name: decodeName(item.songname),
|
name: decodeName(item.songname),
|
||||||
albumName: decodeName(item.remark),
|
albumName: decodeName(item.remark),
|
||||||
albumId: item.album_id,
|
albumId: item.album_id,
|
||||||
|
|||||||
104
src/renderer/utils/musicSdk/kg/musicInfo.js
Normal file
104
src/renderer/utils/musicSdk/kg/musicInfo.js
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
import { decodeName, formatPlayTime, sizeFormate } from '../../index'
|
||||||
|
import { createHttpFetch } from './util'
|
||||||
|
|
||||||
|
const createGetMusicInfosTask = (hashs) => {
|
||||||
|
let data = {
|
||||||
|
appid: 1001,
|
||||||
|
clienttime: 639437935,
|
||||||
|
clientver: 9020,
|
||||||
|
fields: 'album_info,author_name,audio_info,ori_audio_name',
|
||||||
|
is_publish: '1',
|
||||||
|
key: '0475af1457cd3363c7b45b871e94428a',
|
||||||
|
mid: '21511157a05844bd085308bc76ef3342',
|
||||||
|
show_privilege: 1,
|
||||||
|
}
|
||||||
|
let list = hashs
|
||||||
|
let tasks = []
|
||||||
|
while (list.length) {
|
||||||
|
tasks.push(Object.assign({ data: list.slice(0, 100) }, data))
|
||||||
|
if (list.length < 100) break
|
||||||
|
list = list.slice(100)
|
||||||
|
}
|
||||||
|
let url = 'http://kmr.service.kugou.com/v2/album_audio/audio'
|
||||||
|
return tasks.map(task => createHttpFetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
body: task,
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
|
||||||
|
},
|
||||||
|
}).then(data => data.map(s => s[0])))
|
||||||
|
}
|
||||||
|
|
||||||
|
export const filterMusicInfoList = (rawList) => {
|
||||||
|
// console.log(rawList)
|
||||||
|
let ids = new Set()
|
||||||
|
let list = []
|
||||||
|
rawList.forEach(item => {
|
||||||
|
if (!item) return
|
||||||
|
if (ids.has(item.audio_info.audio_id)) return
|
||||||
|
ids.add(item.audio_info.audio_id)
|
||||||
|
const types = []
|
||||||
|
const _types = {}
|
||||||
|
if (item.audio_info.filesize !== '0') {
|
||||||
|
let size = sizeFormate(parseInt(item.audio_info.filesize))
|
||||||
|
types.push({ type: '128k', size, hash: item.audio_info.hash })
|
||||||
|
_types['128k'] = {
|
||||||
|
size,
|
||||||
|
hash: item.audio_info.hash,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.audio_info.filesize_320 !== '0') {
|
||||||
|
let size = sizeFormate(parseInt(item.audio_info.filesize_320))
|
||||||
|
types.push({ type: '320k', size, hash: item.audio_info.hash_320 })
|
||||||
|
_types['320k'] = {
|
||||||
|
size,
|
||||||
|
hash: item.audio_info.hash_320,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.audio_info.filesize_flac !== '0') {
|
||||||
|
let size = sizeFormate(parseInt(item.audio_info.filesize_flac))
|
||||||
|
types.push({ type: 'flac', size, hash: item.audio_info.hash_flac })
|
||||||
|
_types.flac = {
|
||||||
|
size,
|
||||||
|
hash: item.audio_info.hash_flac,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.audio_info.filesize_high !== '0') {
|
||||||
|
let size = sizeFormate(parseInt(item.audio_info.filesize_high))
|
||||||
|
types.push({ type: 'flac24bit', size, hash: item.audio_info.hash_high })
|
||||||
|
_types.flac24bit = {
|
||||||
|
size,
|
||||||
|
hash: item.audio_info.hash_high,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.push({
|
||||||
|
singer: decodeName(item.author_name),
|
||||||
|
name: decodeName(item.ori_audio_name),
|
||||||
|
albumName: decodeName(item.album_info.album_name),
|
||||||
|
albumId: item.album_info.album_id,
|
||||||
|
songmid: item.audio_info.audio_id,
|
||||||
|
source: 'kg',
|
||||||
|
interval: formatPlayTime(parseInt(item.audio_info.timelength) / 1000),
|
||||||
|
img: null,
|
||||||
|
lrc: null,
|
||||||
|
hash: item.audio_info.hash,
|
||||||
|
otherSource: null,
|
||||||
|
types,
|
||||||
|
_types,
|
||||||
|
typeUrl: {},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getMusicInfos = async(hashs) => {
|
||||||
|
return filterMusicInfoList(await Promise.all(createGetMusicInfosTask(hashs)).then(data => data.flat()))
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getMusicInfo = async(hash) => {
|
||||||
|
return getMusicInfos([hash]).then(data => data[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getMusicInfosByList = (list) => {
|
||||||
|
return getMusicInfos(list.map(item => ({ hash: item.hash })))
|
||||||
|
}
|
||||||
@ -1,9 +1,5 @@
|
|||||||
// import '../../polyfill/array.find'
|
|
||||||
|
|
||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import { decodeName, formatPlayTime, sizeFormate } from '../../index'
|
import { decodeName, formatPlayTime, sizeFormate } from '../../index'
|
||||||
// import { debug } from '../../utils/env'
|
|
||||||
// import { formatSinger } from './util'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
limit: 30,
|
limit: 30,
|
||||||
@ -14,76 +10,80 @@ export default {
|
|||||||
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`)
|
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)
|
return searchRequest.promise.then(({ body }) => body)
|
||||||
},
|
},
|
||||||
filterData(rawData) {
|
filterList(raw) {
|
||||||
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(rawData.SingerName),
|
|
||||||
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()
|
let ids = new Set()
|
||||||
const list = []
|
const list = []
|
||||||
rawData.forEach(item => {
|
|
||||||
const key = item.Audioid + item.FileHash
|
raw.forEach(item => {
|
||||||
if (ids.has(key)) return
|
if (ids.has(item.Audioid) || !item.Audioid) return
|
||||||
ids.add(key)
|
ids.add(item.Audioid)
|
||||||
list.push(this.filterData(item))
|
|
||||||
for (const childItem of item.Grp) {
|
const types = []
|
||||||
const key = item.Audioid + item.FileHash
|
const _types = {}
|
||||||
if (ids.has(key)) continue
|
if (item.FileSize !== 0) {
|
||||||
ids.add(key)
|
let size = sizeFormate(item.FileSize)
|
||||||
list.push(this.filterData(childItem))
|
types.push({ type: '128k', size, hash: item.FileHash })
|
||||||
|
_types['128k'] = {
|
||||||
|
size,
|
||||||
|
hash: item.FileHash,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (item.HQFileSize !== 0) {
|
||||||
|
let size = sizeFormate(item.HQFileSize)
|
||||||
|
types.push({ type: '320k', size, hash: item.HQFileHash })
|
||||||
|
_types['320k'] = {
|
||||||
|
size,
|
||||||
|
hash: item.HQFileHash,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.SQFileSize !== 0) {
|
||||||
|
let size = sizeFormate(item.SQFileSize)
|
||||||
|
types.push({ type: 'flac', size, hash: item.SQFileHash })
|
||||||
|
_types.flac = {
|
||||||
|
size,
|
||||||
|
hash: item.SQFileHash,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.ResFileSize !== 0) {
|
||||||
|
let size = sizeFormate(item.ResFileSize)
|
||||||
|
types.push({ type: 'flac24bit', size, hash: item.ResFileHash })
|
||||||
|
_types.flac24bit = {
|
||||||
|
size,
|
||||||
|
hash: item.ResFileHash,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.push({
|
||||||
|
singer: decodeName(item.SingerName),
|
||||||
|
name: decodeName(item.SongName),
|
||||||
|
albumName: decodeName(item.AlbumName),
|
||||||
|
albumId: item.AlbumID,
|
||||||
|
songmid: item.Audioid,
|
||||||
|
source: 'kg',
|
||||||
|
interval: formatPlayTime(item.Duration),
|
||||||
|
_interval: item.Duration,
|
||||||
|
img: null,
|
||||||
|
lrc: null,
|
||||||
|
otherSource: null,
|
||||||
|
hash: item.FileHash,
|
||||||
|
types,
|
||||||
|
_types,
|
||||||
|
typeUrl: {},
|
||||||
|
})
|
||||||
})
|
})
|
||||||
return list
|
return list
|
||||||
},
|
},
|
||||||
|
handleResult(raw) {
|
||||||
|
const handleList = []
|
||||||
|
|
||||||
|
raw.forEach(item => {
|
||||||
|
handleList.push(item)
|
||||||
|
if (item.Grp.length === 0) return
|
||||||
|
for (const e in item.Grp) {
|
||||||
|
handleList.push(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return this.filterList(handleList)
|
||||||
|
},
|
||||||
search(str, page = 1, limit, retryNum = 0) {
|
search(str, page = 1, limit, retryNum = 0) {
|
||||||
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
|
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
|
||||||
if (limit == null) limit = this.limit
|
if (limit == null) limit = this.limit
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
111
src/renderer/utils/musicSdk/kg/temp/musicSearch-new.js
Normal file
111
src/renderer/utils/musicSdk/kg/temp/musicSearch-new.js
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
import { decodeName, formatPlayTime, sizeFormate } from '../../index'
|
||||||
|
import { signatureParams, createHttpFetch } from './util'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
limit: 30,
|
||||||
|
total: 0,
|
||||||
|
page: 0,
|
||||||
|
allPage: 1,
|
||||||
|
musicSearch(str, page, limit) {
|
||||||
|
const sign = signatureParams(`userid=0&area_code=1&appid=1005&dopicfull=1&page=${page}&token=0&privilegefilter=0&requestid=0&pagesize=${limit}&user_labels=&clienttime=0&sec_aggre=1&iscorrection=1&uuid=0&mid=0&keyword=${str}&dfid=-&clientver=11409&platform=AndroidFilter&tag=`, 3)
|
||||||
|
return createHttpFetch(`https://gateway.kugou.com/complexsearch/v3/search/song?userid=0&area_code=1&appid=1005&dopicfull=1&page=${page}&token=0&privilegefilter=0&requestid=0&pagesize=${limit}&user_labels=&clienttime=0&sec_aggre=1&iscorrection=1&uuid=0&mid=0&dfid=-&clientver=11409&platform=AndroidFilter&tag=&keyword=${encodeURIComponent(str)}&signature=${sign}`, {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
|
||||||
|
referer: 'https://kugou.com',
|
||||||
|
},
|
||||||
|
}).then(body => body)
|
||||||
|
},
|
||||||
|
filterList(raw) {
|
||||||
|
let ids = new Set()
|
||||||
|
const list = []
|
||||||
|
|
||||||
|
raw.forEach(item => {
|
||||||
|
if (ids.has(item.Audioid)) return
|
||||||
|
ids.add(item.Audioid)
|
||||||
|
|
||||||
|
const types = []
|
||||||
|
const _types = {}
|
||||||
|
if (item.FileSize !== 0) {
|
||||||
|
let size = sizeFormate(item.FileSize)
|
||||||
|
types.push({ type: '128k', size, hash: item.FileHash })
|
||||||
|
_types['128k'] = {
|
||||||
|
size,
|
||||||
|
hash: item.FileHash,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.HQ != undefined) {
|
||||||
|
let size = sizeFormate(item.HQ.FileSize)
|
||||||
|
types.push({ type: '320k', size, hash: item.HQ.Hash })
|
||||||
|
_types['320k'] = {
|
||||||
|
size,
|
||||||
|
hash: item.HQ.Hash,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.SQ != undefined) {
|
||||||
|
let size = sizeFormate(item.SQ.FileSize)
|
||||||
|
types.push({ type: 'flac', size, hash: item.SQ.Hash })
|
||||||
|
_types.flac = {
|
||||||
|
size,
|
||||||
|
hash: item.SQ.Hash,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.Res != undefined) {
|
||||||
|
let size = sizeFormate(item.Res.FileSize)
|
||||||
|
types.push({ type: 'flac24bit', size, hash: item.Res.Hash })
|
||||||
|
_types.flac24bit = {
|
||||||
|
size,
|
||||||
|
hash: item.Res.Hash,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.push({
|
||||||
|
singer: decodeName(item.SingerName),
|
||||||
|
name: decodeName(item.OriSongName),
|
||||||
|
albumName: decodeName(item.AlbumName),
|
||||||
|
albumId: item.AlbumID,
|
||||||
|
songmid: item.Audioid,
|
||||||
|
source: 'kg',
|
||||||
|
interval: formatPlayTime(item.Duration),
|
||||||
|
_interval: item.Duration,
|
||||||
|
img: null,
|
||||||
|
lrc: null,
|
||||||
|
otherSource: null,
|
||||||
|
hash: item.FileHash,
|
||||||
|
types,
|
||||||
|
_types,
|
||||||
|
typeUrl: {},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return list
|
||||||
|
},
|
||||||
|
handleResult(rawData) {
|
||||||
|
const rawList = []
|
||||||
|
rawData.forEach(item => {
|
||||||
|
rawList.push(item)
|
||||||
|
item.Grp.forEach(e => rawList.push(e))
|
||||||
|
})
|
||||||
|
|
||||||
|
return this.filterList(rawList)
|
||||||
|
},
|
||||||
|
search(str, page = 1, limit, retryNum = 0) {
|
||||||
|
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
|
||||||
|
if (limit == null) limit = this.limit
|
||||||
|
|
||||||
|
return this.musicSearch(str, page, limit).then(data => {
|
||||||
|
let list = this.handleResult(data.lists)
|
||||||
|
if (!list) return this.search(str, page, limit, retryNum)
|
||||||
|
|
||||||
|
this.total = 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',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
930
src/renderer/utils/musicSdk/kg/temp/songList-old.js
Normal file
930
src/renderer/utils/musicSdk/kg/temp/songList-old.js
Normal file
@ -0,0 +1,930 @@
|
|||||||
|
import { httpFetch } from '../../../request'
|
||||||
|
import { decodeName, formatPlayTime, sizeFormate, dateFormat } from '../../../index'
|
||||||
|
import infSign from '../vendors/infSign.min'
|
||||||
|
import { signatureParams } from '../util'
|
||||||
|
|
||||||
|
const handleSignature = (id, page, limit) => new Promise((resolve, reject) => {
|
||||||
|
infSign({ appid: 1058, type: 0, module: 'playlist', page, pagesize: limit, specialid: id }, null, {
|
||||||
|
useH5: !0,
|
||||||
|
isCDN: !0,
|
||||||
|
callback(i) {
|
||||||
|
resolve(i.signature)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
export default {
|
||||||
|
_requestObj_tags: null,
|
||||||
|
_requestObj_listInfo: null,
|
||||||
|
_requestObj_list: null,
|
||||||
|
_requestObj_listRecommend: null,
|
||||||
|
listDetailLimit: 10000,
|
||||||
|
currentTagInfo: {
|
||||||
|
id: undefined,
|
||||||
|
info: undefined,
|
||||||
|
},
|
||||||
|
sortList: [
|
||||||
|
{
|
||||||
|
name: '推荐',
|
||||||
|
id: '5',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '最热',
|
||||||
|
id: '6',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '最新',
|
||||||
|
id: '7',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '热藏',
|
||||||
|
id: '3',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '飙升',
|
||||||
|
id: '8',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
cache: new Map(),
|
||||||
|
regExps: {
|
||||||
|
listData: /global\.data = (\[.+\]);/,
|
||||||
|
listInfo: /global = {[\s\S]+?name: "(.+)"[\s\S]+?pic: "(.+)"[\s\S]+?};/,
|
||||||
|
// https://www.kugou.com/yy/special/single/1067062.html
|
||||||
|
listDetailLink: /^.+\/(\d+)\.html(?:\?.*|&.*$|#.*$|$)/,
|
||||||
|
},
|
||||||
|
async getGlobalSpecialId(specialId) {
|
||||||
|
return httpFetch(`http://mobilecdnbj.kugou.com/api/v5/special/info?specialid=${specialId}`, {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; HLK-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Mobile Safari/537.36 EdgA/104.0.1293.70',
|
||||||
|
},
|
||||||
|
}).promise.then(({ body }) => {
|
||||||
|
// console.log(body)
|
||||||
|
if (!body.data.global_specialid) Promise.reject(new Error('Failed to get global collection id.'))
|
||||||
|
return body.data.global_specialid
|
||||||
|
})
|
||||||
|
},
|
||||||
|
// async getListInfoBySpecialId(special_id, retry = 0) {
|
||||||
|
// if (++retry > 2) throw new Error('failed')
|
||||||
|
// return httpFetch(`https://m.kugou.com/plist/list/${special_id}/?json=true`, {
|
||||||
|
// headers: {
|
||||||
|
// 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; HLK-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Mobile Safari/537.36 EdgA/104.0.1293.70',
|
||||||
|
// },
|
||||||
|
// follow_max: 2,
|
||||||
|
// }).promise.then(({ body }) => {
|
||||||
|
// // console.log(body)
|
||||||
|
// if (!body.info.list) return this.getListInfoBySpecialId(special_id, retry)
|
||||||
|
// let listinfo = body.info.list
|
||||||
|
// return {
|
||||||
|
// listInfo: {
|
||||||
|
// name: listinfo.specialname,
|
||||||
|
// image: listinfo.imgurl.replace('{size}', '150'),
|
||||||
|
// intro: listinfo.intro,
|
||||||
|
// author: listinfo.nickname,
|
||||||
|
// playcount: listinfo.playcount,
|
||||||
|
// total: listinfo.songcount,
|
||||||
|
// },
|
||||||
|
// globalSpecialId: listinfo.global_specialid,
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// },
|
||||||
|
// async getSongListDetailByGlobalSpecialId(id, page, limit = 100, retry = 0) {
|
||||||
|
// if (++retry > 2) throw new Error('failed')
|
||||||
|
// console.log(id)
|
||||||
|
// const params = `specialid=0&need_sort=1&module=CloudMusic&clientver=11409&pagesize=${limit}&global_collection_id=${id}&userid=0&page=${page}&type=1&area_code=1&appid=1005`
|
||||||
|
// return httpFetch(`http://pubsongscdn.tx.kugou.com/v2/get_other_list_file?${params}&signature=${signatureParams(params)}`).promise.then(({ body }) => {
|
||||||
|
// // console.log(body)
|
||||||
|
// if (body.data?.info == null) return this.getSongListDetailByGlobalSpecialId(id, page, limit, retry)
|
||||||
|
// return body.data.info
|
||||||
|
// })
|
||||||
|
// },
|
||||||
|
parseHtmlDesc(html) {
|
||||||
|
const prefix = '<div class="pc_specail_text pc_singer_tab_content" id="specailIntroduceWrap">'
|
||||||
|
let index = html.indexOf(prefix)
|
||||||
|
if (index < 0) return null
|
||||||
|
const afterStr = html.substring(index + prefix.length)
|
||||||
|
index = afterStr.indexOf('</div>')
|
||||||
|
if (index < 0) return null
|
||||||
|
return decodeName(afterStr.substring(0, index))
|
||||||
|
},
|
||||||
|
async getListDetailBySpecialId(id, page, tryNum = 0) {
|
||||||
|
if (tryNum > 2) throw new Error('try max num')
|
||||||
|
|
||||||
|
const { body } = await httpFetch(this.getSongListDetailUrl(id)).promise
|
||||||
|
let listData = body.match(this.regExps.listData)
|
||||||
|
let listInfo = body.match(this.regExps.listInfo)
|
||||||
|
if (!listData) return this.getListDetailBySpecialId(id, page, ++tryNum)
|
||||||
|
let list = await this.getMusicInfos(JSON.parse(listData[1]))
|
||||||
|
// listData = this.filterData(JSON.parse(listData[1]))
|
||||||
|
let name
|
||||||
|
let pic
|
||||||
|
if (listInfo) {
|
||||||
|
name = listInfo[1]
|
||||||
|
pic = listInfo[2]
|
||||||
|
}
|
||||||
|
let desc = this.parseHtmlDesc(body)
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
list,
|
||||||
|
page: 1,
|
||||||
|
limit: 10000,
|
||||||
|
total: list.length,
|
||||||
|
source: 'kg',
|
||||||
|
info: {
|
||||||
|
name,
|
||||||
|
img: pic,
|
||||||
|
desc,
|
||||||
|
// author: body.result.info.userinfo.username,
|
||||||
|
// play_count: this.formatPlayCount(body.result.listen_num),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// const globalSpecialId = await this.getGlobalSpecialId(id)
|
||||||
|
// const limit = 100
|
||||||
|
// const listData = await this.getSongListDetailByGlobalSpecialId(globalSpecialId, page, limit)
|
||||||
|
// if (!Array.isArray(listData))
|
||||||
|
// return this.getUserListDetail2(globalSpecialId)
|
||||||
|
// return {
|
||||||
|
// list: this.filterDatav9(listData),
|
||||||
|
// page,
|
||||||
|
// limit,
|
||||||
|
// total: listInfo.total,
|
||||||
|
// source: 'kg',
|
||||||
|
// info: {
|
||||||
|
// name: listInfo.name,
|
||||||
|
// img: listInfo.image,
|
||||||
|
// desc: listInfo.intro,
|
||||||
|
// author: listInfo.author,
|
||||||
|
// play_count: this.formatPlayCount(listInfo.playcount),
|
||||||
|
// },
|
||||||
|
// }
|
||||||
|
},
|
||||||
|
getInfoUrl(tagId) {
|
||||||
|
return tagId
|
||||||
|
? `http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_smarty=1&cdn=cdn&t=5&c=${tagId}`
|
||||||
|
: 'http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_smarty=1&'
|
||||||
|
},
|
||||||
|
getSongListUrl(sortId, tagId, page) {
|
||||||
|
if (tagId == null) tagId = ''
|
||||||
|
return `http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_ajax=1&cdn=cdn&t=${sortId}&c=${tagId}&p=${page}`
|
||||||
|
},
|
||||||
|
getSongListDetailUrl(id) {
|
||||||
|
return `http://www2.kugou.kugou.com/yueku/v9/special/single/${id}-5-9999.html`
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化播放数量
|
||||||
|
* @param {*} num
|
||||||
|
*/
|
||||||
|
formatPlayCount(num) {
|
||||||
|
if (num > 100000000) return parseInt(num / 10000000) / 10 + '亿'
|
||||||
|
if (num > 10000) return parseInt(num / 1000) / 10 + '万'
|
||||||
|
return num
|
||||||
|
},
|
||||||
|
filterInfoHotTag(rawData) {
|
||||||
|
const result = []
|
||||||
|
if (rawData.status !== 1) return result
|
||||||
|
for (const key of Object.keys(rawData.data)) {
|
||||||
|
let tag = rawData.data[key]
|
||||||
|
result.push({
|
||||||
|
id: tag.special_id,
|
||||||
|
name: tag.special_name,
|
||||||
|
source: 'kg',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
},
|
||||||
|
filterTagInfo(rawData) {
|
||||||
|
const result = []
|
||||||
|
for (const name of Object.keys(rawData)) {
|
||||||
|
result.push({
|
||||||
|
name,
|
||||||
|
list: rawData[name].data.map(tag => ({
|
||||||
|
parent_id: tag.parent_id,
|
||||||
|
parent_name: tag.pname,
|
||||||
|
id: tag.id,
|
||||||
|
name: tag.name,
|
||||||
|
source: 'kg',
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
},
|
||||||
|
|
||||||
|
getSongList(sortId, tagId, page, tryNum = 0) {
|
||||||
|
if (this._requestObj_list) this._requestObj_list.cancelHttp()
|
||||||
|
if (tryNum > 2) return Promise.reject(new Error('try max num'))
|
||||||
|
this._requestObj_list = httpFetch(
|
||||||
|
this.getSongListUrl(sortId, tagId, page),
|
||||||
|
)
|
||||||
|
return this._requestObj_list.promise.then(({ body }) => {
|
||||||
|
if (!body || body.status !== 1) return this.getSongList(sortId, tagId, page, ++tryNum)
|
||||||
|
return this.filterList(body.special_db)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getSongListRecommend(tryNum = 0) {
|
||||||
|
if (this._requestObj_listRecommend) this._requestObj_listRecommend.cancelHttp()
|
||||||
|
if (tryNum > 2) return Promise.reject(new Error('try max num'))
|
||||||
|
this._requestObj_listRecommend = httpFetch(
|
||||||
|
'http://everydayrec.service.kugou.com/guess_special_recommend',
|
||||||
|
{
|
||||||
|
method: 'post',
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'KuGou2012-8275-web_browser_event_handler',
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
appid: 1001,
|
||||||
|
clienttime: 1566798337219,
|
||||||
|
clientver: 8275,
|
||||||
|
key: 'f1f93580115bb106680d2375f8032d96',
|
||||||
|
mid: '21511157a05844bd085308bc76ef3343',
|
||||||
|
platform: 'pc',
|
||||||
|
userid: '262643156',
|
||||||
|
return_min: 6,
|
||||||
|
return_max: 15,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return this._requestObj_listRecommend.promise.then(({ body }) => {
|
||||||
|
if (body.status !== 1) return this.getSongListRecommend(++tryNum)
|
||||||
|
return this.filterList(body.data.special_list)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
filterList(rawData) {
|
||||||
|
return rawData.map(item => ({
|
||||||
|
play_count: item.total_play_count || this.formatPlayCount(item.play_count),
|
||||||
|
id: 'id_' + item.specialid,
|
||||||
|
author: item.nickname,
|
||||||
|
name: item.specialname,
|
||||||
|
time: dateFormat(item.publish_time || item.publishtime, 'Y-M-D'),
|
||||||
|
img: item.img || item.imgurl,
|
||||||
|
total: item.songcount,
|
||||||
|
grade: item.grade,
|
||||||
|
desc: item.intro,
|
||||||
|
source: 'kg',
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
|
||||||
|
async createHttp(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 this.createHttp(url, options, ++retryNum)
|
||||||
|
}
|
||||||
|
// console.log(result.statusCode, result.body)
|
||||||
|
if (result.statusCode !== 200 ||
|
||||||
|
(
|
||||||
|
(result.body.error_code !== undefined
|
||||||
|
? result.body.error_code
|
||||||
|
: result.body.errcode !== undefined
|
||||||
|
? result.body.errcode
|
||||||
|
: result.body.err_code
|
||||||
|
) !== 0)
|
||||||
|
) return this.createHttp(url, options, ++retryNum)
|
||||||
|
if (result.body.data) return result.body.data
|
||||||
|
if (Array.isArray(result.body.info)) return result.body
|
||||||
|
return result.body.info
|
||||||
|
},
|
||||||
|
|
||||||
|
createTask(hashs) {
|
||||||
|
let data = {
|
||||||
|
appid: 1001,
|
||||||
|
clienttime: 639437935,
|
||||||
|
clientver: 9020,
|
||||||
|
fields:
|
||||||
|
'album_info,author_name,audio_info,ori_audio_name',
|
||||||
|
is_publish: '1',
|
||||||
|
key: '0475af1457cd3363c7b45b871e94428a',
|
||||||
|
mid: '21511157a05844bd085308bc76ef3342',
|
||||||
|
show_privilege: 1,
|
||||||
|
}
|
||||||
|
let list = hashs
|
||||||
|
let tasks = []
|
||||||
|
while (list.length) {
|
||||||
|
tasks.push(Object.assign({ data: list.slice(0, 100) }, data))
|
||||||
|
if (list.length < 100) break
|
||||||
|
list = list.slice(100)
|
||||||
|
}
|
||||||
|
let url = 'http://kmr.service.kugou.com/v2/album_audio/audio'
|
||||||
|
return tasks.map(task => this.createHttp(url, {
|
||||||
|
method: 'POST',
|
||||||
|
body: task,
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
|
||||||
|
},
|
||||||
|
}).then(data => data.map(s => s[0])))
|
||||||
|
},
|
||||||
|
async getMusicInfos(list) {
|
||||||
|
return this.filterData2(
|
||||||
|
await Promise.all(
|
||||||
|
this.createTask(
|
||||||
|
this.deDuplication(list)
|
||||||
|
.map(item => ({ hash: item.hash })),
|
||||||
|
))
|
||||||
|
.then(([...datas]) => datas.flat()))
|
||||||
|
},
|
||||||
|
|
||||||
|
async getUserListDetailByCode(id) {
|
||||||
|
const songInfo = await this.createHttp('http://t.kugou.com/command/', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'KG-RC': 1,
|
||||||
|
'KG-THash': 'network_super_call.cpp:3676261689:379',
|
||||||
|
'User-Agent': '',
|
||||||
|
},
|
||||||
|
body: { appid: 1001, clientver: 9020, mid: '21511157a05844bd085308bc76ef3343', clienttime: 640612895, key: '36164c4015e704673c588ee202b9ecb8', data: id },
|
||||||
|
})
|
||||||
|
// console.log(songInfo)
|
||||||
|
// type 1单曲,2歌单,3电台,4酷狗码,5别人的播放队列
|
||||||
|
let songList
|
||||||
|
let info = songInfo.info
|
||||||
|
switch (info.type) {
|
||||||
|
case 2:
|
||||||
|
if (!info.global_collection_id) return this.getListDetailBySpecialId(info.id)
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (info.global_collection_id) return this.getUserListDetail2(info.global_collection_id)
|
||||||
|
if (info.userid != null) {
|
||||||
|
songList = await this.createHttp('http://www2.kugou.kugou.com/apps/kucodeAndShare/app/', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'KG-RC': 1,
|
||||||
|
'KG-THash': 'network_super_call.cpp:3676261689:379',
|
||||||
|
'User-Agent': '',
|
||||||
|
},
|
||||||
|
body: { appid: 1001, clientver: 9020, mid: '21511157a05844bd085308bc76ef3343', clienttime: 640612895, key: '36164c4015e704673c588ee202b9ecb8', data: { id: info.id, type: 3, userid: info.userid, collect_type: 0, page: 1, pagesize: info.count } },
|
||||||
|
})
|
||||||
|
// console.log(songList)
|
||||||
|
}
|
||||||
|
let list = await this.getMusicInfos(songList || songInfo.list)
|
||||||
|
return {
|
||||||
|
list,
|
||||||
|
page: 1,
|
||||||
|
limit: info.count,
|
||||||
|
total: list.length,
|
||||||
|
source: 'kg',
|
||||||
|
info: {
|
||||||
|
name: info.name,
|
||||||
|
img: (info.img_size && info.img_size.replace('{size}', 240)) || info.img,
|
||||||
|
// desc: body.result.info.list_desc,
|
||||||
|
author: info.username,
|
||||||
|
// play_count: this.formatPlayCount(info.count),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async getUserListDetail3(chain, page) {
|
||||||
|
const songInfo = await this.createHttp(`http://m.kugou.com/schain/transfer?pagesize=${this.listDetailLimit}&chain=${chain}&su=1&page=${page}&n=0.7928855356604456`, {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (!songInfo.list) {
|
||||||
|
if (songInfo.global_collection_id) return this.getUserListDetail2(songInfo.global_collection_id)
|
||||||
|
else return this.getUserListDetail4(songInfo, chain, page).catch(() => this.getUserListDetail5(chain))
|
||||||
|
}
|
||||||
|
let list = await this.getMusicInfos(songInfo.list)
|
||||||
|
// console.log(info, songInfo)
|
||||||
|
return {
|
||||||
|
list,
|
||||||
|
page: 1,
|
||||||
|
limit: this.listDetailLimit,
|
||||||
|
total: list.length,
|
||||||
|
source: 'kg',
|
||||||
|
info: {
|
||||||
|
name: songInfo.info.name,
|
||||||
|
img: songInfo.info.img,
|
||||||
|
// desc: body.result.info.list_desc,
|
||||||
|
author: songInfo.info.username,
|
||||||
|
// play_count: this.formatPlayCount(info.count),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
deDuplication(datas) {
|
||||||
|
let ids = new Set()
|
||||||
|
return datas.filter(({ hash }) => {
|
||||||
|
if (ids.has(hash)) return false
|
||||||
|
ids.add(hash)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
async getUserListDetailByLink({ info }, link) {
|
||||||
|
let listInfo = info['0']
|
||||||
|
let total = listInfo.count
|
||||||
|
let tasks = []
|
||||||
|
let page = 0
|
||||||
|
while (total) {
|
||||||
|
const limit = total > 90 ? 90 : total
|
||||||
|
total -= limit
|
||||||
|
page += 1
|
||||||
|
tasks.push(this.createHttp(link.replace(/pagesize=\d+/, 'pagesize=' + limit).replace(/page=\d+/, 'page=' + page), {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
|
||||||
|
Referer: link,
|
||||||
|
},
|
||||||
|
}).then(data => data.list.info))
|
||||||
|
}
|
||||||
|
let result = await Promise.all(tasks).then(([...datas]) => datas.flat())
|
||||||
|
result = await this.getMusicInfos(result)
|
||||||
|
// console.log(result)
|
||||||
|
return {
|
||||||
|
list: result,
|
||||||
|
page,
|
||||||
|
limit: this.listDetailLimit,
|
||||||
|
total: result.length,
|
||||||
|
source: 'kg',
|
||||||
|
info: {
|
||||||
|
name: listInfo.name,
|
||||||
|
img: listInfo.pic && listInfo.pic.replace('{size}', 240),
|
||||||
|
// desc: body.result.info.list_desc,
|
||||||
|
author: listInfo.list_create_username,
|
||||||
|
// play_count: this.formatPlayCount(listInfo.count),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
createGetListDetail2Task(id, total) {
|
||||||
|
let tasks = []
|
||||||
|
let page = 0
|
||||||
|
while (total) {
|
||||||
|
const limit = total > 300 ? 300 : total
|
||||||
|
total -= limit
|
||||||
|
page += 1
|
||||||
|
const params = 'appid=1058&global_specialid=' + id + '&specialid=0&plat=0&version=8000&page=' + page + '&pagesize=' + limit + '&srcappid=2919&clientver=20000&clienttime=1586163263991&mid=1586163263991&uuid=1586163263991&dfid=-'
|
||||||
|
tasks.push(this.createHttp(`https://mobiles.kugou.com/api/v5/special/song_v2?${params}&signature=${signatureParams(params, 5)}`, {
|
||||||
|
headers: {
|
||||||
|
mid: '1586163263991',
|
||||||
|
Referer: 'https://m3ws.kugou.com/share/index.php',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
|
||||||
|
dfid: '-',
|
||||||
|
clienttime: '1586163263991',
|
||||||
|
},
|
||||||
|
}).then(data => data.info))
|
||||||
|
}
|
||||||
|
return Promise.all(tasks).then(([...datas]) => datas.flat())
|
||||||
|
},
|
||||||
|
async getUserListDetail2(global_collection_id) {
|
||||||
|
let id = global_collection_id
|
||||||
|
if (id.length > 1000) throw new Error('get list error')
|
||||||
|
const params = 'appid=1058&specialid=0&global_specialid=' + id + '&format=jsonp&srcappid=2919&clientver=20000&clienttime=1586163242519&mid=1586163242519&uuid=1586163242519&dfid=-'
|
||||||
|
let info = await this.createHttp(`https://mobiles.kugou.com/api/v5/special/info_v2?${params}&signature=${signatureParams(params, 5)}`, {
|
||||||
|
headers: {
|
||||||
|
mid: '1586163242519',
|
||||||
|
Referer: 'https://m3ws.kugou.com/share/index.php',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
|
||||||
|
dfid: '-',
|
||||||
|
clienttime: '1586163242519',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const songInfo = await this.createGetListDetail2Task(id, info.songcount)
|
||||||
|
let list = await this.getMusicInfos(songInfo)
|
||||||
|
// console.log(info, songInfo, list)
|
||||||
|
return {
|
||||||
|
list,
|
||||||
|
page: 1,
|
||||||
|
limit: this.listDetailLimit,
|
||||||
|
total: list.length,
|
||||||
|
source: 'kg',
|
||||||
|
info: {
|
||||||
|
name: info.specialname,
|
||||||
|
img: info.imgurl && info.imgurl.replace('{size}', 240),
|
||||||
|
desc: info.intro,
|
||||||
|
author: info.nickname,
|
||||||
|
play_count: this.formatPlayCount(info.playcount),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async getListInfoByChain(chain) {
|
||||||
|
if (this.cache.has(chain)) return this.cache.get(chain)
|
||||||
|
const { body } = await httpFetch(`https://m.kugou.com/share/?chain=${chain}&id=${chain}`, {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',
|
||||||
|
},
|
||||||
|
}).promise
|
||||||
|
let result = body.match(/var\sphpParam\s=\s({.+?});/)
|
||||||
|
if (result) result = JSON.parse(result[1])
|
||||||
|
this.cache.set(chain, result)
|
||||||
|
return result
|
||||||
|
},
|
||||||
|
|
||||||
|
async getUserListDetailByPcChain(chain) {
|
||||||
|
let key = `${chain}_pc_list`
|
||||||
|
if (this.cache.has(key)) return this.cache.get(key)
|
||||||
|
const { body } = await httpFetch(`http://www.kugou.com/share/${chain}.html`, {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
|
||||||
|
},
|
||||||
|
}).promise
|
||||||
|
let result = body.match(/var\sdataFromSmarty\s=\s(\[.+?\])/)
|
||||||
|
if (result) result = JSON.parse(result[1])
|
||||||
|
this.cache.set(chain, result)
|
||||||
|
result = await this.getMusicInfos(result)
|
||||||
|
// console.log(info, songInfo)
|
||||||
|
return result
|
||||||
|
},
|
||||||
|
|
||||||
|
async getUserListDetail4(songInfo, chain, page) {
|
||||||
|
const limit = 100
|
||||||
|
const [listInfo, list] = await Promise.all([
|
||||||
|
this.getListInfoByChain(chain),
|
||||||
|
this.getUserListDetailById(songInfo.id, page, limit),
|
||||||
|
])
|
||||||
|
return {
|
||||||
|
list: list || [],
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
total: list.length ?? 0,
|
||||||
|
source: 'kg',
|
||||||
|
info: {
|
||||||
|
name: listInfo.specialname,
|
||||||
|
img: listInfo.imgurl && listInfo.imgurl.replace('{size}', 240),
|
||||||
|
// desc: body.result.info.list_desc,
|
||||||
|
author: listInfo.nickname,
|
||||||
|
// play_count: this.formatPlayCount(info.count),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async getUserListDetail5(chain) {
|
||||||
|
const [listInfo, list] = await Promise.all([
|
||||||
|
this.getListInfoByChain(chain),
|
||||||
|
this.getUserListDetailByPcChain(chain),
|
||||||
|
])
|
||||||
|
return {
|
||||||
|
list: list || [],
|
||||||
|
page: 1,
|
||||||
|
limit: this.listDetailLimit,
|
||||||
|
total: list.length ?? 0,
|
||||||
|
source: 'kg',
|
||||||
|
info: {
|
||||||
|
name: listInfo.specialname,
|
||||||
|
img: listInfo.imgurl && listInfo.imgurl.replace('{size}', 240),
|
||||||
|
// desc: body.result.info.list_desc,
|
||||||
|
author: listInfo.nickname,
|
||||||
|
// play_count: this.formatPlayCount(info.count),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async getUserListDetailById(id, page, limit) {
|
||||||
|
const signature = await handleSignature(id, page, limit)
|
||||||
|
let info = await this.createHttp(`https://pubsongscdn.kugou.com/v2/get_other_list_file?srcappid=2919&clientver=20000&appid=1058&type=0&module=playlist&page=${page}&pagesize=${limit}&specialid=${id}&signature=${signature}`, {
|
||||||
|
headers: {
|
||||||
|
Referer: 'https://m3ws.kugou.com/share/index.php',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
|
||||||
|
dfid: '-',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// console.log(info)
|
||||||
|
let result = await this.getMusicInfos(info.info)
|
||||||
|
// console.log(info, songInfo)
|
||||||
|
return result
|
||||||
|
},
|
||||||
|
|
||||||
|
async getUserListDetail(link, page, retryNum = 0) {
|
||||||
|
if (retryNum > 3) return Promise.reject(new Error('link try max num'))
|
||||||
|
if (link.includes('#')) link = link.replace(/#.*$/, '')
|
||||||
|
if (link.includes('global_collection_id')) return this.getUserListDetail2(link.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1'))
|
||||||
|
if (link.includes('chain=')) return this.getUserListDetail3(link.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page)
|
||||||
|
if (link.includes('.html')) {
|
||||||
|
if (link.includes('zlist.html')) {
|
||||||
|
link = link.replace(/^(.*)zlist\.html/, 'https://m3ws.kugou.com/zlist/list')
|
||||||
|
if (link.includes('pagesize')) {
|
||||||
|
link = link.replace('pagesize=30', 'pagesize=' + this.listDetailLimit).replace('page=1', 'page=' + page)
|
||||||
|
} else {
|
||||||
|
link += `&pagesize=${this.listDetailLimit}&page=${page}`
|
||||||
|
}
|
||||||
|
} else if (!link.includes('song.html')) return this.getUserListDetail3(link.replace(/.+\/(\w+).html(?:\?.*|&.*$|#.*$|$)/, '$1'), page)
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestObj_listDetailLink = httpFetch(link, {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
|
||||||
|
Referer: link,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const { headers: { location }, statusCode, body } = await requestObj_listDetailLink.promise
|
||||||
|
// console.log(body, location)
|
||||||
|
if (statusCode > 400) return this.getUserListDetail(link, page, ++retryNum)
|
||||||
|
if (location) {
|
||||||
|
// console.log(location)
|
||||||
|
if (location.includes('global_collection_id')) return this.getUserListDetail2(location.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1'))
|
||||||
|
if (location.includes('chain=')) return this.getUserListDetail3(location.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page)
|
||||||
|
if (location.includes('.html')) {
|
||||||
|
if (location.includes('zlist.html')) {
|
||||||
|
let link = location.replace(/^(.*)zlist\.html/, 'https://m3ws.kugou.com/zlist/list')
|
||||||
|
if (link.includes('pagesize')) {
|
||||||
|
link = link.replace('pagesize=30', 'pagesize=' + this.listDetailLimit).replace('page=1', 'page=' + page)
|
||||||
|
} else {
|
||||||
|
link += `&pagesize=${this.listDetailLimit}&page=${page}`
|
||||||
|
}
|
||||||
|
return this.getUserListDetail(link, page, ++retryNum)
|
||||||
|
} else return this.getUserListDetail3(location.replace(/.+\/(\w+).html(?:\?.*|&.*$|#.*$|$)/, '$1'), page)
|
||||||
|
}
|
||||||
|
// console.log('location', location)
|
||||||
|
return this.getUserListDetail(location, page, ++retryNum)
|
||||||
|
}
|
||||||
|
if (typeof body == 'string') return this.getUserListDetail2(body.replace(/^[\s\S]+?"global_collection_id":"(\w+)"[\s\S]+?$/, '$1'))
|
||||||
|
if (body.errcode !== 0) return this.getUserListDetail(link, page, ++retryNum)
|
||||||
|
return this.getUserListDetailByLink(body, link)
|
||||||
|
},
|
||||||
|
|
||||||
|
async getListDetail(id, page) { // 获取歌曲列表内的音乐
|
||||||
|
id = id.toString()
|
||||||
|
if (id.includes('special/single/')) {
|
||||||
|
id = id.replace(this.regExps.listDetailLink, '$1')
|
||||||
|
} else if (/https?:/.test(id)) {
|
||||||
|
// fix https://www.kugou.com/songlist/xxx/?uid=xxx&chl=qq_client&cover=http%3A%2F%2Fimge.kugou.com%xxx.jpg&iszlist=1
|
||||||
|
return this.getUserListDetail(id.replace(/^.*?http/, 'http'), page)
|
||||||
|
} else if (/^\d+$/.test(id)) {
|
||||||
|
return this.getUserListDetailByCode(id)
|
||||||
|
} else if (id.startsWith('id_')) {
|
||||||
|
id = id.replace('id_', '')
|
||||||
|
}
|
||||||
|
// if ((/[?&:/]/.test(id))) id = id.replace(this.regExps.listDetailLink, '$1')
|
||||||
|
|
||||||
|
return this.getListDetailBySpecialId(id, page)
|
||||||
|
},
|
||||||
|
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.filesize_320 !== 0) {
|
||||||
|
let size = sizeFormate(item.filesize_320)
|
||||||
|
types.push({ type: '320k', size, hash: item.hash_320 })
|
||||||
|
_types['320k'] = {
|
||||||
|
size,
|
||||||
|
hash: item.hash_320,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.filesize_ape !== 0) {
|
||||||
|
let size = sizeFormate(item.filesize_ape)
|
||||||
|
types.push({ type: 'ape', size, hash: item.hash_ape })
|
||||||
|
_types.ape = {
|
||||||
|
size,
|
||||||
|
hash: item.hash_ape,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.filesize_flac !== 0) {
|
||||||
|
let size = sizeFormate(item.filesize_flac)
|
||||||
|
types.push({ type: 'flac', size, hash: item.hash_flac })
|
||||||
|
_types.flac = {
|
||||||
|
size,
|
||||||
|
hash: item.hash_flac,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
singer: decodeName(item.singername),
|
||||||
|
name: decodeName(item.songname),
|
||||||
|
albumName: decodeName(item.album_name),
|
||||||
|
albumId: item.album_id,
|
||||||
|
songmid: item.audio_id,
|
||||||
|
source: 'kg',
|
||||||
|
interval: formatPlayTime(item.duration / 1000),
|
||||||
|
img: null,
|
||||||
|
lrc: null,
|
||||||
|
hash: item.hash,
|
||||||
|
types,
|
||||||
|
_types,
|
||||||
|
typeUrl: {},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
// getSinger(singers) {
|
||||||
|
// let arr = []
|
||||||
|
// singers?.forEach(singer => {
|
||||||
|
// arr.push(singer.name)
|
||||||
|
// })
|
||||||
|
// return arr.join('、')
|
||||||
|
// },
|
||||||
|
// v9 API
|
||||||
|
// filterDatav9(rawList) {
|
||||||
|
// console.log(rawList)
|
||||||
|
// return rawList.map(item => {
|
||||||
|
// const types = []
|
||||||
|
// const _types = {}
|
||||||
|
// item.relate_goods.forEach(qualityObj => {
|
||||||
|
// if (qualityObj.level === 2) {
|
||||||
|
// let size = sizeFormate(qualityObj.size)
|
||||||
|
// types.push({ type: '128k', size, hash: qualityObj.hash })
|
||||||
|
// _types['128k'] = {
|
||||||
|
// size,
|
||||||
|
// hash: qualityObj.hash,
|
||||||
|
// }
|
||||||
|
// } else if (qualityObj.level === 4) {
|
||||||
|
// let size = sizeFormate(qualityObj.size)
|
||||||
|
// types.push({ type: '320k', size, hash: qualityObj.hash })
|
||||||
|
// _types['320k'] = {
|
||||||
|
// size,
|
||||||
|
// hash: qualityObj.hash,
|
||||||
|
// }
|
||||||
|
// } else if (qualityObj.level === 5) {
|
||||||
|
// let size = sizeFormate(qualityObj.size)
|
||||||
|
// types.push({ type: 'flac', size, hash: qualityObj.hash })
|
||||||
|
// _types.flac = {
|
||||||
|
// size,
|
||||||
|
// hash: qualityObj.hash,
|
||||||
|
// }
|
||||||
|
// } else if (qualityObj.level === 6) {
|
||||||
|
// let size = sizeFormate(qualityObj.size)
|
||||||
|
// types.push({ type: 'flac24bit', size, hash: qualityObj.hash })
|
||||||
|
// _types.flac24bit = {
|
||||||
|
// size,
|
||||||
|
// hash: qualityObj.hash,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// const nameInfo = item.name.split(' - ')
|
||||||
|
// return {
|
||||||
|
// singer: this.getSinger(item.singerinfo),
|
||||||
|
// name: decodeName((nameInfo[1] ?? nameInfo[0]).trim()),
|
||||||
|
// albumName: decodeName(item.albuminfo.name),
|
||||||
|
// albumId: item.albuminfo.id,
|
||||||
|
// songmid: item.audio_id,
|
||||||
|
// source: 'kg',
|
||||||
|
// interval: formatPlayTime(item.timelen / 1000),
|
||||||
|
// img: null,
|
||||||
|
// lrc: null,
|
||||||
|
// hash: item.hash,
|
||||||
|
// types,
|
||||||
|
// _types,
|
||||||
|
// typeUrl: {},
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// },
|
||||||
|
|
||||||
|
// hash list filter
|
||||||
|
filterData2(rawList) {
|
||||||
|
// console.log(rawList)
|
||||||
|
let ids = new Set()
|
||||||
|
let list = []
|
||||||
|
rawList.forEach(item => {
|
||||||
|
if (!item) return
|
||||||
|
if (ids.has(item.audio_info.audio_id)) return
|
||||||
|
ids.add(item.audio_info.audio_id)
|
||||||
|
const types = []
|
||||||
|
const _types = {}
|
||||||
|
if (item.audio_info.filesize !== '0') {
|
||||||
|
let size = sizeFormate(parseInt(item.audio_info.filesize))
|
||||||
|
types.push({ type: '128k', size, hash: item.audio_info.hash })
|
||||||
|
_types['128k'] = {
|
||||||
|
size,
|
||||||
|
hash: item.audio_info.hash,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.audio_info.filesize_320 !== '0') {
|
||||||
|
let size = sizeFormate(parseInt(item.audio_info.filesize_320))
|
||||||
|
types.push({ type: '320k', size, hash: item.audio_info.hash_320 })
|
||||||
|
_types['320k'] = {
|
||||||
|
size,
|
||||||
|
hash: item.audio_info.hash_320,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.audio_info.filesize_flac !== '0') {
|
||||||
|
let size = sizeFormate(parseInt(item.audio_info.filesize_flac))
|
||||||
|
types.push({ type: 'flac', size, hash: item.audio_info.hash_flac })
|
||||||
|
_types.flac = {
|
||||||
|
size,
|
||||||
|
hash: item.audio_info.hash_flac,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.audio_info.filesize_high !== '0') {
|
||||||
|
let size = sizeFormate(parseInt(item.audio_info.filesize_high))
|
||||||
|
types.push({ type: 'flac24bit', size, hash: item.audio_info.hash_high })
|
||||||
|
_types.flac24bit = {
|
||||||
|
size,
|
||||||
|
hash: item.audio_info.hash_high,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.push({
|
||||||
|
singer: decodeName(item.author_name),
|
||||||
|
name: decodeName(item.ori_audio_name),
|
||||||
|
albumName: decodeName(item.album_info.album_name),
|
||||||
|
albumId: item.album_info.album_id,
|
||||||
|
songmid: item.audio_info.audio_id,
|
||||||
|
source: 'kg',
|
||||||
|
interval: formatPlayTime(parseInt(item.audio_info.timelength) / 1000),
|
||||||
|
img: null,
|
||||||
|
lrc: null,
|
||||||
|
hash: item.audio_info.hash,
|
||||||
|
otherSource: null,
|
||||||
|
types,
|
||||||
|
_types,
|
||||||
|
typeUrl: {},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return list
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取列表信息
|
||||||
|
getListInfo(tagId, tryNum = 0) {
|
||||||
|
if (this._requestObj_listInfo) this._requestObj_listInfo.cancelHttp()
|
||||||
|
if (tryNum > 2) return Promise.reject(new Error('try max num'))
|
||||||
|
this._requestObj_listInfo = httpFetch(this.getInfoUrl(tagId))
|
||||||
|
return this._requestObj_listInfo.promise.then(({ body }) => {
|
||||||
|
if (body.status !== 1) return this.getListInfo(tagId, ++tryNum)
|
||||||
|
return {
|
||||||
|
limit: body.data.params.pagesize,
|
||||||
|
page: body.data.params.p,
|
||||||
|
total: body.data.params.total,
|
||||||
|
source: 'kg',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取列表数据
|
||||||
|
getList(sortId, tagId, page) {
|
||||||
|
let tasks = [this.getSongList(sortId, tagId, page)]
|
||||||
|
tasks.push(
|
||||||
|
this.currentTagInfo.id === tagId
|
||||||
|
? Promise.resolve(this.currentTagInfo.info)
|
||||||
|
: this.getListInfo(tagId).then(info => {
|
||||||
|
this.currentTagInfo.id = tagId
|
||||||
|
this.currentTagInfo.info = Object.assign({}, info)
|
||||||
|
return info
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
if (!tagId && page === 1 && sortId === this.sortList[0].id) tasks.push(this.getSongListRecommend()) // 如果是所有类别,则顺便获取推荐列表
|
||||||
|
return Promise.all(tasks).then(([list, info, recommendList]) => {
|
||||||
|
if (recommendList) list.unshift(...recommendList)
|
||||||
|
return {
|
||||||
|
list,
|
||||||
|
...info,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取标签
|
||||||
|
getTags(tryNum = 0) {
|
||||||
|
if (this._requestObj_tags) this._requestObj_tags.cancelHttp()
|
||||||
|
if (tryNum > 2) return Promise.reject(new Error('try max num'))
|
||||||
|
this._requestObj_tags = httpFetch(this.getInfoUrl())
|
||||||
|
return this._requestObj_tags.promise.then(({ body }) => {
|
||||||
|
if (body.status !== 1) return this.getTags(++tryNum)
|
||||||
|
return {
|
||||||
|
hotTag: this.filterInfoHotTag(body.data.hotTag),
|
||||||
|
tags: this.filterTagInfo(body.data.tagids),
|
||||||
|
source: 'kg',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
getDetailPageUrl(id) {
|
||||||
|
if (typeof id == 'string') {
|
||||||
|
if (/^https?:\/\//.test(id)) return id
|
||||||
|
id = id.replace('id_', '')
|
||||||
|
}
|
||||||
|
return `https://www.kugou.com/yy/special/single/${id}.html`
|
||||||
|
},
|
||||||
|
|
||||||
|
search(text, page, limit = 20) {
|
||||||
|
// http://msearchretry.kugou.com/api/v3/search/special?version=9209&keyword=%E5%91%A8%E6%9D%B0%E4%BC%A6&pagesize=20&filter=0&page=1&sver=2&with_res_tag=0
|
||||||
|
// return httpFetch(`http://ioscdn.kugou.com/api/v3/search/special?keyword=${encodeURIComponent(text)}&page=${page}&pagesize=${limit}&showtype=10&plat=2&version=7910&correct=1&sver=5`)
|
||||||
|
return httpFetch(`http://msearchretry.kugou.com/api/v3/search/special?keyword=${encodeURIComponent(text)}&page=${page}&pagesize=${limit}&showtype=10&filter=0&version=7910&sver=2`)
|
||||||
|
.promise.then(({ body }) => {
|
||||||
|
if (body.errcode != 0) throw new Error('filed')
|
||||||
|
// console.log(body.data.info)
|
||||||
|
return {
|
||||||
|
list: body.data.info.map(item => {
|
||||||
|
return {
|
||||||
|
play_count: this.formatPlayCount(item.playcount),
|
||||||
|
id: 'id_' + item.specialid,
|
||||||
|
author: item.nickname,
|
||||||
|
name: item.specialname,
|
||||||
|
time: dateFormat(item.publishtime, 'Y-M-D'),
|
||||||
|
img: item.imgurl,
|
||||||
|
grade: item.grade,
|
||||||
|
desc: item.intro,
|
||||||
|
total: item.songcount,
|
||||||
|
source: 'kg',
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
limit,
|
||||||
|
total: body.data.total,
|
||||||
|
source: 'kg',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// getList
|
||||||
|
// getTags
|
||||||
|
// getListDetail
|
||||||
25
src/renderer/utils/musicSdk/kg/tipSearch.js
Normal file
25
src/renderer/utils/musicSdk/kg/tipSearch.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { createHttpFetch } from './util'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
requestObj: null,
|
||||||
|
cancelTipSearch() {
|
||||||
|
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||||
|
},
|
||||||
|
tipSearchBySong(str) {
|
||||||
|
this.cancelTipSearch()
|
||||||
|
this.requestObj = createHttpFetch(`https://searchtip.kugou.com/getSearchTip?MusicTipCount=10&keyword=${encodeURIComponent(str)}`, {
|
||||||
|
headers: {
|
||||||
|
referer: 'https://www.kugou.com/',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return this.requestObj.then(body => {
|
||||||
|
return body[0].RecordDatas
|
||||||
|
})
|
||||||
|
},
|
||||||
|
handleResult(rawData) {
|
||||||
|
return rawData.map(info => info.HintInfo)
|
||||||
|
},
|
||||||
|
async search(str) {
|
||||||
|
return this.tipSearchBySong(str).then(result => this.handleResult(result))
|
||||||
|
},
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
import { inflate } from 'zlib'
|
import { inflate } from 'zlib'
|
||||||
import { toMD5 } from '../utils'
|
import { toMD5 } from '../utils'
|
||||||
|
import { httpFetch } from '../../request'
|
||||||
|
|
||||||
// https://github.com/lyswhut/lx-music-desktop/issues/296#issuecomment-683285784
|
// 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')
|
const enc_key = Buffer.from([0x40, 0x47, 0x61, 0x77, 0x5e, 0x32, 0x74, 0x47, 0x51, 0x36, 0x31, 0x2d, 0xce, 0xd2, 0x6e, 0x69], 'binary')
|
||||||
@ -19,11 +20,53 @@ export const decodeLyric = str => new Promise((resolve, reject) => {
|
|||||||
// console.log(str)
|
// console.log(str)
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
|
||||||
|
const signatureKey = { app: 'OIlwieks28dk2k092lksi2UIkp', web: 'NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt' }
|
||||||
|
/**
|
||||||
|
* 签名
|
||||||
|
* @param {*} params
|
||||||
|
* @param {*} apiver
|
||||||
|
*/
|
||||||
export const signatureParams = (params, apiver = 9) => {
|
export const signatureParams = (params, apiver = 9) => {
|
||||||
let keyparam = 'OIlwieks28dk2k092lksi2UIkp'
|
let key = signatureKey.app
|
||||||
if (apiver === 5) keyparam = 'NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt'
|
if (apiver === 5) key = signatureKey.web
|
||||||
let param_list = params.split('&')
|
|
||||||
param_list.sort()
|
if (typeof params === 'object') {
|
||||||
let sign_params = `${keyparam}${param_list.join('')}${keyparam}`
|
if (!Array.isArray(params)) throw new Error('params error.')
|
||||||
return toMD5(sign_params)
|
params = params.sort()
|
||||||
|
} else if (typeof params === 'string') {
|
||||||
|
params = params.split('&').sort()
|
||||||
|
} else throw new Error('params error.')
|
||||||
|
|
||||||
|
return toMD5(`${key}${params.join('')}${key}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个适用于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 !== undefined
|
||||||
|
? result.body.error_code
|
||||||
|
: result.body.errcode !== undefined
|
||||||
|
? 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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import tempSearch from './tempSearch'
|
import tipSearch from './tipSearch'
|
||||||
import musicSearch from './musicSearch'
|
import musicSearch from './musicSearch'
|
||||||
import { formatSinger, getToken } from './util'
|
import { formatSinger, getToken } from './util'
|
||||||
import leaderboard from './leaderboard'
|
import leaderboard from './leaderboard'
|
||||||
@ -32,7 +32,7 @@ const kw = {
|
|||||||
// // })
|
// // })
|
||||||
// },
|
// },
|
||||||
|
|
||||||
tempSearch,
|
tipSearch,
|
||||||
musicSearch,
|
musicSearch,
|
||||||
leaderboard,
|
leaderboard,
|
||||||
songList,
|
songList,
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { httpFetch } from '../../request'
|
|||||||
import { formatPlayTime, decodeName } from '../../index'
|
import { formatPlayTime, decodeName } from '../../index'
|
||||||
import { formatSinger } from './util'
|
import { formatSinger } from './util'
|
||||||
|
|
||||||
const boardList = [{ id: 'kw__93', name: '酷我飙升榜', bangid: '93' }, { id: 'kw__17', name: '酷我新歌榜', bangid: '17' }, { id: 'kw__16', name: '酷我热歌榜', bangid: '16' }, { id: 'kw__158', name: '抖音热歌榜', bangid: '158' }, { id: 'kw__292', name: '酷我铃声榜', bangid: '292' }, { id: 'kw__284', name: '酷我热评榜', bangid: '284' }, { id: 'kw__290', name: 'ACG新歌榜', bangid: '290' }, { id: 'kw__286', name: '台湾KKBOX榜', bangid: '286' }, { id: 'kw__279', name: '冬日暖心榜', bangid: '279' }, { id: 'kw__281', name: '巴士随身听榜', bangid: '281' }, { id: 'kw__255', name: 'KTV点唱榜', bangid: '255' }, { id: 'kw__280', name: '家务进行曲榜', bangid: '280' }, { id: 'kw__282', name: '熬夜修仙榜', bangid: '282' }, { id: 'kw__283', name: '枕边轻音乐榜', bangid: '283' }, { id: 'kw__278', name: '古风音乐榜', bangid: '278' }, { id: 'kw__264', name: 'Vlog音乐榜', bangid: '264' }, { id: 'kw__242', name: '酷我电音榜', bangid: '242' }, { id: 'kw__187', name: '流行趋势榜', bangid: '187' }, { id: 'kw__204', name: '现场音乐榜', bangid: '204' }, { id: 'kw__186', name: 'ACG神曲榜', bangid: '186' }, { id: 'kw__185', name: '最强翻唱榜', bangid: '185' }, { id: 'kw__26', name: '经典怀旧榜', bangid: '26' }, { id: 'kw__104', name: '酷我华语榜', bangid: '104' }, { id: 'kw__182', name: '酷我粤语榜', bangid: '182' }, { id: 'kw__22', name: '酷我欧美榜', bangid: '22' }, { id: 'kw__184', name: '酷我韩语榜', bangid: '184' }, { id: 'kw__183', name: '酷我日语榜', bangid: '183' }, { id: 'kw__145', name: '会员畅听榜', bangid: '145' }, { id: 'kw__153', name: '网红新歌榜', bangid: '153' }, { id: 'kw__64', name: '影视金曲榜', bangid: '64' }, { id: 'kw__176', name: 'DJ嗨歌榜', bangid: '176' }, { id: 'kw__106', name: '酷我真声音', bangid: '106' }, { id: 'kw__12', name: 'Billboard榜', bangid: '12' }, { id: 'kw__49', name: 'iTunes音乐榜', bangid: '49' }, { id: 'kw__180', name: 'beatport电音榜', bangid: '180' }, { id: 'kw__13', name: '英国UK榜', bangid: '13' }, { id: 'kw__164', name: '百大DJ榜', bangid: '164' }, { id: 'kw__246', name: 'YouTube音乐排行榜', bangid: '246' }, { id: 'kw__265', name: '韩国Genie榜', bangid: '265' }, { id: 'kw__14', name: '韩国M-net榜', bangid: '14' }, { id: 'kw__8', name: '香港电台榜', bangid: '8' }, { id: 'kw__15', name: '日本公信榜', bangid: '15' }, { id: 'kw__151', name: '腾讯音乐人原创榜', bangid: '151' }]
|
const boardList = [{ id: 'kw__93', name: '飙升榜', bangid: '93' }, { id: 'kw__17', name: '新歌榜', bangid: '17' }, { id: 'kw__16', name: '热歌榜', bangid: '16' }, { id: 'kw__158', name: '抖音热歌榜', bangid: '158' }, { id: 'kw__292', name: '铃声榜', bangid: '292' }, { id: 'kw__284', name: '热评榜', bangid: '284' }, { id: 'kw__290', name: 'ACG新歌榜', bangid: '290' }, { id: 'kw__286', name: '台湾KKBOX榜', bangid: '286' }, { id: 'kw__279', name: '冬日暖心榜', bangid: '279' }, { id: 'kw__281', name: '巴士随身听榜', bangid: '281' }, { id: 'kw__255', name: 'KTV点唱榜', bangid: '255' }, { id: 'kw__280', name: '家务进行曲榜', bangid: '280' }, { id: 'kw__282', name: '熬夜修仙榜', bangid: '282' }, { id: 'kw__283', name: '枕边轻音乐榜', bangid: '283' }, { id: 'kw__278', name: '古风音乐榜', bangid: '278' }, { id: 'kw__264', name: 'Vlog音乐榜', bangid: '264' }, { id: 'kw__242', name: '电音榜', bangid: '242' }, { id: 'kw__187', name: '流行趋势榜', bangid: '187' }, { id: 'kw__204', name: '现场音乐榜', bangid: '204' }, { id: 'kw__186', name: 'ACG神曲榜', bangid: '186' }, { id: 'kw__185', name: '最强翻唱榜', bangid: '185' }, { id: 'kw__26', name: '经典怀旧榜', bangid: '26' }, { id: 'kw__104', name: '华语榜', bangid: '104' }, { id: 'kw__182', name: '粤语榜', bangid: '182' }, { id: 'kw__22', name: '欧美榜', bangid: '22' }, { id: 'kw__184', name: '韩语榜', bangid: '184' }, { id: 'kw__183', name: '日语榜', bangid: '183' }, { id: 'kw__145', name: '会员畅听榜', bangid: '145' }, { id: 'kw__153', name: '网红新歌榜', bangid: '153' }, { id: 'kw__64', name: '影视金曲榜', bangid: '64' }, { id: 'kw__176', name: 'DJ嗨歌榜', bangid: '176' }, { id: 'kw__106', name: '真声音', bangid: '106' }, { id: 'kw__12', name: 'Billboard榜', bangid: '12' }, { id: 'kw__49', name: 'iTunes音乐榜', bangid: '49' }, { id: 'kw__180', name: 'beatport电音榜', bangid: '180' }, { id: 'kw__13', name: '英国UK榜', bangid: '13' }, { id: 'kw__164', name: '百大DJ榜', bangid: '164' }, { id: 'kw__246', name: 'YouTube音乐排行榜', bangid: '246' }, { id: 'kw__265', name: '韩国Genie榜', bangid: '265' }, { id: 'kw__14', name: '韩国M-net榜', bangid: '14' }, { id: 'kw__8', name: '香港电台榜', bangid: '8' }, { id: 'kw__15', name: '日本公信榜', bangid: '15' }, { id: 'kw__151', name: '腾讯音乐人原创榜', bangid: '151' }]
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
list: [
|
list: [
|
||||||
|
|||||||
@ -1,15 +1,13 @@
|
|||||||
// import { httpFetch } from '../../request'
|
|
||||||
import { decodeName } from '../../index'
|
import { decodeName } from '../../index'
|
||||||
import { tokenRequest } from './util'
|
import { tokenRequest } from './util'
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
regExps: {
|
regExps: {
|
||||||
relWord: /RELWORD=(.+)/,
|
relWord: /RELWORD=(.+)/,
|
||||||
},
|
},
|
||||||
requestObj: null,
|
requestObj: null,
|
||||||
async tempSearch(str) {
|
async tipSearchBySong(str) {
|
||||||
this.cancelTempSearch()
|
this.cancelTipSearch()
|
||||||
this.requestObj = await tokenRequest(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`)
|
this.requestObj = await tokenRequest(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`)
|
||||||
return this.requestObj.promise.then(({ body }) => {
|
return this.requestObj.promise.then(({ body }) => {
|
||||||
// console.log(body)
|
// console.log(body)
|
||||||
@ -23,10 +21,10 @@ export default {
|
|||||||
return matchResult ? decodeName(matchResult[1]) : ''
|
return matchResult ? decodeName(matchResult[1]) : ''
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
cancelTempSearch() {
|
cancelTipSearch() {
|
||||||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||||
},
|
},
|
||||||
async search(str) {
|
async search(str) {
|
||||||
return this.tempSearch(str).then(result => this.handleResult(result.data))
|
return this.tipSearchBySong(str).then(result => this.handleResult(result.data))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -1,18 +1,9 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { createHttpFetch } from './utils'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getAlbum(songInfo, tryNum = 0) {
|
getAlbumSong(songInfo) {
|
||||||
let requestObj = httpFetch(`http://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/queryAlbumSong?albumId=${songInfo.albumId}&pageNo=1`)
|
return createHttpFetch(`http://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/queryAlbumSong?albumId=${songInfo.albumId}&pageNo=1`).then(body => {
|
||||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
|
||||||
if (body.code !== '000000') {
|
|
||||||
if (tryNum > 5) return Promise.reject('获取专辑失败')
|
|
||||||
let tryRequestObj = this.getAlbum(songInfo, ++tryNum)
|
|
||||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
|
||||||
return tryRequestObj.promise
|
|
||||||
}
|
|
||||||
// console.log(body)
|
|
||||||
return body.songList
|
return body.songList
|
||||||
})
|
})
|
||||||
return requestObj
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -6,8 +6,10 @@ import pic from './pic'
|
|||||||
import lyric from './lyric'
|
import lyric from './lyric'
|
||||||
import hotSearch from './hotSearch'
|
import hotSearch from './hotSearch'
|
||||||
import comment from './comment'
|
import comment from './comment'
|
||||||
|
import tipSearch from './tipSearch'
|
||||||
|
|
||||||
const mg = {
|
const mg = {
|
||||||
|
tipSearch,
|
||||||
songList,
|
songList,
|
||||||
musicSearch,
|
musicSearch,
|
||||||
leaderboard,
|
leaderboard,
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import { filterMusicInfoData } from './musicInfo'
|
import { filterMusicInfoList } from './musicInfo'
|
||||||
|
|
||||||
|
|
||||||
// const boardList = [{ id: 'mg__27553319', name: '咪咕尖叫新歌榜', bangid: '27553319' }, { id: 'mg__27186466', name: '咪咕尖叫热歌榜', bangid: '27186466' }, { id: 'mg__27553408', name: '咪咕尖叫原创榜', bangid: '27553408' }, { id: 'mg__23189800', name: '咪咕港台榜', bangid: '23189800' }, { id: 'mg__23189399', name: '咪咕内地榜', bangid: '23189399' }, { id: 'mg__19190036', name: '咪咕欧美榜', bangid: '19190036' }, { id: 'mg__23189813', name: '咪咕日韩榜', bangid: '23189813' }, { id: 'mg__23190126', name: '咪咕彩铃榜', bangid: '23190126' }, { id: 'mg__15140045', name: '咪咕KTV榜', bangid: '15140045' }, { id: 'mg__15140034', name: '咪咕网络榜', bangid: '15140034' }, { id: 'mg__23217754', name: 'MV榜', bangid: '23217754' }, { id: 'mg__23218151', name: '新专辑榜', bangid: '23218151' }, { id: 'mg__21958042', name: 'iTunes榜', bangid: '21958042' }, { id: 'mg__21975570', name: 'billboard榜', bangid: '21975570' }, { id: 'mg__22272815', name: '台湾Hito中文榜', bangid: '22272815' }, { id: 'mg__22272904', name: '中国TOP排行榜', bangid: '22272904' }, { id: 'mg__22272943', name: '韩国Melon榜', bangid: '22272943' }, { id: 'mg__22273437', name: '英国UK榜', bangid: '22273437' }]
|
// const boardList = [{ id: 'mg__27553319', name: '咪咕尖叫新歌榜', bangid: '27553319' }, { id: 'mg__27186466', name: '咪咕尖叫热歌榜', bangid: '27186466' }, { id: 'mg__27553408', name: '咪咕尖叫原创榜', bangid: '27553408' }, { id: 'mg__23189800', name: '咪咕港台榜', bangid: '23189800' }, { id: 'mg__23189399', name: '咪咕内地榜', bangid: '23189399' }, { id: 'mg__19190036', name: '咪咕欧美榜', bangid: '19190036' }, { id: 'mg__23189813', name: '咪咕日韩榜', bangid: '23189813' }, { id: 'mg__23190126', name: '咪咕彩铃榜', bangid: '23190126' }, { id: 'mg__15140045', name: '咪咕KTV榜', bangid: '15140045' }, { id: 'mg__15140034', name: '咪咕网络榜', bangid: '15140034' }, { id: 'mg__23217754', name: 'MV榜', bangid: '23217754' }, { id: 'mg__23218151', name: '新专辑榜', bangid: '23218151' }, { id: 'mg__21958042', name: 'iTunes榜', bangid: '21958042' }, { id: 'mg__21975570', name: 'billboard榜', bangid: '21975570' }, { id: 'mg__22272815', name: '台湾Hito中文榜', bangid: '22272815' }, { id: 'mg__22272904', name: '中国TOP排行榜', bangid: '22272904' }, { id: 'mg__22272943', name: '韩国Melon榜', bangid: '22272943' }, { id: 'mg__22273437', name: '英国UK榜', bangid: '22273437' }]
|
||||||
|
|
||||||
@ -144,7 +143,7 @@ export default {
|
|||||||
return this.getData(this.getUrl(bangid, page)).then(({ statusCode, body }) => {
|
return this.getData(this.getUrl(bangid, page)).then(({ statusCode, body }) => {
|
||||||
// console.log(body)
|
// console.log(body)
|
||||||
if (statusCode !== 200 || body.code !== this.successCode) return this.getList(bangid, page, retryNum)
|
if (statusCode !== 200 || body.code !== this.successCode) return this.getList(bangid, page, retryNum)
|
||||||
const list = filterMusicInfoData(body.columnInfo.contents.map(m => m.objectInfo))
|
const list = filterMusicInfoList(body.columnInfo.contents.map(m => m.objectInfo))
|
||||||
return {
|
return {
|
||||||
total: list.length,
|
total: list.length,
|
||||||
list,
|
list,
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import { getMusicInfo } from './musicInfo'
|
import { getMusicInfo } from './musicInfo'
|
||||||
import { decrypt } from './mrc'
|
import { decrypt } from './utils/mrc'
|
||||||
|
|
||||||
const mrcTools = {
|
const mrcTools = {
|
||||||
rxps: {
|
rxps: {
|
||||||
|
|||||||
@ -1,15 +1,25 @@
|
|||||||
import { httpFetch } from '../../request'
|
|
||||||
import { sizeFormate } from '../../index'
|
import { sizeFormate } from '../../index'
|
||||||
|
import { createHttpFetch } from './utils'
|
||||||
|
import { formatSingerName } from '../utils'
|
||||||
|
|
||||||
const getSinger = (singers) => {
|
const createGetMusicInfosTask = (ids, resType = 2) => {
|
||||||
let arr = []
|
let list = ids
|
||||||
singers?.forEach(singer => {
|
let tasks = []
|
||||||
arr.push(singer.name)
|
while (list.length) {
|
||||||
})
|
tasks.push(list.slice(0, 100))
|
||||||
return arr.join('、')
|
if (list.length < 100) break
|
||||||
|
list = list.slice(100)
|
||||||
|
}
|
||||||
|
let url = `https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceType=${resType}`
|
||||||
|
return tasks.map(task => createHttpFetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
form: {
|
||||||
|
resourceId: task.join('|'),
|
||||||
|
},
|
||||||
|
}).then(data => data.resource))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const filterMusicInfoData = (rawList) => {
|
export const filterMusicInfoList = (rawList) => {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
let ids = new Set()
|
let ids = new Set()
|
||||||
const list = []
|
const list = []
|
||||||
@ -55,7 +65,7 @@ export const filterMusicInfoData = (rawList) => {
|
|||||||
const intervalTest = /(\d\d:\d\d)$/.test(item.length)
|
const intervalTest = /(\d\d:\d\d)$/.test(item.length)
|
||||||
|
|
||||||
list.push({
|
list.push({
|
||||||
singer: getSinger(item.artists),
|
singer: formatSingerName(item.artists, 'name'),
|
||||||
name: item.songName,
|
name: item.songName,
|
||||||
albumName: item.album,
|
albumName: item.album,
|
||||||
albumId: item.albumId,
|
albumId: item.albumId,
|
||||||
@ -74,27 +84,13 @@ export const filterMusicInfoData = (rawList) => {
|
|||||||
typeUrl: {},
|
typeUrl: {},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
// console.log(list)
|
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getMusicInfos = (copyrightIds, retry = 0) => {
|
export const getMusicInfo = async(copyrightId) => {
|
||||||
if (++retry > 2) return Promise.reject(new Error('Failed to get music info try max'))
|
return getMusicInfos([copyrightId]).then(data => data[0])
|
||||||
return httpFetch('https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceType=2', {
|
|
||||||
method: 'POST',
|
|
||||||
form: {
|
|
||||||
resourceId: copyrightIds.join('|'),
|
|
||||||
},
|
|
||||||
}).promise.then(({ body }) => {
|
|
||||||
if (!body) return getMusicInfos(copyrightIds, retry)
|
|
||||||
if (body.code !== '000000') return Promise.reject(new Error('Failed to get music info'))
|
|
||||||
return filterMusicInfoData(body.resource)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getMusicInfo = (copyrightId) => {
|
export const getMusicInfos = async(copyrightIds) => {
|
||||||
return getMusicInfos([copyrightId]).then(([musicInfo]) => {
|
return filterMusicInfoList(await Promise.all(createGetMusicInfosTask(copyrightIds)).then(data => data))
|
||||||
if (musicInfo) return musicInfo
|
|
||||||
throw new Error('failed')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
import { httpFetch } from '../../request'
|
|
||||||
import { sizeFormate, formatPlayTime } from '../../index'
|
import { sizeFormate, formatPlayTime } from '../../index'
|
||||||
import { toMD5 } from '../utils'
|
import { createHttpFetch } from './utils'
|
||||||
|
import { formatSingerName, toMD5 } from '../utils'
|
||||||
|
|
||||||
const sign = (time, str) => {
|
const searchSign = (timeStr, str, deviceId) => {
|
||||||
const deviceId = '963B7AA0D21511ED807EE5846EC87D20'
|
const key = '6cdc72a439cef99a3418d2a78aa28c73'
|
||||||
const signatureMd5 = '6cdc72a439cef99a3418d2a78aa28c73'
|
return toMD5(`${str}${key}yyapp2d16148780a1dcc7408e06336b98cfd50${deviceId}${timeStr}`)
|
||||||
const sign = toMD5(`${str}${signatureMd5}yyapp2d16148780a1dcc7408e06336b98cfd50${deviceId}${time}`)
|
|
||||||
return { sign, deviceId }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -14,217 +12,115 @@ export default {
|
|||||||
total: 0,
|
total: 0,
|
||||||
page: 0,
|
page: 0,
|
||||||
allPage: 1,
|
allPage: 1,
|
||||||
|
deviceId: '963B7AA0D21511ED807EE5846EC87D20',
|
||||||
// 旧版API
|
|
||||||
// musicSearch(str, page, limit) {
|
|
||||||
// const searchRequest = httpFetch(`http://pd.musicapp.migu.cn/MIGUM2.0/v1.0/content/search_all.do?ua=Android_migu&version=5.0.1&text=${encodeURIComponent(str)}&pageNo=${page}&pageSize=${limit}&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, {
|
|
||||||
// searchRequest = httpFetch(`http://pd.musicapp.migu.cn/MIGUM2.0/v1.0/content/search_all.do?ua=Android_migu&version=5.0.1&text=${encodeURIComponent(str)}&pageNo=${page}&pageSize=${limit}&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, {
|
|
||||||
// searchRequest = httpFetch(`http://jadeite.migu.cn:7090/music_search/v2/search/searchAll?sid=4f87090d01c84984a11976b828e2b02c18946be88a6b4c47bcdc92fbd40762db&isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, {
|
|
||||||
// searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`)
|
|
||||||
// // searchRequest = httpFetch(`http://jadeite.migu.cn:7090/music_search/v2/search/searchAll?sid=4f87090d01c84984a11976b828e2b02c18946be88a6b4c47bcdc92fbd40762db&isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, {
|
|
||||||
// headers: {
|
|
||||||
// // sign: 'c3b7ae985e2206e97f1b2de8f88691e2',
|
|
||||||
// // timestamp: 1578225871982,
|
|
||||||
// // appId: 'yyapp2',
|
|
||||||
// // mode: 'android',
|
|
||||||
// // ua: 'Android_migu',
|
|
||||||
// // version: '6.9.4',
|
|
||||||
// osVersion: 'android 7.0',
|
|
||||||
// 'User-Agent': 'okhttp/3.9.1',
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// // searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`)
|
|
||||||
// return searchRequest.promise.then(({ body }) => body)
|
|
||||||
// },
|
|
||||||
// handleResult(rawData) {
|
|
||||||
// // console.log(rawData)
|
|
||||||
// let ids = new Set()
|
|
||||||
// const list = []
|
|
||||||
// rawData.forEach(item => {
|
|
||||||
// if (ids.has(item.id)) return
|
|
||||||
// ids.add(item.id)
|
|
||||||
// const types = []
|
|
||||||
// const _types = {}
|
|
||||||
// item.newRateFormats && item.newRateFormats.forEach(type => {
|
|
||||||
// let size
|
|
||||||
// switch (type.formatType) {
|
|
||||||
// case 'PQ':
|
|
||||||
// size = sizeFormate(type.size ?? type.androidSize)
|
|
||||||
// types.push({ type: '128k', size })
|
|
||||||
// _types['128k'] = {
|
|
||||||
// size,
|
|
||||||
// }
|
|
||||||
// break
|
|
||||||
// case 'HQ':
|
|
||||||
// size = sizeFormate(type.size ?? type.androidSize)
|
|
||||||
// types.push({ type: '320k', size })
|
|
||||||
// _types['320k'] = {
|
|
||||||
// size,
|
|
||||||
// }
|
|
||||||
// break
|
|
||||||
// case 'SQ':
|
|
||||||
// size = sizeFormate(type.size ?? type.androidSize)
|
|
||||||
// types.push({ type: 'flac', size })
|
|
||||||
// _types.flac = {
|
|
||||||
// size,
|
|
||||||
// }
|
|
||||||
// break
|
|
||||||
// case 'ZQ':
|
|
||||||
// size = sizeFormate(type.size ?? type.androidSize)
|
|
||||||
// types.push({ type: 'flac24bit', size })
|
|
||||||
// _types.flac24bit = {
|
|
||||||
// size,
|
|
||||||
// }
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// const albumNInfo = item.albums && item.albums.length
|
|
||||||
// ? {
|
|
||||||
// id: item.albums[0].id,
|
|
||||||
// name: item.albums[0].name,
|
|
||||||
// }
|
|
||||||
// : {}
|
|
||||||
|
|
||||||
// list.push({
|
|
||||||
// singer: this.getSinger(item.singers),
|
|
||||||
// name: item.name,
|
|
||||||
// albumName: albumNInfo.name,
|
|
||||||
// albumId: albumNInfo.id,
|
|
||||||
// songmid: item.songId,
|
|
||||||
// copyrightId: item.copyrightId,
|
|
||||||
// source: 'mg',
|
|
||||||
// interval: null,
|
|
||||||
// img: item.imgItems && item.imgItems.length ? item.imgItems[0].img : null,
|
|
||||||
// lrc: null,
|
|
||||||
// lrcUrl: item.lyricUrl,
|
|
||||||
// mrcUrl: item.mrcurl,
|
|
||||||
// trcUrl: item.trcUrl,
|
|
||||||
// otherSource: null,
|
|
||||||
// types,
|
|
||||||
// _types,
|
|
||||||
// typeUrl: {},
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// return list
|
|
||||||
// },
|
|
||||||
|
|
||||||
musicSearch(str, page, limit) {
|
musicSearch(str, page, limit) {
|
||||||
const time = Date.now().toString()
|
// searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`)
|
||||||
const signData = sign(time, str)
|
const timeStr = Date.now().toString()
|
||||||
const searchRequest = httpFetch(`https://jadeite.migu.cn/music_search/v3/search/searchAll?isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, {
|
const signResult = searchSign(timeStr, str, this.deviceId)
|
||||||
|
return createHttpFetch(`https://jadeite.migu.cn/music_search/v3/search/searchAll?isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, {
|
||||||
headers: {
|
headers: {
|
||||||
uiVersion: 'A_music_3.6.1',
|
uiVersion: 'A_music_3.6.1',
|
||||||
deviceId: signData.deviceId,
|
deviceId: this.deviceId,
|
||||||
timestamp: time,
|
timestamp: timeStr,
|
||||||
sign: signData.sign,
|
sign: signResult,
|
||||||
channel: '0146921',
|
channel: '0146921',
|
||||||
'User-Agent': 'Mozilla/5.0 (Linux; U; Android 11.0.0; zh-cn; MI 11 Build/OPR1.170623.032) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
|
'User-Agent': 'Mozilla/5.0 (Linux; U; Android 11.0.0; zh-cn; MI 11 Build/OPR1.170623.032) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
|
||||||
},
|
},
|
||||||
})
|
}).then(body => body)
|
||||||
return searchRequest.promise.then(({ body }) => body)
|
|
||||||
},
|
},
|
||||||
getSinger(singers) {
|
filterList(raw) {
|
||||||
let arr = []
|
|
||||||
singers.forEach(singer => {
|
|
||||||
arr.push(singer.name)
|
|
||||||
})
|
|
||||||
return arr.join('、')
|
|
||||||
},
|
|
||||||
filterData(rawData) {
|
|
||||||
// console.log(rawData)
|
|
||||||
const list = []
|
|
||||||
const ids = new Set()
|
const ids = new Set()
|
||||||
|
const list = []
|
||||||
|
|
||||||
rawData.forEach(item => {
|
raw.forEach(item => {
|
||||||
item.forEach(data => {
|
if (!item.songId || !item.copyrightId || ids.has(item.copyrightId)) return
|
||||||
if (!data.songId || !data.copyrightId || ids.has(data.copyrightId)) return
|
ids.add(item.copyrightId)
|
||||||
ids.add(data.copyrightId)
|
|
||||||
|
|
||||||
const types = []
|
const types = []
|
||||||
const _types = {}
|
const _types = {}
|
||||||
data.audioFormats && data.audioFormats.forEach(type => {
|
item.audioFormats && item.audioFormats.forEach(type => {
|
||||||
let size
|
let size
|
||||||
switch (type.formatType) {
|
switch (type.formatType) {
|
||||||
case 'PQ':
|
case 'PQ':
|
||||||
size = sizeFormate(type.asize ?? type.isize)
|
size = sizeFormate(type.asize ?? type.isize)
|
||||||
types.push({ type: '128k', size })
|
types.push({ type: '128k', size })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
size,
|
size,
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'HQ':
|
case 'HQ':
|
||||||
size = sizeFormate(type.asize ?? type.isize)
|
size = sizeFormate(type.asize ?? type.isize)
|
||||||
types.push({ type: '320k', size })
|
types.push({ type: '320k', size })
|
||||||
_types['320k'] = {
|
_types['320k'] = {
|
||||||
size,
|
size,
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'SQ':
|
case 'SQ':
|
||||||
size = sizeFormate(type.asize ?? type.isize)
|
size = sizeFormate(type.asize ?? type.isize)
|
||||||
types.push({ type: 'flac', size })
|
types.push({ type: 'flac', size })
|
||||||
_types.flac = {
|
_types.flac = {
|
||||||
size,
|
size,
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'ZQ24':
|
case 'ZQ24':
|
||||||
size = sizeFormate(type.asize ?? type.isize)
|
size = sizeFormate(type.asize ?? type.isize)
|
||||||
types.push({ type: 'flac24bit', size })
|
types.push({ type: 'flac24bit', size })
|
||||||
_types.flac24bit = {
|
_types.flac24bit = {
|
||||||
size,
|
size,
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let img = data.img3 || data.img2 || data.img1 || null
|
let img = item.img3 || item.img2 || item.img1 || null
|
||||||
if (img && !/https?:/.test(data.img3)) img = 'http://d.musicapp.migu.cn' + img
|
if (img && !/https?:/.test(item.img3)) img = 'http://d.musicapp.migu.cn' + img
|
||||||
|
|
||||||
list.push({
|
list.push({
|
||||||
singer: this.getSinger(data.singerList),
|
singer: formatSingerName(item.singerList, 'name'),
|
||||||
name: data.name,
|
name: item.name,
|
||||||
albumName: data.album,
|
albumName: item.album,
|
||||||
albumId: data.albumId,
|
albumId: item.albumId,
|
||||||
songmid: data.songId,
|
songmid: item.songId,
|
||||||
copyrightId: data.copyrightId,
|
copyrightId: item.copyrightId,
|
||||||
source: 'mg',
|
source: 'mg',
|
||||||
interval: formatPlayTime(data.duration),
|
interval: formatPlayTime(item.duration),
|
||||||
img,
|
img,
|
||||||
lrc: null,
|
lrc: null,
|
||||||
lrcUrl: data.lrcUrl,
|
lrcUrl: item.lrcUrl,
|
||||||
mrcUrl: data.mrcurl,
|
mrcUrl: item.mrcurl,
|
||||||
trcUrl: data.trcUrl,
|
trcUrl: item.trcUrl,
|
||||||
types,
|
types,
|
||||||
_types,
|
_types,
|
||||||
typeUrl: {},
|
typeUrl: {},
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return list
|
return list
|
||||||
},
|
},
|
||||||
|
handleResult(rawData) {
|
||||||
|
return this.filterList(rawData.flat())
|
||||||
|
},
|
||||||
search(str, page = 1, limit, retryNum = 0) {
|
search(str, page = 1, limit, retryNum = 0) {
|
||||||
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
|
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
|
||||||
if (limit == null) limit = this.limit
|
if (limit == null) limit = this.limit
|
||||||
// http://newlyric.kuwo.cn/newlyric.lrc?62355680
|
|
||||||
return this.musicSearch(str, page, limit).then(result => {
|
|
||||||
// console.log(result)
|
|
||||||
if (!result || result.code !== '000000') return Promise.reject(new Error(result ? result.info : '搜索失败'))
|
|
||||||
const songResultData = result.songResultData || { resultList: [], totalCount: 0 }
|
|
||||||
|
|
||||||
let list = this.filterData(songResultData.resultList)
|
return this.musicSearch(str, page, limit).then(data => {
|
||||||
|
const songResultData = data.songResultData || { resultList: [], totalCount: 0 }
|
||||||
|
|
||||||
|
let list = this.handleResult(songResultData.resultList)
|
||||||
if (list == null) return this.search(str, page, limit, retryNum)
|
if (list == null) return this.search(str, page, limit, retryNum)
|
||||||
|
|
||||||
this.total = parseInt(songResultData.totalCount)
|
this.total = parseInt(songResultData.totalCount)
|
||||||
this.page = page
|
this.page = page
|
||||||
this.allPage = Math.ceil(this.total / limit)
|
this.allPage = Math.ceil(this.total / limit)
|
||||||
|
|
||||||
return {
|
return Promise.resolve({
|
||||||
list,
|
list,
|
||||||
allPage: this.allPage,
|
allPage: this.allPage,
|
||||||
limit,
|
limit,
|
||||||
total: this.total,
|
total: this.total,
|
||||||
source: 'mg',
|
source: 'mg',
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -1,5 +1,5 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../../request'
|
||||||
import { formatPlayTime } from '../../index'
|
import { formatPlayTime } from '../../../index'
|
||||||
// import { sizeFormate } from '../../index'
|
// import { sizeFormate } from '../../index'
|
||||||
|
|
||||||
|
|
||||||
25
src/renderer/utils/musicSdk/mg/tipSearch.js
Normal file
25
src/renderer/utils/musicSdk/mg/tipSearch.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { createHttpFetch } from './utils'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
requestObj: null,
|
||||||
|
cancelTipSearch() {
|
||||||
|
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||||
|
},
|
||||||
|
tipSearchBySong(str) {
|
||||||
|
this.cancelTipSearch()
|
||||||
|
this.requestObj = createHttpFetch(`https://music.migu.cn/v3/api/search/suggest?keyword=${encodeURIComponent(str)}`, {
|
||||||
|
headers: {
|
||||||
|
referer: 'https://music.migu.cn/v3',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return this.requestObj.then(body => {
|
||||||
|
return body.songs
|
||||||
|
})
|
||||||
|
},
|
||||||
|
handleResult(rawData) {
|
||||||
|
return rawData.map(info => `${info.name} - ${info.singerName}`)
|
||||||
|
},
|
||||||
|
async search(str) {
|
||||||
|
return this.tipSearchBySong(str).then(result => this.handleResult(result))
|
||||||
|
},
|
||||||
|
}
|
||||||
29
src/renderer/utils/musicSdk/mg/utils/index.js
Normal file
29
src/renderer/utils/musicSdk/mg/utils/index.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { httpFetch } from '../../../request'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个适用于MG的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)
|
||||||
|
}
|
||||||
|
if (result.statusCode !== 200 ||
|
||||||
|
(
|
||||||
|
(result.body.code !== undefined
|
||||||
|
? result.body.code
|
||||||
|
: result.body.returnCode !== undefined
|
||||||
|
? result.body.returnCode
|
||||||
|
: result.body.code
|
||||||
|
) !== '000000')
|
||||||
|
) return createHttpFetch(url, options, ++retryNum)
|
||||||
|
if (result.body.data) return result.body.data
|
||||||
|
return result.body
|
||||||
|
}
|
||||||
@ -5,8 +5,10 @@ import musicSearch from './musicSearch'
|
|||||||
import { apis } from '../api-source'
|
import { apis } from '../api-source'
|
||||||
import hotSearch from './hotSearch'
|
import hotSearch from './hotSearch'
|
||||||
import comment from './comment'
|
import comment from './comment'
|
||||||
|
import tipSearch from './tipSearch'
|
||||||
|
|
||||||
const tx = {
|
const tx = {
|
||||||
|
tipSearch,
|
||||||
leaderboard,
|
leaderboard,
|
||||||
songList,
|
songList,
|
||||||
musicSearch,
|
musicSearch,
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import { formatPlayTime, sizeFormate } from '../../index'
|
import { formatPlayTime, sizeFormate } from '../../index'
|
||||||
|
import { formatSingerName } from '../utils'
|
||||||
|
|
||||||
let boardList = [{ id: 'tx__4', name: '流行指数榜', bangid: '4' }, { id: 'tx__26', name: '热歌榜', bangid: '26' }, { id: 'tx__27', name: '新歌榜', bangid: '27' }, { id: 'tx__62', name: '飙升榜', bangid: '62' }, { id: 'tx__58', name: '说唱榜', bangid: '58' }, { id: 'tx__57', name: '喜力电音榜', bangid: '57' }, { id: 'tx__28', name: '网络歌曲榜', bangid: '28' }, { id: 'tx__5', name: '内地榜', bangid: '5' }, { id: 'tx__3', name: '欧美榜', bangid: '3' }, { id: 'tx__59', name: '香港地区榜', bangid: '59' }, { id: 'tx__16', name: '韩国榜', bangid: '16' }, { id: 'tx__60', name: '抖快榜', bangid: '60' }, { id: 'tx__29', name: '影视金曲榜', bangid: '29' }, { id: 'tx__17', name: '日本榜', bangid: '17' }, { id: 'tx__52', name: '腾讯音乐人原创榜', bangid: '52' }, { id: 'tx__36', name: 'K歌金曲榜', bangid: '36' }, { id: 'tx__61', name: '台湾地区榜', bangid: '61' }, { id: 'tx__63', name: 'DJ舞曲榜', bangid: '63' }, { id: 'tx__64', name: '综艺新歌榜', bangid: '64' }, { id: 'tx__65', name: '国风热歌榜', bangid: '65' }, { id: 'tx__67', name: '听歌识曲榜', bangid: '67' }, { id: 'tx__72', name: '动漫音乐榜', bangid: '72' }, { id: 'tx__73', name: '游戏音乐榜', bangid: '73' }, { id: 'tx__75', name: '有声榜', bangid: '75' }, { id: 'tx__131', name: '校园音乐人排行榜', bangid: '131' }]
|
let boardList = [{ id: 'tx__4', name: '流行指数榜', bangid: '4' }, { id: 'tx__26', name: '热歌榜', bangid: '26' }, { id: 'tx__27', name: '新歌榜', bangid: '27' }, { id: 'tx__62', name: '飙升榜', bangid: '62' }, { id: 'tx__58', name: '说唱榜', bangid: '58' }, { id: 'tx__57', name: '喜力电音榜', bangid: '57' }, { id: 'tx__28', name: '网络歌曲榜', bangid: '28' }, { id: 'tx__5', name: '内地榜', bangid: '5' }, { id: 'tx__3', name: '欧美榜', bangid: '3' }, { id: 'tx__59', name: '香港地区榜', bangid: '59' }, { id: 'tx__16', name: '韩国榜', bangid: '16' }, { id: 'tx__60', name: '抖快榜', bangid: '60' }, { id: 'tx__29', name: '影视金曲榜', bangid: '29' }, { id: 'tx__17', name: '日本榜', bangid: '17' }, { id: 'tx__52', name: '腾讯音乐人原创榜', bangid: '52' }, { id: 'tx__36', name: 'K歌金曲榜', bangid: '36' }, { id: 'tx__61', name: '台湾地区榜', bangid: '61' }, { id: 'tx__63', name: 'DJ舞曲榜', bangid: '63' }, { id: 'tx__64', name: '综艺新歌榜', bangid: '64' }, { id: 'tx__65', name: '国风热歌榜', bangid: '65' }, { id: 'tx__67', name: '听歌识曲榜', bangid: '67' }, { id: 'tx__72', name: '动漫音乐榜', bangid: '72' }, { id: 'tx__73', name: '游戏音乐榜', bangid: '73' }, { id: 'tx__75', name: '有声榜', bangid: '75' }, { id: 'tx__131', name: '校园音乐人排行榜', bangid: '131' }]
|
||||||
|
|
||||||
@ -104,13 +105,6 @@ export default {
|
|||||||
const requestDataObj = httpFetch(url)
|
const requestDataObj = httpFetch(url)
|
||||||
return requestDataObj.promise
|
return requestDataObj.promise
|
||||||
},
|
},
|
||||||
getSinger(singers) {
|
|
||||||
let arr = []
|
|
||||||
singers.forEach(singer => {
|
|
||||||
arr.push(singer.name)
|
|
||||||
})
|
|
||||||
return arr.join('、')
|
|
||||||
},
|
|
||||||
filterData(rawList) {
|
filterData(rawList) {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
return rawList.map(item => {
|
return rawList.map(item => {
|
||||||
@ -146,7 +140,7 @@ export default {
|
|||||||
}
|
}
|
||||||
// types.reverse()
|
// types.reverse()
|
||||||
return {
|
return {
|
||||||
singer: this.getSinger(item.singer),
|
singer: formatSingerName(item.singer, 'name'),
|
||||||
name: item.name,
|
name: item.name,
|
||||||
albumName: item.album.name,
|
albumName: item.album.name,
|
||||||
albumId: item.album.mid,
|
albumId: item.album.mid,
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
// import '../../polyfill/array.find'
|
|
||||||
|
|
||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import { formatPlayTime, sizeFormate } from '../../index'
|
import { formatPlayTime, sizeFormate } from '../../index'
|
||||||
// import { debug } from '../../utils/env'
|
import { formatSingerName } from '../utils'
|
||||||
// import { formatSinger } from './util'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
limit: 50,
|
limit: 50,
|
||||||
@ -52,13 +49,6 @@ export default {
|
|||||||
return body.req.data
|
return body.req.data
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getSinger(singers) {
|
|
||||||
let arr = []
|
|
||||||
singers.forEach(singer => {
|
|
||||||
arr.push(singer.name)
|
|
||||||
})
|
|
||||||
return arr.join('、')
|
|
||||||
},
|
|
||||||
handleResult(rawList) {
|
handleResult(rawList) {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
const list = []
|
const list = []
|
||||||
@ -104,7 +94,7 @@ export default {
|
|||||||
albumId = item.album.mid
|
albumId = item.album.mid
|
||||||
}
|
}
|
||||||
list.push({
|
list.push({
|
||||||
singer: this.getSinger(item.singer),
|
singer: formatSingerName(item.singer, 'name'),
|
||||||
name: item.name,
|
name: item.name,
|
||||||
albumName,
|
albumName,
|
||||||
albumId,
|
albumId,
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import { decodeName, formatPlayTime, sizeFormate, dateFormat } from '../../index'
|
import { decodeName, formatPlayTime, sizeFormate, dateFormat, formatPlayCount } from '../../index'
|
||||||
|
import { formatSingerName } from '../utils'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
_requestObj_tags: null,
|
_requestObj_tags: null,
|
||||||
@ -125,20 +126,10 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 格式化播放数量
|
|
||||||
* @param {*} num
|
|
||||||
*/
|
|
||||||
formatPlayCount(num) {
|
|
||||||
if (num > 100000000) return parseInt(num / 10000000) / 10 + '亿'
|
|
||||||
if (num > 10000) return parseInt(num / 1000) / 10 + '万'
|
|
||||||
return num
|
|
||||||
},
|
|
||||||
filterList(data, page) {
|
filterList(data, page) {
|
||||||
return {
|
return {
|
||||||
list: data.v_playlist.map(item => ({
|
list: data.v_playlist.map(item => ({
|
||||||
play_count: this.formatPlayCount(item.access_num),
|
play_count: formatPlayCount(item.access_num),
|
||||||
id: item.tid,
|
id: item.tid,
|
||||||
author: item.creator_info.nick,
|
author: item.creator_info.nick,
|
||||||
name: item.title,
|
name: item.title,
|
||||||
@ -159,7 +150,7 @@ export default {
|
|||||||
// console.log(content.v_item)
|
// console.log(content.v_item)
|
||||||
return {
|
return {
|
||||||
list: content.v_item.map(({ basic }) => ({
|
list: content.v_item.map(({ basic }) => ({
|
||||||
play_count: this.formatPlayCount(basic.play_cnt),
|
play_count: formatPlayCount(basic.play_cnt),
|
||||||
id: basic.tid,
|
id: basic.tid,
|
||||||
author: basic.creator.nick,
|
author: basic.creator.nick,
|
||||||
name: basic.title,
|
name: basic.title,
|
||||||
@ -228,17 +219,10 @@ export default {
|
|||||||
img: cdlist.logo,
|
img: cdlist.logo,
|
||||||
desc: decodeName(cdlist.desc).replace(/<br>/g, '\n'),
|
desc: decodeName(cdlist.desc).replace(/<br>/g, '\n'),
|
||||||
author: cdlist.nickname,
|
author: cdlist.nickname,
|
||||||
play_count: this.formatPlayCount(cdlist.visitnum),
|
play_count: formatPlayCount(cdlist.visitnum),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getSinger(singers) {
|
|
||||||
let arr = []
|
|
||||||
singers.forEach(singer => {
|
|
||||||
arr.push(singer.name)
|
|
||||||
})
|
|
||||||
return arr.join('、')
|
|
||||||
},
|
|
||||||
filterListDetail(rawList) {
|
filterListDetail(rawList) {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
return rawList.map(item => {
|
return rawList.map(item => {
|
||||||
@ -274,7 +258,7 @@ export default {
|
|||||||
}
|
}
|
||||||
// types.reverse()
|
// types.reverse()
|
||||||
return {
|
return {
|
||||||
singer: this.getSinger(item.singer),
|
singer: formatSingerName(item.singer, 'name'),
|
||||||
name: item.name,
|
name: item.name,
|
||||||
albumName: item.album.name,
|
albumName: item.album.name,
|
||||||
albumId: item.album.mid,
|
albumId: item.album.mid,
|
||||||
@ -319,7 +303,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
list: body.data.list.map(item => {
|
list: body.data.list.map(item => {
|
||||||
return {
|
return {
|
||||||
play_count: this.formatPlayCount(item.listennum),
|
play_count: formatPlayCount(item.listennum),
|
||||||
id: item.dissid,
|
id: item.dissid,
|
||||||
author: item.creator.name,
|
author: item.creator.name,
|
||||||
name: item.dissname,
|
name: item.dissname,
|
||||||
|
|||||||
@ -1,30 +1,27 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
regExps: {
|
|
||||||
relWord: /RELWORD=(.+)/,
|
|
||||||
},
|
|
||||||
requestObj: null,
|
requestObj: null,
|
||||||
tempSearch(str) {
|
cancelTipSearch() {
|
||||||
this.cancelTempSearch()
|
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||||
this.requestObj = httpFetch(`https://c.y.qq.com/splcloud/fcgi-bin/smartbox_new.fcg?is_xml=0&format=json&key=${encodeURIComponent(str)}&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0`, {
|
},
|
||||||
|
tipSearchBySong(str) {
|
||||||
|
this.cancelTipSearch()
|
||||||
|
this.requestObj = httpFetch(`https://c.y.qq.com/splcloud/fcgi-bin/smartbox_new.fcg?&format=json&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=1&uin=0&hostUin=0&is_xml=0&key=${encodeURIComponent(str)}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Referer: 'https://y.qq.com/portal/player.html',
|
origin: 'https://y.qq.com/',
|
||||||
|
referer: 'https://y.qq.com/',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return this.requestObj.promise.then(({ statusCode, body }) => {
|
return this.requestObj.promise.then(({ statusCode, body }) => {
|
||||||
if (statusCode != 200 || body.code != 0) return Promise.reject(new Error('请求失败'))
|
if (statusCode != 200 || body.code != 0) return Promise.reject(new Error('请求失败'))
|
||||||
return body.data
|
return body.data.song.itemlist
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleResult(rawData) {
|
handleResult(rawData) {
|
||||||
return rawData.map(info => `${info.name} - ${info.singer}`)
|
return rawData.map(info => `${info.name} - ${info.singer}`)
|
||||||
},
|
},
|
||||||
cancelTempSearch() {
|
|
||||||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
|
||||||
},
|
|
||||||
async search(str) {
|
async search(str) {
|
||||||
return this.tempSearch(str).then(result => this.handleResult(result.song.itemlist))
|
return this.tipSearchBySong(str).then(result => this.handleResult(result))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import crypto from 'crypto'
|
import crypto from 'crypto'
|
||||||
import dns from 'dns'
|
import dns from 'dns'
|
||||||
|
import { decodeName } from '@common/utils/common'
|
||||||
|
|
||||||
export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex')
|
export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex')
|
||||||
|
|
||||||
@ -21,9 +22,36 @@ export const getHostIp = hostname => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const dnsLookup = (hostname, options, callback) => {
|
export const dnsLookup = (hostname, options, callback) => {
|
||||||
const result = getHostIp(hostname)
|
const result = getHostIp(hostname)
|
||||||
if (result) return callback(null, result.address, result.family)
|
if (result) return callback(null, result.address, result.family)
|
||||||
|
|
||||||
dns.lookup(hostname, options, callback)
|
dns.lookup(hostname, options, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化歌手
|
||||||
|
* @param singers 歌手数组
|
||||||
|
* @param obj 读取的数据
|
||||||
|
* @param join 插入的字符
|
||||||
|
*/
|
||||||
|
export const formatSingerName = (singers, obj = 'name', join = '、') => {
|
||||||
|
if (typeof singers === 'string') {
|
||||||
|
try {
|
||||||
|
singers = JSON.parse(singers)
|
||||||
|
} catch (err) {
|
||||||
|
return decodeName(singers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Array.isArray(singers)) return decodeName(singers)
|
||||||
|
|
||||||
|
const singer = []
|
||||||
|
singers.forEach(item => {
|
||||||
|
let name = item[obj]
|
||||||
|
if (!name) return
|
||||||
|
singer.push(name)
|
||||||
|
})
|
||||||
|
return decodeName(singer.join(join))
|
||||||
|
}
|
||||||
|
|||||||
@ -6,8 +6,10 @@ import musicSearch from './musicSearch'
|
|||||||
import songList from './songList'
|
import songList from './songList'
|
||||||
import hotSearch from './hotSearch'
|
import hotSearch from './hotSearch'
|
||||||
import comment from './comment'
|
import comment from './comment'
|
||||||
|
import tipSearch from './tipSearch'
|
||||||
|
|
||||||
const wy = {
|
const wy = {
|
||||||
|
tipSearch,
|
||||||
leaderboard,
|
leaderboard,
|
||||||
musicSearch,
|
musicSearch,
|
||||||
songList,
|
songList,
|
||||||
|
|||||||
@ -6,30 +6,30 @@ const topList = [{ id: 'wy__19723756', name: '飙升榜', bangid: '19723756' },
|
|||||||
{ id: 'wy__3779629', name: '新歌榜', bangid: '3779629' },
|
{ id: 'wy__3779629', name: '新歌榜', bangid: '3779629' },
|
||||||
{ id: 'wy__2884035', name: '原创榜', bangid: '2884035' },
|
{ id: 'wy__2884035', name: '原创榜', bangid: '2884035' },
|
||||||
{ id: 'wy__3778678', name: '热歌榜', bangid: '3778678' },
|
{ id: 'wy__3778678', name: '热歌榜', bangid: '3778678' },
|
||||||
{ id: 'wy__991319590', name: '云音乐说唱榜', bangid: '991319590' },
|
{ id: 'wy__991319590', name: '说唱榜', bangid: '991319590' },
|
||||||
{ id: 'wy__71384707', name: '云音乐古典榜', bangid: '71384707' },
|
{ id: 'wy__71384707', name: '古典榜', bangid: '71384707' },
|
||||||
{ id: 'wy__1978921795', name: '云音乐电音榜', bangid: '1978921795' },
|
{ id: 'wy__1978921795', name: '电音榜', bangid: '1978921795' },
|
||||||
{ id: 'wy__5453912201', name: '黑胶VIP爱听榜', bangid: '5453912201' },
|
{ id: 'wy__5453912201', name: '黑胶VIP爱听榜', bangid: '5453912201' },
|
||||||
{ id: 'wy__71385702', name: '云音乐ACG榜', bangid: '71385702' },
|
{ id: 'wy__71385702', name: 'ACG榜', bangid: '71385702' },
|
||||||
{ id: 'wy__745956260', name: '云音乐韩语榜', bangid: '745956260' },
|
{ id: 'wy__745956260', name: '韩语榜', bangid: '745956260' },
|
||||||
{ id: 'wy__10520166', name: '云音乐国电榜', bangid: '10520166' },
|
{ id: 'wy__10520166', name: '国电榜', bangid: '10520166' },
|
||||||
{ id: 'wy__180106', name: 'UK排行榜周榜', bangid: '180106' },
|
{ id: 'wy__180106', name: 'UK排行榜周榜', bangid: '180106' },
|
||||||
{ id: 'wy__60198', name: '美国Billboard榜', bangid: '60198' },
|
{ id: 'wy__60198', name: '美国Billboard榜', bangid: '60198' },
|
||||||
{ id: 'wy__3812895', name: 'Beatport全球电子舞曲榜', bangid: '3812895' },
|
{ id: 'wy__3812895', name: 'Beatport全球电子舞曲榜', bangid: '3812895' },
|
||||||
{ id: 'wy__21845217', name: 'KTV唛榜', bangid: '21845217' },
|
{ id: 'wy__21845217', name: 'KTV唛榜', bangid: '21845217' },
|
||||||
{ id: 'wy__60131', name: '日本Oricon榜', bangid: '60131' },
|
{ id: 'wy__60131', name: '日本Oricon榜', bangid: '60131' },
|
||||||
{ id: 'wy__2809513713', name: '云音乐欧美热歌榜', bangid: '2809513713' },
|
{ id: 'wy__2809513713', name: '欧美热歌榜', bangid: '2809513713' },
|
||||||
{ id: 'wy__2809577409', name: '云音乐欧美新歌榜', bangid: '2809577409' },
|
{ id: 'wy__2809577409', name: '欧美新歌榜', bangid: '2809577409' },
|
||||||
{ id: 'wy__27135204', name: '法国 NRJ Vos Hits 周榜', bangid: '27135204' },
|
{ id: 'wy__27135204', name: '法国 NRJ Vos Hits 周榜', bangid: '27135204' },
|
||||||
{ id: 'wy__3001835560', name: '云音乐ACG动画榜', bangid: '3001835560' },
|
{ id: 'wy__3001835560', name: 'ACG动画榜', bangid: '3001835560' },
|
||||||
{ id: 'wy__3001795926', name: '云音乐ACG游戏榜', bangid: '3001795926' },
|
{ id: 'wy__3001795926', name: 'ACG游戏榜', bangid: '3001795926' },
|
||||||
{ id: 'wy__3001890046', name: '云音乐ACG VOCALOID榜', bangid: '3001890046' },
|
{ id: 'wy__3001890046', name: 'ACG VOCALOID榜', bangid: '3001890046' },
|
||||||
{ id: 'wy__3112516681', name: '中国新乡村音乐排行榜', bangid: '3112516681' },
|
{ id: 'wy__3112516681', name: '中国新乡村音乐排行榜', bangid: '3112516681' },
|
||||||
{ id: 'wy__5059644681', name: '云音乐日语榜', bangid: '5059644681' },
|
{ id: 'wy__5059644681', name: '日语榜', bangid: '5059644681' },
|
||||||
{ id: 'wy__5059633707', name: '云音乐摇滚榜', bangid: '5059633707' },
|
{ id: 'wy__5059633707', name: '摇滚榜', bangid: '5059633707' },
|
||||||
{ id: 'wy__5059642708', name: '云音乐国风榜', bangid: '5059642708' },
|
{ id: 'wy__5059642708', name: '国风榜', bangid: '5059642708' },
|
||||||
{ id: 'wy__5338990334', name: '潜力爆款榜', bangid: '5338990334' },
|
{ id: 'wy__5338990334', name: '潜力爆款榜', bangid: '5338990334' },
|
||||||
{ id: 'wy__5059661515', name: '云音乐民谣榜', bangid: '5059661515' },
|
{ id: 'wy__5059661515', name: '民谣榜', bangid: '5059661515' },
|
||||||
{ id: 'wy__6688069460', name: '听歌识曲榜', bangid: '6688069460' },
|
{ id: 'wy__6688069460', name: '听歌识曲榜', bangid: '6688069460' },
|
||||||
{ id: 'wy__6723173524', name: '网络热歌榜', bangid: '6723173524' },
|
{ id: 'wy__6723173524', name: '网络热歌榜', bangid: '6723173524' },
|
||||||
{ id: 'wy__6732051320', name: '俄语榜', bangid: '6732051320' },
|
{ id: 'wy__6732051320', name: '俄语榜', bangid: '6732051320' },
|
||||||
|
|||||||
@ -5,9 +5,10 @@
|
|||||||
|
|
||||||
import { weapi, linuxapi } from './utils/crypto'
|
import { weapi, linuxapi } from './utils/crypto'
|
||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import { formatPlayTime, sizeFormate, dateFormat } from '../../index'
|
import { formatPlayTime, sizeFormate, dateFormat, formatPlayCount } from '../../index'
|
||||||
import musicDetailApi from './musicDetail'
|
import musicDetailApi from './musicDetail'
|
||||||
import { eapiRequest } from './utils/index'
|
import { eapiRequest } from './utils/index'
|
||||||
|
import { formatSingerName } from '../utils'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
_requestObj_tags: null,
|
_requestObj_tags: null,
|
||||||
@ -31,22 +32,6 @@ export default {
|
|||||||
listDetailLink: /^.+(?:\?|&)id=(\d+)(?:&.*$|#.*$|$)/,
|
listDetailLink: /^.+(?:\?|&)id=(\d+)(?:&.*$|#.*$|$)/,
|
||||||
listDetailLink2: /^.+\/playlist\/(\d+)\/\d+\/.+$/,
|
listDetailLink2: /^.+\/playlist\/(\d+)\/\d+\/.+$/,
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* 格式化播放数量
|
|
||||||
* @param {*} num
|
|
||||||
*/
|
|
||||||
formatPlayCount(num) {
|
|
||||||
if (num > 100000000) return parseInt(num / 10000000) / 10 + '亿'
|
|
||||||
if (num > 10000) return parseInt(num / 1000) / 10 + '万'
|
|
||||||
return num
|
|
||||||
},
|
|
||||||
getSinger(singers) {
|
|
||||||
let arr = []
|
|
||||||
singers?.forEach(singer => {
|
|
||||||
arr.push(singer.name)
|
|
||||||
})
|
|
||||||
return arr.join('、')
|
|
||||||
},
|
|
||||||
|
|
||||||
async handleParseId(link, retryNum = 0) {
|
async handleParseId(link, retryNum = 0) {
|
||||||
if (retryNum > 2) throw new Error('link try max num')
|
if (retryNum > 2) throw new Error('link try max num')
|
||||||
@ -130,7 +115,7 @@ export default {
|
|||||||
total: body.playlist.trackIds.length,
|
total: body.playlist.trackIds.length,
|
||||||
source: 'wy',
|
source: 'wy',
|
||||||
info: {
|
info: {
|
||||||
play_count: this.formatPlayCount(body.playlist.playCount),
|
play_count: formatPlayCount(body.playlist.playCount),
|
||||||
name: body.playlist.name,
|
name: body.playlist.name,
|
||||||
img: body.playlist.coverImgUrl,
|
img: body.playlist.coverImgUrl,
|
||||||
desc: body.playlist.description,
|
desc: body.playlist.description,
|
||||||
@ -198,7 +183,7 @@ export default {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
list.push({
|
list.push({
|
||||||
singer: this.getSinger(item.ar),
|
singer: formatSingerName(item.ar, 'name'),
|
||||||
name: item.name ?? '',
|
name: item.name ?? '',
|
||||||
albumName: item.al?.name,
|
albumName: item.al?.name,
|
||||||
albumId: item.al?.id,
|
albumId: item.al?.id,
|
||||||
@ -232,7 +217,7 @@ export default {
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
return this._requestObj_list.promise.then(({ body }) => {
|
return this._requestObj_list.promise.then(({ body }) => {
|
||||||
console.log(body)
|
// console.log(body)
|
||||||
if (body.code !== this.successCode) return this.getList(sortId, tagId, page, ++tryNum)
|
if (body.code !== this.successCode) return this.getList(sortId, tagId, page, ++tryNum)
|
||||||
return {
|
return {
|
||||||
list: this.filterList(body.playlists),
|
list: this.filterList(body.playlists),
|
||||||
@ -246,7 +231,7 @@ export default {
|
|||||||
filterList(rawData) {
|
filterList(rawData) {
|
||||||
// console.log(rawData)
|
// console.log(rawData)
|
||||||
return rawData.map(item => ({
|
return rawData.map(item => ({
|
||||||
play_count: this.formatPlayCount(item.playCount),
|
play_count: formatPlayCount(item.playCount),
|
||||||
id: item.id,
|
id: item.id,
|
||||||
author: item.creator.nickname,
|
author: item.creator.nickname,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
|
|||||||
33
src/renderer/utils/musicSdk/wy/tipSearch.js
Normal file
33
src/renderer/utils/musicSdk/wy/tipSearch.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { httpFetch } from '../../request'
|
||||||
|
import { weapi } from './utils/crypto'
|
||||||
|
import { formatSingerName } from '../utils'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
requestObj: null,
|
||||||
|
cancelTipSearch() {
|
||||||
|
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||||
|
},
|
||||||
|
tipSearchBySong(str) {
|
||||||
|
this.cancelTipSearch()
|
||||||
|
this.requestObj = httpFetch('https://music.163.com/weapi/search/suggest/web', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
referer: 'https://music.163.com/',
|
||||||
|
origin: 'https://music.163.com/',
|
||||||
|
},
|
||||||
|
form: weapi({
|
||||||
|
s: str,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
return this.requestObj.promise.then(({ statusCode, body }) => {
|
||||||
|
if (statusCode != 200 || body.code != 200) return Promise.reject(new Error('请求失败'))
|
||||||
|
return body.result.songs
|
||||||
|
})
|
||||||
|
},
|
||||||
|
handleResult(rawData) {
|
||||||
|
return rawData.map(info => `${info.name} - ${formatSingerName(info.artists, 'name')}`)
|
||||||
|
},
|
||||||
|
async search(str) {
|
||||||
|
return this.tipSearchBySong(str).then(result => this.handleResult(result))
|
||||||
|
},
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user