Skip to content

Commit

Permalink
feat: support searching for more songs
Browse files Browse the repository at this point in the history
Gray level
  • Loading branch information
hq001 committed Dec 6, 2020
1 parent ad1f79d commit ef0c91e
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 55 deletions.
29 changes: 11 additions & 18 deletions packages/api/module/song_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,16 @@ module.exports = (query, request) => {
realIP: query.realIP,
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++
).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
}
return v
})
.catch((e) => {
return {
status: 500,
body: e,
}
})
i++
}
return v
})
}
8 changes: 5 additions & 3 deletions packages/unblock/src/provider/qq.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@ const single = (id, format) => {
return request('GET', url, headers)
.then(response => response.json())
.then(jsonBody => {
const { sip, midurlinfo } = jsonBody.req_0.data
const { sip, midurlinfo, msg } = jsonBody.req_0.data
// const vkey =
// jsonBody.req_0.data.midurlinfo[0].vkey ||
// (jsonBody.req_0.data.testfile2g.match(/vkey=(\w+)/) || [])[1]
// return concatenate(vkey)
return midurlinfo[0].purl ? sip[0] + midurlinfo[0].purl : Promise.reject()
return midurlinfo[0].purl
? sip[0] + midurlinfo[0].purl
: Promise.reject(msg)
})
}

Expand Down Expand Up @@ -177,4 +179,4 @@ const track = id => {

const check = info => cache(search, info).then(track)

module.exports = { check, track, search }
module.exports = { check, track, search, single }
12 changes: 5 additions & 7 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { get } from '@/utils/http'
import { SongsBase, SongsDetail, SongInteface } from '@/interface/index'
import { SongsDetail, SongInteface } from '@/interface/index'

export const getSongUrl = async (
id: number | number[]
): Promise<SongsBase[]> => {
const data = await get<{ data: SongsBase[] }>('/api/song/url', {
id: typeof id === 'number' ? id : id.join(','),
br: 3.2e5
export const getSongUrl = async <T>(id: number | number[]): Promise<T> => {
const data = await get<{ data: T }>('/api/song/url', {
id: Array.isArray(id) ? id.join(',') : id,
br: 9.99e5
})
return data.data
}
Expand Down
8 changes: 8 additions & 0 deletions src/interface/service/songs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export interface SongsBase {
freeTrialInfo: FreeTrialInfo
}

export interface PlayLists extends GlobalBase {
playCount: number
trackCount: number
highQuality: boolean
subscribed: boolean
coverImgUrl: string
}

export interface SongsDetail extends GlobalBase {
alia: string[]
dt: number // duration
Expand Down
7 changes: 4 additions & 3 deletions src/pages/footer/sage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isNumber, timeTos, toFixed, storage } from '@/utils/index'
import { getSongUrl, getSongDetail, getLyric } from './api/index'
import { FooterState, LocalKey } from './state'
import { RootState } from '@/store/index'
import { SongsDetail } from '@/interface'
import { SongsDetail, SongsBase } from '@/interface'
import { cloneDeep } from 'lodash'

const { get, set } = storage()
Expand Down Expand Up @@ -104,12 +104,13 @@ export const getters: GetterTree<FooterState, RootState> = {
duration = allDt - time
}
return {
time: time,
time: time || 0,
lyric: lyric,
duration: toFixed(duration, 3)
}
})
.filter(item => item.time)
.sort((a, b) => a.time - b.time)
return lyrices
},
musicDes(state) {
Expand Down Expand Up @@ -146,7 +147,7 @@ export const actions: ActionTree<FooterState, RootState> = {
) {
let id, url
if (typeof payload === 'number') {
const data = await getSongUrl(payload)
const data = await getSongUrl<SongsBase[]>(payload)
id = payload
url = data[0].url
} else {
Expand Down
16 changes: 16 additions & 0 deletions src/pages/header/api/search.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import { get } from '@/utils/http'
import { SearchSuggest } from '../state'

interface QQ {
id: { song: number; file: number }
name: string
duration: number
album: { id: string; name: string }
artists: { id: number; name: string; alias: unknown[]; img1v1Url: string }[]
}

export const searchSuggest = async (key: string): Promise<SearchSuggest> => {
const data = await get<{ result: SearchSuggest }>('/api/search/suggest', {
keywords: key
})
const songs = await get<{
result: {
songs: SearchSuggest['songs']
}
}>('/api/search', {
keywords: key
})
data.result.songs = songs.result.songs
return data.result
}
11 changes: 10 additions & 1 deletion src/pages/header/component/search.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
@import '~@/theme/index.less';

li.qq-song {
strong.keyword {
color: #31c27c;
}
}

.search {
-webkit-app-region: no-drag;
margin-left: 10px;
Expand All @@ -8,7 +14,7 @@
font-size: 13px;
&-title {
padding: 4px 10px;
background-color: var(--background-lighter);
background-color: #e7e7e7;
}
&-group {
li {
Expand Down Expand Up @@ -53,4 +59,7 @@ div.auto-complete-template {
padding: 0;
border-radius: 4px;
box-shadow: 0 0 2px 0 #c7c7c7;
ul {
max-height: max-content;
}
}
Loading

0 comments on commit ef0c91e

Please sign in to comment.