🎨 Clean up code
This commit is contained in:
parent
7657ffedef
commit
5e3075dad1
1 changed files with 80 additions and 90 deletions
34
src/Track.js
34
src/Track.js
|
@ -11,7 +11,7 @@ class Track {
|
||||||
* @param {Discord.User | null} user The user who requested the track
|
* @param {Discord.User | null} user The user who requested the track
|
||||||
* @param {Player} player
|
* @param {Player} player
|
||||||
*/
|
*/
|
||||||
constructor(videoData, user, player) {
|
constructor (videoData, user, player) {
|
||||||
/**
|
/**
|
||||||
* The player instantiating the track
|
* The player instantiating the track
|
||||||
* @type {Player}
|
* @type {Player}
|
||||||
|
@ -31,22 +31,18 @@ class Track {
|
||||||
* The video duration (formatted).
|
* The video duration (formatted).
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.duration =
|
this.duration = videoData.durationFormatted ||
|
||||||
videoData.durationFormatted ||
|
`${Math.floor(parseInt(videoData.videoDetails.lengthSeconds) / 60)}:${parseInt(videoData.videoDetails.lengthSeconds) % 60}`
|
||||||
`${Math.floor(parseInt(videoData.videoDetails.lengthSeconds) / 60)}:${
|
|
||||||
parseInt(videoData.videoDetails.lengthSeconds) % 60
|
|
||||||
}`
|
|
||||||
/**
|
/**
|
||||||
* The video description
|
* The video description
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.description = videoData.description;
|
this.description = videoData.description
|
||||||
/**
|
/**
|
||||||
* The video thumbnail
|
* The video thumbnail
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.thumbnail =
|
this.thumbnail = typeof videoData.thumbnail === 'object'
|
||||||
typeof videoData.thumbnail === "object"
|
|
||||||
? videoData.thumbnail.url
|
? videoData.thumbnail.url
|
||||||
: videoData.thumbnail
|
: videoData.thumbnail
|
||||||
/**
|
/**
|
||||||
|
@ -77,7 +73,7 @@ class Track {
|
||||||
* The queue in which the track is
|
* The queue in which the track is
|
||||||
* @type {Queue}
|
* @type {Queue}
|
||||||
*/
|
*/
|
||||||
get queue() {
|
get queue () {
|
||||||
return this.player.queues.find((queue) => queue.tracks.includes(this))
|
return this.player.queues.find((queue) => queue.tracks.includes(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,18 +81,12 @@ class Track {
|
||||||
* The track duration
|
* The track duration
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
get durationMS() {
|
get durationMS () {
|
||||||
const args = this.duration.split(":")
|
const args = this.duration.split(':')
|
||||||
if (args.length === 3) {
|
switch (args.length) {
|
||||||
return (
|
case 3: return parseInt(args[0]) * 60 * 60 * 1000 + parseInt(args[1]) * 60 * 1000 + parseInt(args[2]) * 1000
|
||||||
parseInt(args[0]) * 60 * 60 * 1000 +
|
case 2: return parseInt(args[0]) * 60 * 1000 + parseInt(args[1]) * 1000
|
||||||
parseInt(args[1]) * 60 * 1000 +
|
default: return parseInt(args[0]) * 1000
|
||||||
parseInt(args[2]) * 1000
|
|
||||||
);
|
|
||||||
} else if (args.length === 2) {
|
|
||||||
return parseInt(args[0]) * 60 * 1000 + parseInt(args[1]) * 1000
|
|
||||||
} else {
|
|
||||||
return parseInt(args[0]) * 1000
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue