🐛 Fixed author and duration undefined errors (#141)
This commit is contained in:
parent
a6adc0e41f
commit
7657ffedef
1 changed files with 88 additions and 78 deletions
166
src/Track.js
166
src/Track.js
|
@ -6,89 +6,99 @@ 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) {
|
||||||
/**
|
/**
|
||||||
* @param {Object} videoData The video data for this track
|
* The player instantiating the track
|
||||||
* @param {Discord.User | null} user The user who requested the track
|
* @type {Player}
|
||||||
* @param {Player} player
|
|
||||||
*/
|
*/
|
||||||
constructor (videoData, user, player) {
|
this.player = player
|
||||||
/**
|
/**
|
||||||
* The player instantiating the track
|
* The track title
|
||||||
* @type {Player}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.player = player
|
this.title = videoData.title
|
||||||
/**
|
/**
|
||||||
* The track title
|
* The Youtube URL of the track
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.title = videoData.title
|
this.url = videoData.url
|
||||||
/**
|
/**
|
||||||
* The Youtube URL of the track
|
* The video duration (formatted).
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.url = videoData.url
|
this.duration =
|
||||||
/**
|
videoData.durationFormatted ||
|
||||||
* The video duration (formatted).
|
`${Math.floor(parseInt(videoData.videoDetails.lengthSeconds) / 60)}:${
|
||||||
* @type {string}
|
parseInt(videoData.videoDetails.lengthSeconds) % 60
|
||||||
*/
|
}`
|
||||||
this.duration = videoData.durationFormatted
|
/**
|
||||||
/**
|
* 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' ? videoData.thumbnail.url : videoData.thumbnail
|
typeof videoData.thumbnail === "object"
|
||||||
/**
|
? videoData.thumbnail.url
|
||||||
* The video views
|
: videoData.thumbnail
|
||||||
* @type {?number}
|
/**
|
||||||
*/
|
* The video views
|
||||||
this.views = parseInt(videoData.views)
|
* @type {?number}
|
||||||
/**
|
*/
|
||||||
* The video channel
|
this.views = parseInt(videoData.views)
|
||||||
* @type {string}
|
/**
|
||||||
*/
|
* The video channel
|
||||||
this.author = videoData.channel.name
|
* @type {string}
|
||||||
/**
|
*/
|
||||||
* The user who requested the track
|
this.author = videoData.channel
|
||||||
* @type {Discord.User?}
|
? videoData.channel.name
|
||||||
*/
|
: videoData.author.name
|
||||||
this.requestedBy = user
|
/**
|
||||||
/**
|
* The user who requested the track
|
||||||
* Whether the track was added from a playlist
|
* @type {Discord.User?}
|
||||||
* @type {boolean}
|
*/
|
||||||
*/
|
this.requestedBy = user
|
||||||
this.fromPlaylist = videoData.fromPlaylist || false
|
/**
|
||||||
}
|
* Whether the track was added from a playlist
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.fromPlaylist = videoData.fromPlaylist || false
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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) {
|
if (args.length === 3) {
|
||||||
return parseInt(args[0]) * 60 * 60 * 1000 +
|
return (
|
||||||
parseInt(args[1]) * 60 * 1000 +
|
parseInt(args[0]) * 60 * 60 * 1000 +
|
||||||
parseInt(args[2]) * 1000
|
parseInt(args[1]) * 60 * 1000 +
|
||||||
} else if (args.length === 2) {
|
parseInt(args[2]) * 1000
|
||||||
return parseInt(args[0]) * 60 * 1000 +
|
);
|
||||||
parseInt(args[1]) * 1000
|
} else if (args.length === 2) {
|
||||||
} else {
|
return parseInt(args[0]) * 60 * 1000 + parseInt(args[1]) * 1000
|
||||||
return parseInt(args[0]) * 1000
|
} else {
|
||||||
}
|
return parseInt(args[0]) * 1000
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Track
|
module.exports = Track
|
||||||
|
|
Loading…
Reference in a new issue