🎨 Clean up code

This commit is contained in:
Androz2091 2020-11-08 14:23:34 +01:00
parent 7657ffedef
commit 5e3075dad1

View file

@ -6,99 +6,89 @@ const Player = require('./Player')
* Represents a track. * Represents a track.
*/ */
class Track { class Track {
/**
* @param {Object} videoData The video data for this track
* @param {Discord.User | null} user The user who requested the track
* @param {Player} player
*/
constructor(videoData, user, player) {
/** /**
* The player instantiating the track * @param {Object} videoData The video data for this track
* @type {Player} * @param {Discord.User | null} user The user who requested the track
* @param {Player} player
*/ */
this.player = player constructor (videoData, user, player) {
/** /**
* The track title * The player instantiating the track
* @type {string} * @type {Player}
*/ */
this.title = videoData.title this.player = player
/** /**
* The Youtube URL of the track * The track title
* @type {string} * @type {string}
*/ */
this.url = videoData.url this.title = videoData.title
/** /**
* The video duration (formatted). * The Youtube URL of the track
* @type {string} * @type {string}
*/ */
this.duration = this.url = videoData.url
videoData.durationFormatted || /**
`${Math.floor(parseInt(videoData.videoDetails.lengthSeconds) / 60)}:${ * The video duration (formatted).
parseInt(videoData.videoDetails.lengthSeconds) % 60 * @type {string}
}` */
/** this.duration = videoData.durationFormatted ||
* The video description `${Math.floor(parseInt(videoData.videoDetails.lengthSeconds) / 60)}:${parseInt(videoData.videoDetails.lengthSeconds) % 60}`
* @type {string} /**
*/ * The video description
this.description = videoData.description; * @type {string}
/** */
* The video thumbnail this.description = videoData.description
* @type {string} /**
*/ * The video thumbnail
this.thumbnail = * @type {string}
typeof videoData.thumbnail === "object" */
? videoData.thumbnail.url this.thumbnail = typeof videoData.thumbnail === 'object'
: videoData.thumbnail ? videoData.thumbnail.url
/** : videoData.thumbnail
* The video views /**
* @type {?number} * The video views
*/ * @type {?number}
this.views = parseInt(videoData.views) */
/** this.views = parseInt(videoData.views)
* The video channel /**
* @type {string} * The video channel
*/ * @type {string}
this.author = videoData.channel */
? videoData.channel.name this.author = videoData.channel
: videoData.author.name ? videoData.channel.name
/** : videoData.author.name
* The user who requested the track /**
* @type {Discord.User?} * The user who requested the track
*/ * @type {Discord.User?}
this.requestedBy = user */
/** this.requestedBy = user
* Whether the track was added from a playlist /**
* @type {boolean} * Whether the track was added from a playlist
*/ * @type {boolean}
this.fromPlaylist = videoData.fromPlaylist || false */
} this.fromPlaylist = videoData.fromPlaylist || false
}
/**
* The queue in which the track is /**
* @type {Queue} * The queue in which the track is
*/ * @type {Queue}
get queue() { */
return this.player.queues.find((queue) => queue.tracks.includes(this)) get queue () {
} return this.player.queues.find((queue) => queue.tracks.includes(this))
}
/**
* The track duration /**
* @type {number} * The track duration
*/ * @type {number}
get durationMS() { */
const args = this.duration.split(":") get durationMS () {
if (args.length === 3) { const args = this.duration.split(':')
return ( switch (args.length) {
parseInt(args[0]) * 60 * 60 * 1000 + case 3: return parseInt(args[0]) * 60 * 60 * 1000 + parseInt(args[1]) * 60 * 1000 + parseInt(args[2]) * 1000
parseInt(args[1]) * 60 * 1000 + case 2: return parseInt(args[0]) * 60 * 1000 + parseInt(args[1]) * 1000
parseInt(args[2]) * 1000 default: return parseInt(args[0]) * 1000
); }
} else if (args.length === 2) {
return parseInt(args[0]) * 60 * 1000 + parseInt(args[1]) * 1000
} else {
return parseInt(args[0]) * 1000
} }
}
} }
module.exports = Track module.exports = Track