This commit is contained in:
Folltoshe 2023-04-24 22:24:27 +08:00
commit f383f132e7
8 changed files with 1025 additions and 942 deletions

1169
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "lx-music-desktop",
"version": "2.2.1-beta.3",
"version": "2.2.1-beta.4",
"description": "一个免费的音乐查找助手",
"main": "./dist/main.js",
"productName": "lx-music-desktop",
@ -216,9 +216,9 @@
"@types/better-sqlite3": "^7.6.4",
"@types/needle": "^3.2.0",
"@types/tunnel": "^0.0.3",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"@volar/vue-language-plugin-pug": "^1.2.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"@volar/vue-language-plugin-pug": "^1.4.4",
"babel-loader": "^9.1.2",
"browserslist": "^4.21.5",
"chalk": "^4.1.2",
@ -233,9 +233,9 @@
"electron-builder": "^24.2.1",
"electron-debug": "^3.2.0",
"electron-devtools-installer": "^3.2.0",
"electron-to-chromium": "^1.4.363",
"electron-to-chromium": "^1.4.369",
"electron-updater": "^6.0.4",
"eslint": "^8.38.0",
"eslint": "^8.39.0",
"eslint-config-standard": "^17.0.0",
"eslint-config-standard-with-typescript": "^34.0.1",
"eslint-formatter-friendly": "github:lyswhut/eslint-friendly-formatter#2170d1320e2fad13615a9dcf229669f0bb473a53",
@ -243,14 +243,14 @@
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-vue": "^9.10.0",
"eslint-plugin-vue": "^9.11.0",
"eslint-webpack-plugin": "^4.0.1",
"html-webpack-plugin": "^5.5.0",
"html-webpack-plugin": "^5.5.1",
"less": "^4.1.3",
"less-loader": "^11.1.0",
"mini-css-extract-plugin": "^2.7.5",
"node-loader": "^2.0.0",
"postcss": "^8.4.21",
"postcss": "^8.4.23",
"postcss-loader": "^7.2.4",
"postcss-pxtorem": "^6.0.0",
"pug": "^3.0.2",
@ -260,16 +260,16 @@
"svg-sprite-loader": "^6.0.11",
"svg-transform-loader": "^2.0.13",
"svgo-loader": "^4.0.0",
"terser": "^5.16.9",
"terser": "^5.17.1",
"terser-webpack-plugin": "^5.3.7",
"ts-loader": "^9.4.2",
"typescript": "^5.0.4",
"vue-eslint-parser": "^9.1.1",
"vue-loader": "^17.0.1",
"vue-template-compiler": "^2.7.14",
"webpack": "^5.79.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.13.2",
"webpack": "^5.80.0",
"webpack-cli": "^5.0.2",
"webpack-dev-server": "^4.13.3",
"webpack-hot-middleware": "github:lyswhut/webpack-hot-middleware#329c4375134b89d39da23a56a94db651247c74a1",
"webpack-merge": "^5.8.0"
},
@ -285,7 +285,7 @@
"iconv-lite": "^0.6.3",
"image-size": "^1.0.2",
"jschardet": "^3.0.0",
"long": "^5.2.1",
"long": "^5.2.3",
"music-metadata": "^8.1.4",
"needle": "github:lyswhut/needle#93299ac841b7e9a9f82ca7279b88aaaeda404060",
"node-id3": "^0.2.6",

View File

@ -12,6 +12,7 @@
- 修复启用全局快捷键时与Media Session注册冲突的问题启用全局快捷键时不再注册媒体控制快捷键
- 修复mg搜索不显示时长的问题@Folltoshe
- 修复mg评论加载失败的问题@Folltoshe
- 修复对存在错误时间标签的歌词的解析
### 其他

View File

@ -1,9 +1,7 @@
const { getNow, TimeoutTools } = require('./utils')
const timeFieldExp = /^(?:\[[\d:.]+\])+/g
const timeExp = /[\d:.]+/g
const timeLabelRxp = /^(\[[\d:]+\.)0+(\d+\])/
const timeLabelFixRxp = /(?:\.0+|0+)$/
const timeExp = /\d{1,3}(:\d{1,3}){0,2}(?:\.\d{1,3})/g
const tagRegMap = {
title: 'ti',
artist: 'ar',
@ -14,6 +12,15 @@ const tagRegMap = {
const timeoutTools = new TimeoutTools()
const t_rxp_1 = /^0+(\d+)/
const t_rxp_2 = /:0+(\d+)/g
const t_rxp_3 = /\.0+(\d+)/
const formatTimeLabel = (label) => {
return label.replace(t_rxp_1, '$1')
.replace(t_rxp_2, ':$1')
.replace(t_rxp_3, '.$1')
}
const parseExtendedLyric = (lrcLinesMap, extendedLyric) => {
const extendedLines = extendedLyric.split(/\r\n|\n|\r/)
for (let i = 0; i < extendedLines.length; i++) {
@ -26,9 +33,7 @@ const parseExtendedLyric = (lrcLinesMap, extendedLyric) => {
const times = timeField.match(timeExp)
if (times == null) continue
for (let time of times) {
if (time.includes('.')) time = time.replace(timeLabelRxp, '$1$2')
else time += '.0'
const timeStr = time.replace(timeLabelFixRxp, '')
const timeStr = formatTimeLabel(time)
const targetLine = lrcLinesMap[timeStr]
if (targetLine) targetLine.extendedLyrics.push(text)
}
@ -88,19 +93,16 @@ module.exports = class LinePlayer {
const times = timeField.match(timeExp)
if (times == null) continue
for (let time of times) {
if (time.includes('.')) time = time.replace(timeLabelRxp, '$1$2')
else time += '.0'
const timeStr = time.replace(timeLabelFixRxp, '')
const timeStr = formatTimeLabel(time)
if (linesMap[timeStr]) {
linesMap[timeStr].extendedLyrics.push(text)
continue
}
const timeArr = timeStr.split(':')
if (timeArr.length < 3) timeArr.unshift(0)
if (timeArr[2].indexOf('.') > -1) {
timeArr.push(...timeArr[2].split('.'))
timeArr.splice(2, 1)
} else if (!timeArr[2]) timeArr[2] = '0'
if (timeArr.length > 3) continue
else if (timeArr.length < 3) for (let i = 3 - timeArr.length; i--;) timeArr.unshift('0')
if (timeArr[2].indexOf('.') > -1) timeArr.splice(2, 1, ...timeArr[2].split('.'))
linesMap[timeStr] = {
time: parseInt(timeArr[0]) * 60 * 60 * 1000 + parseInt(timeArr[1]) * 60 * 1000 + parseInt(timeArr[2]) * 1000 + parseInt(timeArr[3] || 0),
text,

View File

@ -137,8 +137,8 @@ export default {
// padding: 18px 3px;
// margin: 5px 0;
// border-left: 5px solid transparent;
transition: @transition-normal;
transition-property: color;
transition: @transition-fast;
transition-property: background-color, opacity;
color: var(--color-nav-font);
cursor: pointer;
font-size: 11.5px;
@ -148,17 +148,30 @@ export default {
align-items: center;
justify-content: center;
transition: 0.3s ease;
transition-property: background-color, opacity;
// border-radius: @radius-border;
.mixin-ellipsis-1;
&:before {
.mixin-after;
left: 0;
top: 0;
width: 3px;
height: 100%;
background-color: var(--color-primary-dark-200-alpha-700);
border-radius: 4px;
transform: translateX(-100%);
transition: transform @transition-fast;
}
&.active {
// border-left-color: @color-theme-active;
background-color: var(--color-primary-light-400-alpha-600);
background-color: var(--color-primary-light-300-alpha-700);
&:before {
transform: translateX(0);
}
&:hover {
background-color: var(--color-primary-light-300-alpha-600);
background-color: var(--color-primary-light-300-alpha-800);
}
}
@ -168,12 +181,12 @@ export default {
&:not(.active) {
opacity: .8;
background-color: var(--color-primary-light-500-alpha-600);
background-color: var(--color-primary-light-400-alpha-700);
}
}
&:active:not(.active) {
opacity: .6;
background-color: var(--color-primary-light-200-alpha-600);
background-color: var(--color-primary-light-300-alpha-600);
}
}

View File

@ -0,0 +1,109 @@
import { decodeName, formatPlayTime, sizeFormate } from '../../index'
const createGetMusicInfoTask = (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])))
}
const deDuplication = (datas) => {
let ids = new Set()
return datas.filter(({ hash }) => {
if (ids.has(hash)) return false
ids.add(hash)
return true
})
}
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(createGetMusicInfoTask(hashs)).then(data => data.flat()))
}
export const getMusicInfosByList = (list) => {
return getMusicInfos(deDuplication(list).map(item => ({ hash: item.hash })))
}

View File

@ -1,17 +1,18 @@
import { httpFetch } from '../../request'
import { decodeName, formatPlayTime, sizeFormate, dateFormat } from '../../index'
import infSign from './vendors/infSign.min'
import { signatureParams } from './util'
import { getMusicInfosByList } from './musicInfo'
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)
},
})
})
// import infSign from './vendors/infSign.min'
// 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,
@ -77,6 +78,90 @@ export default {
return result.body.info
},
/**
* 获取SpecialId歌单详情
* @param {*} id
*/
async getListInfoBySpecialId(id, tryNum = 0) {
if (tryNum > 2) throw new Error('try max num')
const { body } = await httpFetch(this.getSongListDetailUrl(id)).promise
let listInfo = body.match(this.regExps.listInfo)
if (!listInfo) return this.getListDetailBySpecialId(id, ++tryNum)
let name
let pic
if (listInfo) {
name = listInfo[1]
pic = listInfo[2]
}
let desc = this.parseHtmlDesc(body)
return {
name,
image: pic,
desc,
// author: body.result.info.userinfo.username,
// play_count: this.formatPlayCount(body.result.listen_num),
}
},
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))
},
/**
* 使用SpecialId获取CollectionId
* @param {*} specialId
*/
async getCollectionIdBySpecialId(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('getCollectionIdBySpecialId', body)
if (!body.data.global_specialid) return Promise.reject(new Error('Failed to get global collection id.'))
return body.data.global_specialid
})
},
/**
* 获取歌单URL
* @param {*} sortId
* @param {*} tagId
* @param {*} page
*/
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}`
},
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&'
},
getSongListDetailUrl(id) {
return `http://www2.kugou.kugou.com/yueku/v9/special/single/${id}-5-9999.html`
},
/**
* 格式化歌手
* @param {*} list
* @param {*} join
*/
getSinger(list, joinText = '、') {
const singers = []
list.forEach(item => {
if (!item.name) return
singers.push(item.name)
})
return singers ? singers.join(joinText) : ''
},
/**
* 格式化播放数量
* @param {*} num
@ -99,6 +184,7 @@ export default {
}
return result
},
filterTagInfo(rawData) {
const result = []
for (const name of Object.keys(rawData)) {
@ -115,51 +201,19 @@ export default {
}
return result
},
/**
* 使用SpecialId获取CollectionId
* @param {*} specialId
*/
async getCollectionIdBySpecialId(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('getCollectionIdBySpecialId', body)
if (!body.data.global_specialid) return Promise.reject(new Error('Failed to get global collection id.'))
return body.data.global_specialid
})
},
/**
* 获取歌手
* @param {*} list
* @param {*} join
*/
getSinger(list, join = '、') {
const singers = []
list.forEach(item => {
if (!item.name) return
singers.push(item.name)
})
return singers ? singers.join(join) : ''
},
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&'
},
/**
* 获取歌单URL
* @param {*} sortId
* @param {*} tagId
* @param {*} page
*/
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}`
filterSongList(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',
}))
},
getSongList(sortId, tagId, page, tryNum = 0) {
@ -201,20 +255,6 @@ export default {
return this.filterSongList(body.data.special_list)
})
},
filterSongList(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',
}))
},
createTask(hashs) {
let data = {
@ -274,6 +314,39 @@ export default {
}
})
},
/**
* 通过SpecialId获取歌单
* @param {*} id
*/
async getUserListDetailBySpecialId(id, page = 1, limit = 300) {
if (!id || id.length > 1000) return Promise.reject(new Error('get list error.'))
const listInfo = await this.getListInfoBySpecialId(id)
const params = `specialid=${id}&need_sort=1&module=CloudMusic&clientver=11589&pagesize=${limit}&userid=0&page=${page}&type=0&area_code=1&appid=1005`
return this.createHttp(`http://pubsongs.kugou.com/v2/get_other_list_file?${params}&signature=${signatureParams(params, 2)}`, {
headers: {
'User-Agent': 'Android10-AndroidPhone-11589-201-0-playlist-wifi',
},
}).then(body => {
if (!body.info) return Promise.reject(new Error('Get list failed.'))
const songList = this.filterCollectionIdList(body.info)
return {
list: songList || [],
page,
limit,
total: songList.length,
source: 'kg',
info: {
name: listInfo.name,
img: listInfo.image,
desc: listInfo.desc,
// author: listInfo.userName,
// play_count: this.formatPlayCount(listInfo.playCount),
},
}
})
},
/**
* 通过CollectionId获取歌单
* @param {*} id
@ -282,7 +355,7 @@ export default {
if (!id || id.length > 1000) return Promise.reject(new Error('ID error.'))
const listInfo = await this.getUserListInfoByCollectionId(id)
const params = `specialid=0&need_sort=1&module=CloudMusic&clientver=11589&pagesize=${limit}&global_collection_id=${id}&userid=0&page=${page}&type=0&area_code=1&appid=1005`
const params = `need_sort=1&module=CloudMusic&clientver=11589&pagesize=${limit}&global_collection_id=${id}&userid=0&page=${page}&type=0&area_code=1&appid=1005`
return this.createHttp(`http://pubsongs.kugou.com/v2/get_other_list_file?${params}&signature=${signatureParams(params, 2)}`, {
headers: {
'User-Agent': 'Android10-AndroidPhone-11589-201-0-playlist-wifi',
@ -413,76 +486,25 @@ export default {
},
body: { appid: 1001, clientver: 9020, mid: '21511157a05844bd085308bc76ef3343', clienttime: 640612895, key: '36164c4015e704673c588ee202b9ecb8', data: { id: codeInfo.id, type: 3, userid: codeInfo.userid, collect_type: 0, page: 1, pagesize: codeInfo.count } },
})
let result = await Promise.all(this.createTask((songList || codeData.list).map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat())
// console.log(songList)
let list = await getMusicInfosByList(songList || codeInfo.list)
return {
list: this.filterData2(result) || [],
list,
page: 1,
limit: codeInfo.count,
total: codeInfo.count,
total: list.length,
source: 'kg',
info: {
name: codeInfo.name,
img: (codeInfo.img_size && codeInfo.img_size.replace('{size}', 240)) || codeInfo.img,
// desc: body.result.info.list_desc,
author: codeInfo.username,
// play_count: this.formatPlayCount(info.count),
},
}
}
},
/**
* 通过SpecialId获取歌单
* @param {*} id
* @param {*} page
*/
async getUserListDetailBySpecialId(id, page = 1) {
const globalSpecialId = await this.getCollectionIdBySpecialId(id)
return this.getUserListDetailByCollectionId(globalSpecialId, page)
},
/**
* 通过AlbumId获取专辑
* @param {*} id
* @param {*} page
*/
async getListDetailByAlbumId(id, page = 1, limit = 200) {
console.log(id)
const albumInfoRequest = await this.createHttp('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,
},
})
const albumInfo = albumInfoRequest[0]
const albumList = await this.createHttp(`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 Promise.all(this.createTask(albumList.info.map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat())
return {
list: this.filterData2(result) || [],
page,
limit,
total: albumList.total,
source: 'kg',
info: {
name: albumInfo.album_name,
img: albumInfo.sizable_cover.replace('{size}', 240),
desc: albumInfo.intro,
author: albumInfo.author_name,
// 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: {
@ -493,13 +515,13 @@ export default {
if (songInfo.global_collection_id) return this.getUserListDetailByCollectionId(songInfo.global_collection_id, page)
else return this.getUserListDetail4(songInfo, chain, page).catch(() => this.getUserListDetail5(chain))
}
let result = await Promise.all(this.createTask(songInfo.list.map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat())
let list = await getMusicInfosByList(songInfo.list)
// console.log(info, songInfo)
return {
list: this.filterData2(result) || [],
list,
page: 1,
limit: this.listDetailLimit,
total: songInfo.count,
total: list.length,
source: 'kg',
info: {
name: songInfo.info.name,
@ -511,15 +533,6 @@ export default {
}
},
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
@ -537,13 +550,13 @@ export default {
}).then(data => data.list.info))
}
let result = await Promise.all(tasks).then(([...datas]) => datas.flat())
result = await Promise.all(this.createTask(this.deDuplication(result).map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat())
result = await getMusicInfosByList(result)
// console.log(result)
return {
list: this.filterData2(result) || [],
list: result,
page,
limit: this.listDetailLimit,
total: listInfo.count,
total: result.length,
source: 'kg',
info: {
name: listInfo.name,
@ -574,6 +587,37 @@ export default {
}
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 getMusicInfosByList(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)
@ -600,22 +644,22 @@ export default {
let result = body.match(/var\sdataFromSmarty\s=\s(\[.+?\])/)
if (result) result = JSON.parse(result[1])
this.cache.set(chain, result)
result = await Promise.all(this.createTask(result.map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat())
result = await getMusicInfosByList(result)
// console.log(info, songInfo)
return this.filterData2(result)
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),
this.getUserListDetailBySpecialId(songInfo.id, page, limit),
])
return {
list: list || [],
page,
limit,
total: listInfo.songcount,
total: list.length ?? 0,
source: 'kg',
info: {
name: listInfo.specialname,
@ -636,7 +680,7 @@ export default {
list: list || [],
page: 1,
limit: this.listDetailLimit,
total: listInfo.songcount,
total: list.length ?? 0,
source: 'kg',
info: {
name: listInfo.specialname,
@ -648,21 +692,6 @@ export default {
}
},
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: '-',
},
})
let result = await Promise.all(this.createTask(info.info.map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat())
// console.log(info, songInfo)
return this.filterData2(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(/#.*$/, '')
@ -790,69 +819,6 @@ export default {
})
},
// 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()

View File

@ -58,26 +58,106 @@ export default {
'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 }) => {
if (!body.data.global_specialid) return Promise.reject(new Error('Failed to get global collection id.'))
// console.log(body)
if (!body.data.global_specialid) Promise.reject(new Error('Failed to get global collection id.'))
return body.data.global_specialid
})
},
async getLiteGlobalCollectionId(url) {
return httpFetch(url, {
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: 0,
}).promise.then(({ headers }) => {
if (!headers.location) return Promise.reject(new Error('Failed to get lite global collection id.'))
const gid = headers.location.replace(/^.*?global_specialid=(\w+)(?:&.*$|#.*$|$)/, '$1')
if (!gid) return Promise.reject(new Error('Failed to get lite global collection id.'))
return gid
})
// 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) {
const globalSpecialId = await this.getGlobalSpecialId(id)
return this.getUserListDetailByGid(globalSpecialId)
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
@ -88,6 +168,9 @@ export default {
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`
},
/**
* 格式化播放数量
@ -234,6 +317,15 @@ export default {
},
}).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/', {
@ -257,7 +349,7 @@ export default {
default:
break
}
if (info.global_collection_id) return this.getUserListDetailByGid(info.global_collection_id)
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',
@ -270,12 +362,12 @@ export default {
})
// console.log(songList)
}
let result = await Promise.all(this.createTask((songList || songInfo.list).map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat())
let list = await this.getMusicInfos(songList || songInfo.list)
return {
list: this.filterData2(result) || [],
list,
page: 1,
limit: info.count,
total: info.count,
total: list.length,
source: 'kg',
info: {
name: info.name,
@ -294,16 +386,16 @@ export default {
},
})
if (!songInfo.list) {
if (songInfo.global_collection_id) return this.getUserListDetailByGid(songInfo.global_collection_id)
if (songInfo.global_collection_id) return this.getUserListDetail2(songInfo.global_collection_id)
else return this.getUserListDetail4(songInfo, chain, page).catch(() => this.getUserListDetail5(chain))
}
let result = await Promise.all(this.createTask(songInfo.list.map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat())
let list = await this.getMusicInfos(songInfo.list)
// console.log(info, songInfo)
return {
list: this.filterData2(result) || [],
list,
page: 1,
limit: this.listDetailLimit,
total: songInfo.count,
total: list.length,
source: 'kg',
info: {
name: songInfo.info.name,
@ -341,13 +433,13 @@ export default {
}).then(data => data.list.info))
}
let result = await Promise.all(tasks).then(([...datas]) => datas.flat())
result = await Promise.all(this.createTask(this.deDuplication(result).map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat())
result = await this.getMusicInfos(result)
// console.log(result)
return {
list: this.filterData2(result) || [],
list: result,
page,
limit: this.listDetailLimit,
total: listInfo.count,
total: result.length,
source: 'kg',
info: {
name: listInfo.name,
@ -378,7 +470,7 @@ export default {
}
return Promise.all(tasks).then(([...datas]) => datas.flat())
},
async getUserListDetailByGid(global_collection_id) {
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=-'
@ -392,14 +484,13 @@ export default {
},
})
const songInfo = await this.createGetListDetail2Task(id, info.songcount)
console.log(songInfo)
let result = await Promise.all(this.createTask(this.deDuplication(songInfo).map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat())
// console.log(info, songInfo, result)
let list = await this.getMusicInfos(songInfo)
// console.log(info, songInfo, list)
return {
list: this.filterData2(result) || [],
list,
page: 1,
limit: this.listDetailLimit,
total: info.songcount,
total: list.length,
source: 'kg',
info: {
name: info.specialname,
@ -435,9 +526,9 @@ export default {
let result = body.match(/var\sdataFromSmarty\s=\s(\[.+?\])/)
if (result) result = JSON.parse(result[1])
this.cache.set(chain, result)
result = await Promise.all(this.createTask(result.map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat())
result = await this.getMusicInfos(result)
// console.log(info, songInfo)
return this.filterData2(result)
return result
},
async getUserListDetail4(songInfo, chain, page) {
@ -450,7 +541,7 @@ export default {
list: list || [],
page,
limit,
total: listInfo.songcount,
total: list.length ?? 0,
source: 'kg',
info: {
name: listInfo.specialname,
@ -471,7 +562,7 @@ export default {
list: list || [],
page: 1,
limit: this.listDetailLimit,
total: listInfo.songcount,
total: list.length ?? 0,
source: 'kg',
info: {
name: listInfo.specialname,
@ -494,15 +585,15 @@ export default {
})
// console.log(info)
let result = await Promise.all(this.createTask(info.info.map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat())
let result = await this.getMusicInfos(info.info)
// console.log(info, songInfo)
return this.filterData2(result)
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.getUserListDetailByGid(link.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1'))
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')) {
@ -526,7 +617,7 @@ export default {
if (statusCode > 400) return this.getUserListDetail(link, page, ++retryNum)
if (location) {
// console.log(location)
if (location.includes('global_collection_id')) return this.getUserListDetailByGid(location.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1'))
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')) {
@ -542,22 +633,16 @@ export default {
// console.log('location', location)
return this.getUserListDetail(location, page, ++retryNum)
}
if (typeof body == 'string') return this.getUserListDetailByGid(body.replace(/^[\s\S]+?"global_collection_id":"(\w+)"[\s\S]+?$/, '$1'))
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 getLiteListDetail(url) {
const id = await this.getLiteGlobalCollectionId(url)
return this.getUserListDetailByGid(id)
},
async getListDetail(id, page) { // 获取歌曲列表内的音乐
id = id.toString()
if (id.includes('special/single/')) {
id = id.replace(this.regExps.listDetailLink, '$1')
} else if (/https?:/.test(id)) {
// 酷狗概念版 https://t1.kugou.com/gfX9973BaV2
if (id.includes('t1.kugou.com')) return this.getLiteListDetail(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)) {
@ -567,7 +652,7 @@ export default {
}
// if ((/[?&:/]/.test(id))) id = id.replace(this.regExps.listDetailLink, '$1')
return this.getListDetailBySpecialId(id)
return this.getListDetailBySpecialId(id, page)
},
filterData(rawList) {
// console.log(rawList)
@ -842,4 +927,4 @@ export default {
// getList
// getTags
// getListDetail
// getListDetail