Skip to content

Commit

Permalink
feat: support gray song playback
Browse files Browse the repository at this point in the history
  • Loading branch information
hq001 committed Dec 4, 2020
1 parent 5e61608 commit 62c2940
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 30 deletions.
8 changes: 4 additions & 4 deletions packages/api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ app.use((req, res, next) => {
// cookie parser
app.use((req, res, next) => {
req.cookies = {}
;(req.headers.cookie || '').split(/\s*;\s*/).forEach(pair => {
;(req.headers.cookie || '').split(/\s*;\s*/).forEach((pair) => {
let crack = pair.indexOf('=')
if (crack < 1 || crack == pair.length - 1) return
req.cookies[
Expand Down Expand Up @@ -56,7 +56,7 @@ const special = {

fs.readdirSync(path.join(__dirname, 'module'))
.reverse()
.forEach(file => {
.forEach((file) => {
if (!file.endsWith('.js')) return
let route =
file in special
Expand All @@ -77,12 +77,12 @@ fs.readdirSync(path.join(__dirname, 'module'))
)

question(query, request)
.then(answer => {
.then((answer) => {
console.log('[OK]', decodeURIComponent(req.originalUrl))
res.append('Set-Cookie', answer.cookie)
res.status(answer.status).send(answer.body)
})
.catch(answer => {
.catch((answer) => {
console.log('[ERR]', decodeURIComponent(req.originalUrl), {
status: answer.status,
body: answer.body,
Expand Down
39 changes: 39 additions & 0 deletions packages/api/module/song_url.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
// 歌曲链接

// 从 packages/unblock 中解析网易云音乐ID的播放链接,突破灰色歌曲限制
const match = require('@nondanee/unblockneteasemusic')
const crypto = require('crypto')

const find = async (id) => {
await match(id, [
'qq',
// 'xiami',
// 'baidu',
'kugou',
'kuwo',
// 'joox',
// 'youtube',
'migu',
])
.then((url) => {
return url.url
})
.catch((e) => {
return ''
})
}

module.exports = (query, request) => {
if (!('MUSIC_U' in query.cookie))
query.cookie._ntes_nuid = crypto.randomBytes(16).toString('hex')
Expand All @@ -22,4 +43,22 @@ module.exports = (query, request) => {
url: '/api/song/enhance/player/url',
},
)
.then(async (v) => {
const { body } = v
let i = 0
while (i < body.data.length) {
if (!body.data[i].url) {
const url = await find(body.data[i].id)
v.body.data[i].url = url
}
i++
}
return v
})
.catch((e) => {
return {
status: 500,
body: e,
}
})
}
3 changes: 2 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"express": "^4.17.1",
"express-fileupload": "^1.1.9",
"pac-proxy-agent": "^4.0.0",
"tunnel": "^0.0.6"
"tunnel": "^0.0.6",
"@nondanee/unblockneteasemusic": "file:../unblock"
},
"devDependencies": {
"@types/node": "14.11.10",
Expand Down
1 change: 0 additions & 1 deletion packages/unblock/src/provider/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const match = (id, source) => {
.then(songs => {
songs = songs.filter(song => song.url)
if (!songs.length) return Promise.reject()
console.log(`[${meta.id}] ${meta.name}\n${songs[0].url}`)
return songs[0]
})
}
Expand Down
1 change: 1 addition & 0 deletions src/components/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const Table = defineComponent({
<div class={`${prefix}-header`}></div>
<div class={`${prefix}-body`}>
<ATable
size="small"
rowKey="id"
rowClassName={rowClassName.value}
pagination={false}
Expand Down
5 changes: 5 additions & 0 deletions src/interface/service/songs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ export interface SongsDetail extends GlobalBase {
lyric: string
}
url: string
copyright: number
noCopyrightRcmd?: {
type: number
typeDesc: string
}
}
5 changes: 4 additions & 1 deletion src/pages/footer/component/volume-history/history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export const MusicHistory = defineComponent({

const handleDbClick = (item: Music) => {
useMutations(FooterMutations.PAUES_MUSIC)
useActions(FooterActions.SET_MUSIC, item.id)
useActions(FooterActions.SET_MUSIC, {
url: item.url,
id: item.id
})
}

const trigger = () => {
Expand Down
30 changes: 17 additions & 13 deletions src/pages/footer/sage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,24 @@ export const getters: GetterTree<FooterState, RootState> = {
}

export const actions: ActionTree<FooterState, RootState> = {
async [FooterActions.SET_MUSIC]({ state, dispatch, commit }, id: number) {
const data = await getSongUrl(id)
if (state.sourceElement && state.audioElement) {
if (data.length) {
const url =
data[0].url ||
`https://music.163.com/song/media/outer/url?id=${id}.mp3`
state.musicUrl = url
commit(FooterMutations.CAN_PLAY, false)
await dispatch(FooterActions.SET_MUSIC_DEFAILT, id)
await dispatch(FooterActions.SET_MUSIC_LYRICS, id)
commit(FooterMutations.SET_MUSIC_URL, url)
}
async [FooterActions.SET_MUSIC](
{ state, dispatch, commit },
payload: number | { url: string; id: number }
) {
let id, url
if (typeof payload === 'number') {
const data = await getSongUrl(payload)
id = payload
url = data[0].url
} else {
id = payload.id
url = payload.url
}
state.musicUrl = url
commit(FooterMutations.CAN_PLAY, false)
await dispatch(FooterActions.SET_MUSIC_DEFAILT, id)
await dispatch(FooterActions.SET_MUSIC_LYRICS, id)
commit(FooterMutations.SET_MUSIC_URL, url)
},
async [FooterActions.SET_MUSIC_DEFAILT]({ state }, id: number | number[]) {
const data = await getSongDetail(id)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/song/view/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
display: flex;
padding: 10px;
&--coverimg {
width: 180px;
width: 210px;
height: 210px;
margin-right: 20px;
border-radius: 4px;
Expand Down
32 changes: 24 additions & 8 deletions src/pages/song/view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,27 @@ import { RouterLink } from 'vue-router'
const renderClass = (name: string) => `song-list-${name}`

const columns = [
{
width: 80,
align: 'center',
customRender: ({ index }: { index: number }) => (
<div>{++index < 10 ? '0' + index : index}</div>
)
},
{
title: '音乐标题',
dataIndex: 'name',
key: 'name',
ellipsis: true
ellipsis: true,
customRender: ({ text }: { text: Tracks }) => {
return (
<div
style={{
color: text.noCopyrightRcmd?.typeDesc ? '#eee' : ''
}}
>
{text.name}
</div>
)
}
},
{
title: '歌手',
Expand Down Expand Up @@ -83,20 +99,20 @@ export default defineComponent({
const tracksDetail = await getSongUrl(tracks.map(item => item.id))
const stack = tracks.map(item => {
const urlItem = tracksDetail.find(o => o.id === item.id)
const url = urlItem
? urlItem.url
: ` https://music.163.com/song/media/outer/url?${item.id}=id.mp3`
return {
...item,
url: url
url: urlItem?.url
}
})
footerStore.useMutations(FooterMutations.SET_PLAYLIST_TO_STACK, stack)

const { music } = footerStore.useState()
if (music?.id !== stack[0].id) {
footerStore.useMutations(FooterMutations.PAUES_MUSIC)
await footerStore.useActions(FooterActions.SET_MUSIC, stack[0].id)
await footerStore.useActions(FooterActions.SET_MUSIC, {
id: stack[0].id,
url: stack[0].url
})
footerStore.useMutations(FooterMutations.PLAY_MUSIC)
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/theme/cover.less
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ li {
button.easy-button-text {
color: #1890ff !important;
}

.ant-table-body {
font-size: 13px;
}

.ant-table-row-cell-ellipsis {
> div {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
}
2 changes: 1 addition & 1 deletion src/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const baseURL =

const http: AxiosInstance = Axios.create({
baseURL: baseURL,
timeout: 5000
timeout: 20000
})

http.interceptors.request.use(
Expand Down

0 comments on commit 62c2940

Please sign in to comment.