2020-04-16 19:26:00 +00:00
|
|
|
<template>
|
2020-04-17 19:16:59 +00:00
|
|
|
<div id="main_search" class="search_tabcontent">
|
2020-04-16 19:26:00 +00:00
|
|
|
<template v-for="(section, index) in results.ORDER">
|
|
|
|
<div
|
|
|
|
class="search_section"
|
|
|
|
v-if="(section !== 'TOP_RESULT' && results[section].data.length > 0) || (results[section].length > 0)"
|
|
|
|
:key="`section-${index}`"
|
|
|
|
>
|
2020-04-17 19:16:59 +00:00
|
|
|
<h1 @click="changeSearchTab(section)">{{ toTitleCase(section) }}</h1>
|
|
|
|
<div v-if="section === 'TOP_RESULT'" class="top_result">
|
2020-04-16 19:26:00 +00:00
|
|
|
<div class="cover_container">
|
|
|
|
<img
|
2020-04-17 19:16:59 +00:00
|
|
|
:src="getTopResultImgURL2(results.TOP_RESULT)"
|
2020-04-16 19:26:00 +00:00
|
|
|
:class="(results.TOP_RESULT[0].__TYPE__ == 'artist' ? 'circle' : 'rounded') + ' coverart'"
|
|
|
|
/>
|
|
|
|
<div
|
|
|
|
role="button"
|
|
|
|
aria-label="download"
|
2020-04-17 19:16:59 +00:00
|
|
|
@contextmenu="openQualityModal(event)"
|
|
|
|
@click="addToQueue(event)"
|
|
|
|
:data-link="topResult.buttonURL"
|
2020-04-16 19:26:00 +00:00
|
|
|
class="download_overlay"
|
|
|
|
>
|
|
|
|
<i class="material-icons">get_app</i>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="info_box">
|
2020-04-17 19:16:59 +00:00
|
|
|
<p class="primary-text">{{ topResult.primaryText }}</p>
|
|
|
|
<p class="secondary-text">{{ topResult.secondaryText }}</p>
|
|
|
|
<span class="tag">{{ topResult.tag }}</span>
|
2020-04-16 19:26:00 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-04-17 19:16:59 +00:00
|
|
|
<div v-else-if="section === 'TRACK'">
|
2020-04-16 19:26:00 +00:00
|
|
|
<table class="tracks_table">
|
2020-04-17 19:16:59 +00:00
|
|
|
<tr v-for="track in results.TRACK.data.slice(0, 6)" :key="track.SNG_ID" class="track_row">
|
2020-04-16 19:26:00 +00:00
|
|
|
<td style="width: 48px; text-align: center;">
|
|
|
|
<img
|
|
|
|
class="rounded coverart"
|
|
|
|
v-bind:src="'https://e-cdns-images.dzcdn.net/images/cover/'+track.ALB_PICTURE+'/32x32-000000-80-0-0.jpg'"
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
<td class="breakline">{{track.SNG_TITLE + (track.VERSION ? ' '+track.VERSION : '')}}</td>
|
2020-04-17 19:16:59 +00:00
|
|
|
<td class="breakline artists___">
|
|
|
|
<!-- <span v-for="artist in track.ARTISTS" :key="artist.ART_ID">{{artist.ART_NAME}}</span> -->
|
|
|
|
<span>{{track.ARTISTS.map(a => a.ART_NAME).join(' ')}}</span>
|
2020-04-16 19:26:00 +00:00
|
|
|
</td>
|
|
|
|
<td class="breakline">{{track.ALB_TITLE}}</td>
|
|
|
|
<td>{{convertDuration(track.DURATION)}}</td>
|
|
|
|
<td
|
2020-04-17 19:16:59 +00:00
|
|
|
class="clickable"
|
2020-04-16 19:26:00 +00:00
|
|
|
role="button"
|
|
|
|
aria-label="download"
|
2020-04-17 19:16:59 +00:00
|
|
|
@contextmenu="openQualityModal(event)"
|
|
|
|
@click="addToQueue(event)"
|
|
|
|
:data-link="'https://www.deezer.com/track/' + track.SNG_ID"
|
2020-04-16 19:26:00 +00:00
|
|
|
style="width: 56px; text-align: center;"
|
|
|
|
>
|
|
|
|
<i class="material-icons">get_app</i>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
2020-04-17 19:16:59 +00:00
|
|
|
</div>
|
|
|
|
<!-- <div v-else-if="section != 'TRACK' && section != 'TOP_RESULT'" class="release_grid firstrow_only"> -->
|
|
|
|
<div v-else class="release_grid firstrow_only">
|
|
|
|
<div v-for="(release, index) in results[section].data.slice(0, 10)" :key="`release-${index}`" class="release">
|
2020-04-16 19:26:00 +00:00
|
|
|
<div class="cover_container">
|
|
|
|
<img
|
|
|
|
v-bind:class="(section == 'ARTIST' ? 'circle' : 'rounded') + ' coverart'"
|
|
|
|
v-bind:src="(section == 'ARTIST' ? 'https://e-cdns-images.dzcdn.net/images/artist/' + release.ART_PICTURE : section == 'ALBUM' ? 'https://e-cdns-images.dzcdn.net/images/cover/' + release.ALB_PICTURE : section == 'PLAYLIST' ? 'https://e-cdns-images.dzcdn.net/images/'+ release.PICTURE_TYPE +'/' + release.PLAYLIST_PICTURE : 'https://e-cdns-images.dzcdn.net/images/cover/' ) + '/156x156-000000-80-0-0.jpg'"
|
|
|
|
/>
|
|
|
|
<div
|
|
|
|
role="button"
|
|
|
|
aria-label="download"
|
|
|
|
v-on:contextmenu="openQualityModal(event)"
|
|
|
|
v-on:click="addToQueue(event)"
|
|
|
|
v-bind:data-link="'https://deezer.com/'+(section == 'ARTIST' ? 'artist/'+release.ART_ID : section == 'ALBUM' ? 'album/'+release.ALB_ID : section == 'PLAYLIST' ? 'playlist/'+release.PLAYLIST_ID : '')"
|
|
|
|
class="download_overlay"
|
|
|
|
>
|
|
|
|
<i class="material-icons">get_app</i>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<p
|
|
|
|
class="primary-text"
|
|
|
|
>{{ section == 'ARTIST' ? release.ART_NAME : section == 'ALBUM' ? release.ALB_TITLE : section == 'PLAYLIST' ? release.TITLE : '' }}</p>
|
|
|
|
<p
|
|
|
|
class="secondary-text"
|
|
|
|
>{{ section == 'ARTIST' ? numberWithDots(release.NB_FAN) + ' fans' : section == 'ALBUM' ? release.ART_NAME+' - '+release.NUMBER_TRACK+' tracks' : section == 'PLAYLIST' ? release.NB_SONG+' tracks' : '' }}</p>
|
|
|
|
</div>
|
2020-04-17 19:16:59 +00:00
|
|
|
</div>
|
2020-04-16 19:26:00 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<div
|
|
|
|
v-if="results.ORDER.every(section => section == 'TOP_RESULT' ? results[section].length == 0 : results[section].data.length == 0)"
|
|
|
|
>
|
|
|
|
<h1>No results</h1>
|
|
|
|
</div>
|
2020-04-17 19:16:59 +00:00
|
|
|
<p>marco</p>
|
2020-04-16 19:26:00 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
module.exports = {
|
|
|
|
data: () => ({
|
|
|
|
results: {
|
|
|
|
QUERY: '',
|
|
|
|
ORDER: [],
|
|
|
|
ALBUM: {},
|
|
|
|
ARTIST: {},
|
|
|
|
TRACK: {},
|
|
|
|
TOP_RESULT: [],
|
|
|
|
PLAYLIST: {}
|
|
|
|
},
|
2020-04-17 19:16:59 +00:00
|
|
|
topResult: {
|
|
|
|
imgURL: '',
|
|
|
|
buttonURL: '',
|
|
|
|
primaryText: '',
|
|
|
|
secondaryText: '',
|
|
|
|
tag: ''
|
|
|
|
}
|
2020-04-16 19:26:00 +00:00
|
|
|
}),
|
|
|
|
methods: {
|
|
|
|
changeSearchTab(section) {
|
|
|
|
if (section != 'TOP_RESULT') clickElement('search_' + section.toLowerCase() + '_tab')
|
|
|
|
},
|
|
|
|
addToQueue: function(e) {
|
|
|
|
sendAddToQueue(e.currentTarget.dataset.link)
|
|
|
|
},
|
|
|
|
openQualityModal: function(e) {
|
|
|
|
e.preventDefault()
|
|
|
|
openQualityModal(e.currentTarget.dataset.link)
|
|
|
|
},
|
|
|
|
handleMainSearch(result) {
|
|
|
|
this.results = result
|
|
|
|
},
|
2020-04-17 19:16:59 +00:00
|
|
|
toTitleCase(name) {
|
2020-04-16 19:26:00 +00:00
|
|
|
if ('string' !== typeof name) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
name = name.replace('_', ' ')
|
|
|
|
|
|
|
|
// Step 1. Lowercase the string
|
|
|
|
name = name.toLowerCase()
|
|
|
|
|
|
|
|
// Step 2. Split the string into an array of strings
|
|
|
|
name = name.split(' ')
|
|
|
|
|
|
|
|
// Step 3. Create the FOR loop
|
|
|
|
for (var i = 0; i < name.length; i++) {
|
|
|
|
name[i] = name[i].charAt(0).toUpperCase() + name[i].slice(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
name = name.join(' ')
|
|
|
|
|
|
|
|
return name
|
|
|
|
},
|
2020-04-17 19:16:59 +00:00
|
|
|
getTopResultImgURL(results) {
|
|
|
|
if (results.TOP_RESULT.length === 0) {
|
|
|
|
this.topResult.imgURL = ''
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const topResult = results.TOP_RESULT[0]
|
|
|
|
const topResultType = topResult.__TYPE__
|
|
|
|
|
|
|
|
switch (topResultType) {
|
|
|
|
case 'artist':
|
|
|
|
this.topResult.imgURL = 'https://e-cdns-images.dzcdn.net/images/artist/' + topResult.ART_PICTURE
|
|
|
|
break
|
|
|
|
case 'album':
|
|
|
|
this.topResult.imgURL = 'https://e-cdns-images.dzcdn.net/images/cover/' + topResult.ALB_PICTURE
|
|
|
|
break
|
|
|
|
case 'playlist':
|
|
|
|
this.topResult.imgURL =
|
|
|
|
'https://e-cdns-images.dzcdn.net/images/' + topResult.PICTURE_TYPE + '/' + topResult.PLAYLIST_PICTURE
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
this.topResult.imgURL = 'https://e-cdns-images.dzcdn.net/images/cover/'
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
this.topResult.imgURL += '/156x156-000000-80-0-0.jpg'
|
|
|
|
},
|
|
|
|
getTopResultImgURL2(topRes) {
|
|
|
|
if (topRes.length === 0) {
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
|
|
|
|
const topResult = topRes[0]
|
|
|
|
const topResultType = topResult.__TYPE__
|
|
|
|
let imgURL = ''
|
|
|
|
|
|
|
|
switch (topResultType) {
|
|
|
|
case 'artist':
|
|
|
|
imgURL = 'https://e-cdns-images.dzcdn.net/images/artist/' + topResult.ART_PICTURE
|
|
|
|
break
|
|
|
|
case 'album':
|
|
|
|
imgURL = 'https://e-cdns-images.dzcdn.net/images/cover/' + topResult.ALB_PICTURE
|
|
|
|
break
|
|
|
|
case 'playlist':
|
|
|
|
imgURL =
|
|
|
|
'https://e-cdns-images.dzcdn.net/images/' + topResult.PICTURE_TYPE + '/' + topResult.PLAYLIST_PICTURE
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
imgURL = 'https://e-cdns-images.dzcdn.net/images/cover/'
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
imgURL += '/156x156-000000-80-0-0.jpg'
|
|
|
|
|
|
|
|
return imgURL
|
|
|
|
},
|
|
|
|
getTopResultButtonURL(results) {
|
|
|
|
if (results.TOP_RESULT.length === 0) {
|
|
|
|
this.topResult.buttonURL = ''
|
2020-04-16 19:26:00 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-17 19:16:59 +00:00
|
|
|
const topResult = results.TOP_RESULT[0]
|
|
|
|
const topResultType = topResult.__TYPE__
|
|
|
|
|
|
|
|
this.topResult.buttonURL = 'https://deezer.com/' + topResultType + '/'
|
2020-04-16 19:26:00 +00:00
|
|
|
|
|
|
|
switch (topResultType) {
|
|
|
|
case 'artist':
|
2020-04-17 19:16:59 +00:00
|
|
|
this.topResult.buttonURL += topResult.ART_ID
|
2020-04-16 19:26:00 +00:00
|
|
|
break
|
|
|
|
case 'album':
|
2020-04-17 19:16:59 +00:00
|
|
|
this.topResult.buttonURL += topResult.ALB_ID
|
2020-04-16 19:26:00 +00:00
|
|
|
break
|
|
|
|
case 'playlist':
|
2020-04-17 19:16:59 +00:00
|
|
|
this.topResult.buttonURL += topResult.PLAYLIST_ID
|
2020-04-16 19:26:00 +00:00
|
|
|
break
|
|
|
|
default:
|
2020-04-17 19:16:59 +00:00
|
|
|
this.topResult.buttonURL += ''
|
2020-04-16 19:26:00 +00:00
|
|
|
break
|
|
|
|
}
|
2020-04-17 19:16:59 +00:00
|
|
|
},
|
|
|
|
getTopResultText(results) {
|
|
|
|
if (results.TOP_RESULT.length === 0) {
|
|
|
|
this.topResult.primaryText = ''
|
|
|
|
this.topResult.secondaryText = ''
|
|
|
|
this.topResult.tag = ''
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const topResult = results.TOP_RESULT[0]
|
|
|
|
const topResultType = topResult.__TYPE__
|
|
|
|
|
|
|
|
this.topResult.tag = this.toTitleCase(topResultType)
|
2020-04-16 19:26:00 +00:00
|
|
|
|
2020-04-17 19:16:59 +00:00
|
|
|
switch (topResultType) {
|
|
|
|
case 'artist':
|
|
|
|
this.topResult.primaryText = topResult.ART_NAME
|
|
|
|
this.topResult.secondaryText = numberWithDots(topResult.NB_FAN) + ' fans'
|
|
|
|
break
|
|
|
|
case 'album':
|
|
|
|
this.topResult.primaryText = topResult.ALB_TITLE
|
|
|
|
this.topResult.secondaryText = 'by ' + topResult.ART_NAME + ' - ' + topResult.NUMBER_TRACK + ' tracks'
|
|
|
|
break
|
|
|
|
case 'playlist':
|
|
|
|
this.topResult.primaryText = topResult.TITLE
|
|
|
|
this.topResult.secondaryText = 'by ' + topResult.PARENT_USERNAME + ' - ' + topResult.NB_SONG + ' tracks'
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
this.topResult.primaryText = ''
|
|
|
|
this.topResult.secondaryText = ''
|
|
|
|
break
|
|
|
|
}
|
2020-04-16 19:26:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
results(newRes, oldRes) {
|
|
|
|
console.log('new', newRes)
|
|
|
|
console.log('old', oldRes)
|
|
|
|
|
2020-04-17 19:16:59 +00:00
|
|
|
this.getTopResultImgURL(newRes)
|
|
|
|
this.getTopResultButtonURL(newRes)
|
|
|
|
this.getTopResultText(newRes)
|
2020-04-16 19:26:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
socket.on('mainSearch', this.handleMainSearch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
2020-04-17 19:16:59 +00:00
|
|
|
.artists > :not(:last-child)::after {
|
|
|
|
content: ' ';
|
|
|
|
}
|
2020-04-16 19:26:00 +00:00
|
|
|
</style>
|