2020-04-28 18:42:22 +00:00
|
|
|
import { socket } from '../socket.js'
|
|
|
|
import { albumView, artistView } from '../tabs.js'
|
|
|
|
import Downloads from '../downloads.js'
|
|
|
|
import QualityModal from '../quality-modal.js'
|
|
|
|
import TrackPreview from '../track-preview.js'
|
2020-04-21 20:20:19 +00:00
|
|
|
|
2020-04-23 19:03:12 +00:00
|
|
|
const TracklistTab = new Vue({
|
2020-05-03 20:08:59 +00:00
|
|
|
data: () => ({
|
2020-04-21 20:20:19 +00:00
|
|
|
title: '',
|
|
|
|
metadata: '',
|
|
|
|
release_date: '',
|
|
|
|
label: '',
|
|
|
|
explicit: false,
|
|
|
|
image: '',
|
|
|
|
type: '',
|
|
|
|
link: '',
|
|
|
|
head: null,
|
|
|
|
body: []
|
2020-05-03 20:08:59 +00:00
|
|
|
}),
|
2020-04-21 20:20:19 +00:00
|
|
|
methods: {
|
2020-04-22 20:06:59 +00:00
|
|
|
artistView,
|
|
|
|
albumView,
|
2020-04-28 18:42:22 +00:00
|
|
|
playPausePreview: TrackPreview.playPausePreview,
|
2020-04-23 19:03:12 +00:00
|
|
|
reset() {
|
|
|
|
this.title = 'Loading...'
|
|
|
|
this.image = ''
|
|
|
|
this.metadata = ''
|
|
|
|
this.label = ''
|
|
|
|
this.release_date = ''
|
|
|
|
this.explicit = false
|
|
|
|
this.type = ''
|
|
|
|
this.head = []
|
|
|
|
this.body = []
|
|
|
|
},
|
2020-05-03 20:08:59 +00:00
|
|
|
addToQueue(e) {
|
2020-04-21 20:20:19 +00:00
|
|
|
e.stopPropagation()
|
2020-04-22 20:06:59 +00:00
|
|
|
Downloads.sendAddToQueue(e.currentTarget.dataset.link)
|
2020-04-21 20:20:19 +00:00
|
|
|
},
|
2020-05-03 20:08:59 +00:00
|
|
|
openQualityModal(e) {
|
2020-04-22 20:06:59 +00:00
|
|
|
QualityModal.open(e.currentTarget.dataset.link)
|
2020-04-21 20:20:19 +00:00
|
|
|
},
|
2020-05-03 20:08:59 +00:00
|
|
|
toggleAll(e) {
|
2020-04-21 20:20:19 +00:00
|
|
|
this.body.forEach(item => {
|
|
|
|
if (item.type == 'track') {
|
|
|
|
item.selected = e.currentTarget.checked
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2020-05-03 20:08:59 +00:00
|
|
|
selectedLinks() {
|
2020-04-21 20:20:19 +00:00
|
|
|
var selected = []
|
|
|
|
if (this.body) {
|
|
|
|
this.body.forEach(item => {
|
|
|
|
if (item.type == 'track' && item.selected) selected.push(item.link)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return selected.join(';')
|
|
|
|
},
|
|
|
|
convertDuration(duration) {
|
|
|
|
//convert from seconds only to mm:ss format
|
|
|
|
let mm, ss
|
|
|
|
mm = Math.floor(duration / 60)
|
|
|
|
ss = duration - mm * 60
|
|
|
|
//add leading zero if ss < 0
|
|
|
|
if (ss < 10) {
|
|
|
|
ss = '0' + ss
|
|
|
|
}
|
|
|
|
return mm + ':' + ss
|
2020-04-23 19:03:12 +00:00
|
|
|
},
|
|
|
|
showAlbum(data) {
|
|
|
|
this.type = 'Album'
|
|
|
|
this.link = `https://www.deezer.com/album/${data.id}`
|
|
|
|
this.title = data.title
|
|
|
|
this.explicit = data.explicit_lyrics
|
|
|
|
this.label = data.label
|
|
|
|
this.metadata = `${data.artist.name} • ${data.tracks.length} songs`
|
|
|
|
this.release_date = data.release_date.substring(0, 10)
|
|
|
|
this.image = data.cover_xl
|
|
|
|
this.head = [
|
|
|
|
{ title: '<i class="material-icons">music_note</i>', width: '24px' },
|
|
|
|
{ title: '#' },
|
|
|
|
{ title: 'Song' },
|
|
|
|
{ title: 'Artist' },
|
|
|
|
{ title: '<i class="material-icons">timer</i>', width: '40px' }
|
|
|
|
]
|
|
|
|
if (_.isEmpty(data.tracks)) {
|
|
|
|
console.log('show e lodash ok')
|
|
|
|
|
|
|
|
this.body = null
|
|
|
|
} else {
|
|
|
|
this.body = data.tracks
|
|
|
|
}
|
|
|
|
},
|
|
|
|
showPlaylist(data) {
|
|
|
|
this.type = 'Playlist'
|
|
|
|
this.link = `https://www.deezer.com/playlist/${data.id}`
|
|
|
|
this.title = data.title
|
|
|
|
this.image = data.picture_xl
|
|
|
|
this.release_date = data.creation_date.substring(0, 10)
|
|
|
|
this.metadata = `by ${data.creator.name} • ${data.tracks.length} songs`
|
|
|
|
this.head = [
|
|
|
|
{ title: '<i class="material-icons">music_note</i>', width: '24px' },
|
|
|
|
{ title: '#' },
|
|
|
|
{ title: 'Song' },
|
|
|
|
{ title: 'Artist' },
|
|
|
|
{ title: 'Album' },
|
|
|
|
{ title: '<i class="material-icons">timer</i>', width: '40px' }
|
|
|
|
]
|
|
|
|
if (_.isEmpty(data.tracks)) {
|
|
|
|
this.body = null
|
|
|
|
} else {
|
|
|
|
this.body = data.tracks
|
|
|
|
}
|
2020-04-21 20:20:19 +00:00
|
|
|
}
|
2020-04-22 20:06:59 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
2020-04-23 19:03:12 +00:00
|
|
|
socket.on('show_album', this.showAlbum)
|
|
|
|
socket.on('show_playlist', this.showPlaylist)
|
2020-04-21 20:20:19 +00:00
|
|
|
}
|
2020-04-23 19:26:47 +00:00
|
|
|
}).$mount('#tracklist_tab')
|
2020-04-21 20:20:19 +00:00
|
|
|
|
2020-04-23 19:03:12 +00:00
|
|
|
export default TracklistTab
|