🐛 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
26
src/Track.js
26
src/Track.js
|
@ -31,17 +31,24 @@ class Track {
|
||||||
* The video duration (formatted).
|
* The video duration (formatted).
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.duration = videoData.durationFormatted
|
this.duration =
|
||||||
|
videoData.durationFormatted ||
|
||||||
|
`${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 = typeof videoData.thumbnail === 'object' ? videoData.thumbnail.url : videoData.thumbnail
|
this.thumbnail =
|
||||||
|
typeof videoData.thumbnail === "object"
|
||||||
|
? videoData.thumbnail.url
|
||||||
|
: videoData.thumbnail
|
||||||
/**
|
/**
|
||||||
* The video views
|
* The video views
|
||||||
* @type {?number}
|
* @type {?number}
|
||||||
|
@ -51,7 +58,9 @@ class Track {
|
||||||
* The video channel
|
* The video channel
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.author = videoData.channel.name
|
this.author = videoData.channel
|
||||||
|
? videoData.channel.name
|
||||||
|
: videoData.author.name
|
||||||
/**
|
/**
|
||||||
* The user who requested the track
|
* The user who requested the track
|
||||||
* @type {Discord.User?}
|
* @type {Discord.User?}
|
||||||
|
@ -77,14 +86,15 @@ class Track {
|
||||||
* @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[0]) * 60 * 60 * 1000 +
|
||||||
parseInt(args[1]) * 60 * 1000 +
|
parseInt(args[1]) * 60 * 1000 +
|
||||||
parseInt(args[2]) * 1000
|
parseInt(args[2]) * 1000
|
||||||
|
);
|
||||||
} else if (args.length === 2) {
|
} else if (args.length === 2) {
|
||||||
return parseInt(args[0]) * 60 * 1000 +
|
return parseInt(args[0]) * 60 * 1000 + parseInt(args[1]) * 1000
|
||||||
parseInt(args[1]) * 1000
|
|
||||||
} else {
|
} else {
|
||||||
return parseInt(args[0]) * 1000
|
return parseInt(args[0]) * 1000
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue