Added search and tracklist pages

This commit is contained in:
RemixDev 2021-04-22 10:32:41 +02:00
parent 902a9563a6
commit 9800edf68d
7 changed files with 138 additions and 6 deletions

View File

@ -14,7 +14,7 @@
"cookie-parser": "1.4.5",
"debug": "2.6.9",
"deemix": "^0.0.1",
"deezer-js": "^0.0.6",
"deezer-js": "^0.0.7",
"express": "4.17.1",
"morgan": "1.10.0",
"ws": "^7.4.5"

View File

@ -29,3 +29,93 @@ export async function getCharts(){
}
return chartsCache
}
export async function getTracklist(list_id: string, list_type: string){
switch (list_type) {
case 'artist':
let artistAPI = await dz.api.get_artist(list_id)
artistAPI.releases = await dz.gw.get_artist_discography_tabs(list_id, 100)
return artistAPI
default:
let releaseAPI = await dz.api[`get_${list_type}`](list_id)
let releaseTracksAPI = await dz.api[`get_${list_type}_tracks`](list_id)
releaseTracksAPI = releaseTracksAPI['data']
let tracks: any[] = []
const showdiscs = (list_type == 'album' && releaseTracksAPI.length && releaseTracksAPI[releaseTracksAPI.length -1].disk_number != 1)
let current_disk = 0
releaseTracksAPI.forEach((track: any) => {
if (showdiscs && parseInt(track.disk_number) !== current_disk){
current_disk = parseInt(track.disk_number)
tracks.push({type: 'disc_separator', number: current_disk})
}
track.selected = false
tracks.push(track)
})
releaseAPI.tracks = tracks
return releaseAPI
break
}
}
export async function searchAll(term: string){
let results = await dz.gw.search(term)
let order: string[] = []
results.ORDER.forEach((element: string) => {
if (['TOP_RESULT', 'TRACK', 'ALBUM', 'ARTIST', 'PLAYLIST'].indexOf(element) != -1) order.push(element)
})
if (results.TOP_RESULT && results.TOP_RESULT.length){
let originalTopResult = results.TOP_RESULT[0]
let topResult: any = {
type: originalTopResult.__TYPE__
}
switch (topResult.type) {
case 'artist':
topResult.id = originalTopResult.ART_ID
topResult.picture = `https://e-cdns-images.dzcdn.net/images/artist/${originalTopResult.ART_PICTURE}`
topResult.title = originalTopResult.ART_NAME
topResult.nb_fan = originalTopResult.NB_FAN
break
case 'album':
topResult.id = originalTopResult.ALB_ID
topResult.picture = `https://e-cdns-images.dzcdn.net/images/cover/${originalTopResult.ALB_PICTURE}`
topResult.title = originalTopResult.ALB_TITLE
topResult.artist = originalTopResult.ART_NAME
topResult.nb_song = originalTopResult.NUMBER_TRACK
break
case 'playlist':
topResult.id = originalTopResult.PLAYLIST_ID
topResult.picture = `https://e-cdns-images.dzcdn.net/images/${originalTopResult.PICTURE_TYPE}/${originalTopResult.PLAYLIST_PICTURE}`
topResult.title = originalTopResult.TITLE
topResult.artist = originalTopResult.PARENT_USERNAME
topResult.nb_song = originalTopResult.NB_SONG
break
default:
topResult.id = "0"
topResult.picture = 'https://e-cdns-images.dzcdn.net/images/cover'
break;
}
}
results.ORDER = order
return results
}
export async function search(term: string, type: string, start: number, nb: number){
switch (type) {
case 'track':
return await dz.api.search_track(term, {limit: nb, index: start})
case 'album':
return await dz.api.search_album(term, {limit: nb, index: start})
case 'artist':
return await dz.api.search_artist(term, {limit: nb, index: start})
case 'playlist':
return await dz.api.search_playlist(term, {limit: nb, index: start})
case 'radio':
return await dz.api.search_radio(term, {limit: nb, index: start})
case 'user':
return await dz.api.search_user(term, {limit: nb, index: start})
default:
return await dz.api.search(term, {limit: nb, index: start})
}
}

View File

@ -0,0 +1,13 @@
import { ApiHandler } from '../../../types'
import { getTracklist } from '../../../main'
const path: ApiHandler['path'] = '/getTracklist'
const handler: ApiHandler['handler'] = async (req, res) => {
const tracklistData = await getTracklist(String(req.query.id), String(req.query.type))
res.send(tracklistData)
}
const apiHandler: ApiHandler = { path, handler }
export default apiHandler

View File

@ -1,5 +1,8 @@
import sample from './sample'
import getHome from './getHome'
import getCharts from './getCharts'
import mainSearch from './mainSearch'
import search from './search'
import getTracklist from './getTracklist'
export default [sample, getHome, getCharts]
export default [sample, getHome, getCharts, mainSearch, search, getTracklist]

View File

@ -0,0 +1,13 @@
import { ApiHandler } from '../../../types'
import { searchAll } from '../../../main'
const path: ApiHandler['path'] = '/mainSearch'
const handler: ApiHandler['handler'] = async (req, res) => {
const searchData = await searchAll(String(req.query.term))
res.send(searchData)
}
const apiHandler: ApiHandler = { path, handler }
export default apiHandler

View File

@ -0,0 +1,13 @@
import { ApiHandler } from '../../../types'
import { search } from '../../../main'
const path: ApiHandler['path'] = '/search'
const handler: ApiHandler['handler'] = async (req, res) => {
const searchData = await search(String(req.query.term), String(req.query.type), parseInt(String(req.query.start)), parseInt(String(req.query.nb)))
res.send(searchData)
}
const apiHandler: ApiHandler = { path, handler }
export default apiHandler

View File

@ -1118,10 +1118,10 @@ deezer-js@^0.0.3:
got "^11.8.2"
tough-cookie "^4.0.0"
deezer-js@^0.0.6:
version "0.0.6"
resolved "https://registry.npmjs.org/deezer-js/-/deezer-js-0.0.6.tgz"
integrity sha512-EX8dLLzM8hc1a1fWEi9agwu9MW9HjZxoWTEfzPLGpiJkh/Yix4Z1HM6X3KwBh4Uc90TIlzUdePRY3fmbpcZfig==
deezer-js@^0.0.7:
version "0.0.7"
resolved "https://registry.npmjs.org/deezer-js/-/deezer-js-0.0.7.tgz"
integrity sha512-DCnIGDvgikWSqJd1GJ5jsJ6ieY9VHLaGLMeizTCoAbDNQqzxMB1wDO+u2KI76dBKZIhVJOAuXTe1gZzok7VjrQ==
dependencies:
got "^11.8.2"
tough-cookie "^4.0.0"