This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
appcat
/
sonist
Archived
1
0
Fork 0

修复播放切换,增加歌词搜索

2.x
宇天 2020-11-20 19:09:12 +08:00
parent bf84344f9c
commit 995a967312
2 changed files with 58 additions and 128 deletions

View File

@ -1,143 +1,63 @@
/** /**
* 音乐APP接口 * 部分远程接口
* @author yutent<yutent@doui.cc> * @author yutent<yutent.io@gmail.com>
* @date 2018/12/24 16:02:00 * @date 2020/11/20 19:07:32
*/ */
'use strict' import fetch from './lib/fetch/index.js'
import request from '/lib/request/index.js' function tojson(r) {
return r.json()
// `http://lyrics.kugou.com/search?client=pc&duration=188000&keyword=%E6%98%93%E7%83%8A%E5%8D%83%E7%8E%BA%20-%20%E4%BD%A0%E6%9B%BE%E6%98%AF%E5%B0%91%E5%B9%B4%20%28Live%29&man=no&ver=1`
// `http://lyrics.kugou.com/download?ver=1&client=pc&fmt=lrc&charset=utf8&accesskey=2128A0ED9B2F6B34C3AE23EA7ACC46A7&id=43066968`
const log = console.log
const BASE_API_URI = 'http://mobilecdnbj.kugou.com'
request.init({ dataType: 'json' })
const get = uri => {
return request.get(BASE_API_URI + uri)
}
const post = uri => {
return request.post(BASE_API_URI + uri)
} }
export default { export default {
getLastHot100Artists() { searchLrc(keyword, duration) {
return get('/api/v5/singer/list', { return fetch('http://lyrics.kugou.com/search', {
data: { body: {
sort: 1, client: 'pc',
showtype: 1, duration: duration * 1000,
sextype: 0,
musician: 0,
pagesize: 100,
plat: 2,
type: 0,
page: 1
}
}).then(res => {
if (res.status === 200) {
return res.body
}
})
},
getArtistList(sextype = 1, type = 1) {
return get('/api/v5/singer/list', {
data: {
showtype: 2,
musician: 0,
type,
sextype
}
}).then(res => {
if (res.status === 200) {
return res.body
}
})
},
getArtistInfo(singerid) {
return get('/api/v3/singer/info', { data: { singerid } }).then(res => {
if (res.status === 200) {
return res.body
}
})
},
getArtistInfo(singerid) {
return get('/api/v3/singer/info', { data: { singerid } }).then(res => {
if (res.status === 200) {
return res.body
}
})
},
getArtistSongs(singerid, page = 1) {
return get('/api/v3/singer/song', {
data: {
sorttype: 2,
pagesize: 50,
singerid,
area_code: 1,
page
}
}).then(res => {
if (res.status === 200) {
return res.body
}
})
},
getArtistAlbums(singerid, page = 1) {
return get('/api/v3/singer/album', {
data: {
pagesize: 50,
singerid,
area_code: 1,
page
}
}).then(res => {
if (res.status === 200) {
return res.body
}
})
},
search(keyword, page = 1, pagesize = 20) {
return request
.get('https://songsearch.kugou.com/song_search_v2', {
data: {
keyword, keyword,
platform: 'WebFilter', man: 'no',
tag: '', ver: 1
page,
pagesize
} }
}) })
.then(res => { .then(tojson)
if (res.status === 200) { .then(r => {
return res.body.data.lists if (r.candidates && r.candidates.length) {
return r.candidates.map(it => ({
id: it.id,
accesskey: it.accesskey,
duration: it.duration,
singer: it.singer,
song: it.song
}))
} }
return []
}) })
}, },
getSongInfoByHash(hash, album_id = '') { downloadLrc(id, accesskey) {
return request return fetch('http://lyrics.kugou.com/download', {
.get('https://wwwapi.kugou.com/yy', { body: {
data: { client: 'pc',
r: 'play/getdata', id,
hash, accesskey,
album_id ver: 1,
fmt: 'lrc',
charset: 'utf8'
} }
}) })
.then(res => { .then(tojson)
if (res.status === 200) { .then(r => {
return res.body.data if (r.status === 200 && r.content) {
var lrc
try {
lrc = Buffer.from(r.content, 'base64').toString()
lrc = lrc.split(/[\r\n]+/).join('\n')
} catch (e) {
console.error(e, r)
}
return lrc
} }
}) })
} }

View File

@ -10,6 +10,7 @@ import '/js/lib/scroll/index.js'
import Keyboard from '/js/lib/keyboard/index.js' import Keyboard from '/js/lib/keyboard/index.js'
import app from '/js/lib/socket.js' import app from '/js/lib/socket.js'
import fetch from '/js/lib/fetch/index.js' import fetch from '/js/lib/fetch/index.js'
import Api from '/js/api.js'
import Player from '/js/lib/audio/index.js' import Player from '/js/lib/audio/index.js'
@ -123,7 +124,7 @@ Anot({
break break
} }
this.playSong(this.list[idx], idx, repeat) this.playSong(idx, repeat)
}) })
}, },
watch: { watch: {
@ -226,6 +227,15 @@ Anot({
this.previewSong(it) this.previewSong(it)
player.play(i) player.play(i)
this.$refs.list.scrollTop = (i - 3) * 26 this.$refs.list.scrollTop = (i - 3) * 26
// if (!it.lrc) {
// Api.searchLrc(it.name, it.duration).then(list => {
// var { id, accesskey } = list[0]
// Api.downloadLrc(id, accesskey).then(lrc => {
// console.log(lrc)
// })
// })
// }
} }
} }
}) })