-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSong.js
60 lines (50 loc) · 1.56 KB
/
Song.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const { escapeMarkdown } = require('discord.js');
const { oneLineTrim } = require('common-tags');
const config = require('./settings');
module.exports = class Song {
constructor(video, member) {
this.name = escapeMarkdown(video.title);
this.id = video.id;
this.length = video.durationSeconds ? parseInt(video.durationSeconds) : parseInt(video.duration) / 1000;
this.member = member;
this.dispatcher = null;
this.playing = false;
}
get url() {
if (!isNaN(this.id)) {
return `https://api.soundcloud.com/tracks/${this.id}/stream?client_id=${config.soundcloudID}`;
} else {
return `https://www.youtube.com/watch?v=${this.id}`;
}
}
get thumbnail() {
const thumbnail = `https://img.youtube.com/vi/${this.id}/mqdefault.jpg`;
return thumbnail;
}
get username() {
const name = `${this.member.user.username}#${this.member.user.discriminator} (${this.member.user.id})`;
return escapeMarkdown(name);
}
get avatar() {
const avatar = `${this.member.user.displayAvatarURL}`;
return avatar;
}
get lengthString() {
return this.constructor.timeString(this.length);
}
timeLeft(currentTime) {
return this.constructor.timeString(this.length - currentTime);
}
toString() {
return `${this.name} (${this.lengthString})`;
}
static timeString(seconds, forceHours = false) {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor(seconds % 3600 / 60);
return oneLineTrim`
${forceHours || hours >= 1 ? `${hours}:` : ''}
${hours >= 1 ? `0${minutes}`.slice(-2) : minutes}:
${`0${Math.floor(seconds % 60)}`.slice(-2)}
`;
}
};