2020-04-21 20:20:19 +00:00
|
|
|
import { socket } from './socket.js'
|
2020-04-23 19:03:12 +00:00
|
|
|
import { artistView, albumView } from './tabs.js'
|
2020-04-22 20:06:59 +00:00
|
|
|
import Downloads from './downloads.js'
|
|
|
|
import QualityModal from './quality-modal.js'
|
2020-04-21 20:20:19 +00:00
|
|
|
|
2020-04-23 19:03:12 +00:00
|
|
|
const TracklistTab = new Vue({
|
2020-04-21 20:20:19 +00:00
|
|
|
data: {
|
|
|
|
title: '',
|
|
|
|
metadata: '',
|
|
|
|
release_date: '',
|
|
|
|
label: '',
|
|
|
|
explicit: false,
|
|
|
|
image: '',
|
|
|
|
type: '',
|
|
|
|
link: '',
|
|
|
|
head: null,
|
|
|
|
body: []
|
|
|
|
},
|
|
|
|
methods: {
|
2020-04-22 20:06:59 +00:00
|
|
|
artistView,
|
|
|
|
albumView,
|
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-04-21 20:20:19 +00:00
|
|
|
addToQueue: function (e) {
|
|
|
|
e.stopPropagation()
|
2020-04-22 20:06:59 +00:00
|
|
|
Downloads.sendAddToQueue(e.currentTarget.dataset.link)
|
2020-04-21 20:20:19 +00:00
|
|
|
},
|
|
|
|
openQualityModal: function (e) {
|
|
|
|
e.preventDefault()
|
2020-04-22 20:06:59 +00:00
|
|
|
QualityModal.open(e.currentTarget.dataset.link)
|
2020-04-21 20:20:19 +00:00
|
|
|
},
|
|
|
|
toggleAll: function (e) {
|
|
|
|
this.body.forEach(item => {
|
|
|
|
if (item.type == 'track') {
|
|
|
|
item.selected = e.currentTarget.checked
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
selectedLinks: function () {
|
|
|
|
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
|