Skip to content

Commit

Permalink
添加cdn
Browse files Browse the repository at this point in the history
Signed-off-by: fengT-T <[email protected]>
  • Loading branch information
fengT-T committed Dec 2, 2019
1 parent 2f53818 commit 1177d38
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cocomusic",
"version": "2.0.5",
"version": "2.0.6",
"author": "fengT-T <[email protected]>",
"description": "a simple music player.",
"license": "LGPL-3.0",
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
<div>
<login></login>
</div>
<div class="divider text-center" data-content="HotKey" @click="hotkeysbtn = !hotkeysbtn"></div>
<div v-if="hotkeysbtn" class="form-group">
<div class="divider text-center" data-content="HotKey" ></div>
<div class="form-group">
<div class="col-12 col-sm-12 text-center">
<button class="btn" @click="defaultKeySet">重置快捷键</button>
</div>
Expand All @@ -85,7 +85,7 @@ import { getkeyMap } from '../../main/hotKey.js'
const localStorage = require('../../main/localStorage').default
const { shell, getCurrentWebContents } = require('electron').remote
const packjsonUrl = 'http://cocomusic-1252075019.file.myqcloud.com/package.json'
const CURRENT_VERSION = '2.0.5'
const CURRENT_VERSION = '2.0.6'
export default {
data () {
Expand Down
13 changes: 9 additions & 4 deletions src/renderer/store/modules/Player.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSongVkey, getLyric, getKey } from '../../../spider/index'
import { getSongVkey, getLyric, getKey, getCdn } from '../../../spider/index'
import { throttle, random } from 'lodash'
import { setMprisProp, setPosition, mpris } from '../../mpris'
const { dialog, app } = require('electron').remote
Expand Down Expand Up @@ -58,7 +58,8 @@ const state = {
loop: window.localStorage.loop !== undefined
? !!window.localStorage.loop
: true,
vkey: ''
vkey: '',
cdn: ''
}

const mutations = {
Expand Down Expand Up @@ -132,6 +133,10 @@ const actions = {
* @param {Object} state
*/
async initPlayer ({ state, commit, dispatch, getters }) {
commit('setPlayerState', {
cdn: await getCdn(state.guid)
})

state.player.append(state.source, state.sourceBac1, state.sourceBac2)

let { player, playVolume, mode } = state
Expand Down Expand Up @@ -202,7 +207,7 @@ const actions = {
* @param {Number} index 歌曲索引
*/
async setPlay ({ state, commit, getters }, index) {
const { guid } = state
const { guid, cdn } = state
const current = state.playList[index] // 保存当前播放的引用

commit('setPlayerState', { loading: true })
Expand All @@ -218,7 +223,7 @@ const actions = {
})

commit('setPlayerSrc', [
`http://113.105.155.25/amobile.music.tc.qq.com/${song.fileName}?vkey=${vkey}&guid=${guid}&uin=0&fromtag=66`
`${cdn}${song.fileName}?vkey=${vkey}&guid=${guid}&uin=0&fromtag=66`
])
// TODO 添加 cdn 选择,不过我觉得没有必要,毕竟要搞新坑了

Expand Down
34 changes: 24 additions & 10 deletions src/spider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export async function getSingerMusicList ({page, singerMid}) {
return {
total: Math.floor(total / 30),
list: list.map(
({musicData: {songmid, strMediaMid, songname, albumname, albummid, singer, type}}) =>
({musicData: {
songmid, strMediaMid, songname, albumname, albummid, singer, type}}) =>
new Music(songname, songmid, strMediaMid,
new Album(albumname, albummid),
singer.map(
({mid, name}) => new Singer(name,mid))
singer.map(({mid, name}) => new Singer(name, mid))
, type))
}
}
Expand Down Expand Up @@ -188,10 +188,10 @@ export async function getSearch ({keyword, page}) {
return {direct, totalPage: Math.ceil(totalnum / 20),
songList: list.map(
({name, mid, file: {media_mid}, singer, album, type}) =>
new Music(name, mid, media_mid,
new Music(
name, mid, media_mid,
new Album(album.name, album.mid),
singer.map(
singerItem =>
singer.map(singerItem =>
new Singer(singerItem.name, singerItem.mid)),
type))
}
Expand All @@ -209,10 +209,10 @@ export async function getAlbum ({albumMid}) {
return {
musicList: list.map(
({songname, songmid, strMediaMid, albumname, albummid, singer, type}) =>
new Music(songname, songmid, strMediaMid,
new Music(
songname, songmid, strMediaMid,
new Album(albumname, albummid),
singer.map(
({mid, name}) => new Singer(name, mid)),
singer.map(({mid, name}) => new Singer(name, mid)),
type)),
album: new Album(name, albumMid)
}
Expand Down Expand Up @@ -247,10 +247,24 @@ export async function getPlayListInfo (playListMid) {
playListName: dissname,
list: songlist.map(
({songname, songmid, strMediaMid, albumname, albummid, singer, type}) =>
new Music(songname, songmid, strMediaMid,
new Music(
songname, songmid, strMediaMid,
new Album(albumname, albummid),
singer.map(
({mid, name}) => new Singer(name, mid))
, type))
}
}

export async function getCdn (guid) {
const url = `https://u.y.qq.com/cgi-bin/musicu.fcg?data=${encodeURIComponent(`{"req":{"module":"CDN.SrfCdnDispatchServer","method":"GetCdnDispatch","param":{"guid":${guid},"calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"${guid}","songmid":["000KDHyB23K7Eq"],"songtype":[0],"uin":"0","loginflag":1,"platform":"20"}},"comm":{"uin":0,"format":"json","ct":24,"cv":0}}`)}`
const { data: { req: { data: { sip: cdnList, testfilewifi: testUrl } } }} = await baseRequest(url)
return new Promise((resolve, reject) => {
cdnList.map(cdn => {
baseRequest(cdn + testUrl).then(() => {
console.log(cdn)
resolve(cdn)
})
})
})
}

0 comments on commit 1177d38

Please sign in to comment.