Merge pull request #42 from jakexks/song-length-limit
Added a restriction on maximum video length
This commit is contained in:
commit
3815634971
|
@ -195,6 +195,8 @@ func add(user *gumble.User, username, url string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if fmt.Sprint(err) == "video exceeds the maximum allowed duration." {
|
||||||
|
dj.SendPrivateMessage(user, VIDEO_TOO_LONG_MSG)
|
||||||
} else {
|
} else {
|
||||||
dj.SendPrivateMessage(user, INVALID_YOUTUBE_ID_MSG)
|
dj.SendPrivateMessage(user, INVALID_YOUTUBE_ID_MSG)
|
||||||
}
|
}
|
||||||
|
@ -208,7 +210,7 @@ func add(user *gumble.User, username, url string) {
|
||||||
oldLength := dj.queue.Len()
|
oldLength := dj.queue.Len()
|
||||||
if newPlaylist, err := NewPlaylist(username, shortUrl); err == nil {
|
if newPlaylist, err := NewPlaylist(username, shortUrl); err == nil {
|
||||||
dj.client.Self.Channel.Send(fmt.Sprintf(PLAYLIST_ADDED_HTML, username, newPlaylist.title), false)
|
dj.client.Self.Channel.Send(fmt.Sprintf(PLAYLIST_ADDED_HTML, username, newPlaylist.title), false)
|
||||||
if oldLength == 0 && !dj.audioStream.IsPlaying() {
|
if oldLength == 0 && dj.queue.Len() != 0 && !dj.audioStream.IsPlaying() {
|
||||||
if err := dj.queue.CurrentSong().Download(); err == nil {
|
if err := dj.queue.CurrentSong().Download(); err == nil {
|
||||||
dj.queue.CurrentSong().Play()
|
dj.queue.CurrentSong().Play()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,6 +22,9 @@ PlaylistSkipRatio = 0.5
|
||||||
# NOTE: If you do not want a comment by default, set the variable equal to an empty string ("").
|
# NOTE: If you do not want a comment by default, set the variable equal to an empty string ("").
|
||||||
DefaultComment = "Hello! I am a bot. Type !help for a list of commands."
|
DefaultComment = "Hello! I am a bot. Type !help for a list of commands."
|
||||||
|
|
||||||
|
# Maximum song duration in seconds (0 = unristrcted)
|
||||||
|
# Default Value: 0
|
||||||
|
MaxSongDuration = 0
|
||||||
|
|
||||||
[Cache]
|
[Cache]
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ type DjConfig struct {
|
||||||
SkipRatio float32
|
SkipRatio float32
|
||||||
PlaylistSkipRatio float32
|
PlaylistSkipRatio float32
|
||||||
DefaultComment string
|
DefaultComment string
|
||||||
|
MaxSongDuration int
|
||||||
}
|
}
|
||||||
Cache struct {
|
Cache struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
|
|
10
playlist.go
10
playlist.go
|
@ -58,9 +58,9 @@ func NewPlaylist(user, id string) (*Playlist, error) {
|
||||||
id: id,
|
id: id,
|
||||||
title: playlistTitle,
|
title: playlistTitle,
|
||||||
}
|
}
|
||||||
|
j := 0
|
||||||
for i := 0; i < playlistItems; i++ {
|
for i := 0; i < playlistItems; i++ {
|
||||||
index := strconv.Itoa(i)
|
index := strconv.Itoa(j)
|
||||||
songTitle, _ := jq.String("data", "items", index, "video", "title")
|
songTitle, _ := jq.String("data", "items", index, "video", "title")
|
||||||
songId, _ := jq.String("data", "items", index, "video", "id")
|
songId, _ := jq.String("data", "items", index, "video", "id")
|
||||||
songThumbnail, _ := jq.String("data", "items", index, "video", "thumbnail", "hqDefault")
|
songThumbnail, _ := jq.String("data", "items", index, "video", "thumbnail", "hqDefault")
|
||||||
|
@ -75,7 +75,11 @@ func NewPlaylist(user, id string) (*Playlist, error) {
|
||||||
playlist: playlist,
|
playlist: playlist,
|
||||||
dontSkip: false,
|
dontSkip: false,
|
||||||
}
|
}
|
||||||
dj.queue.AddSong(newSong)
|
// Don't spam the chat if a playlist contains songs that are too long
|
||||||
|
if dj.conf.General.MaxSongDuration == 0 || duration <= dj.conf.General.MaxSongDuration {
|
||||||
|
dj.queue.AddSong(newSong)
|
||||||
|
j += 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return playlist, nil
|
return playlist, nil
|
||||||
|
|
4
song.go
4
song.go
|
@ -60,6 +60,10 @@ func NewSong(user, id string, playlist *Playlist) (*Song, error) {
|
||||||
duration, _ := jq.Int("data", "duration")
|
duration, _ := jq.Int("data", "duration")
|
||||||
videoDuration := fmt.Sprintf("%d:%02d", duration/60, duration%60)
|
videoDuration := fmt.Sprintf("%d:%02d", duration/60, duration%60)
|
||||||
|
|
||||||
|
if dj.conf.General.MaxSongDuration > 0 && duration > dj.conf.General.MaxSongDuration {
|
||||||
|
return nil, errors.New("video exceeds the maximum allowed duration.")
|
||||||
|
}
|
||||||
|
|
||||||
song := &Song{
|
song := &Song{
|
||||||
submitter: user,
|
submitter: user,
|
||||||
title: videoTitle,
|
title: videoTitle,
|
||||||
|
|
|
@ -22,6 +22,9 @@ const CHANNEL_DOES_NOT_EXIST_MSG = "The channel you specified does not exist."
|
||||||
// Message shown to users when they attempt to add an invalid URL to the queue.
|
// Message shown to users when they attempt to add an invalid URL to the queue.
|
||||||
const INVALID_URL_MSG = "The URL you submitted does not match the required format."
|
const INVALID_URL_MSG = "The URL you submitted does not match the required format."
|
||||||
|
|
||||||
|
// Message shown to users when they attempt to add a video that's too long
|
||||||
|
const VIDEO_TOO_LONG_MSG = "The video you submitted exceeds the duration allowed by the server."
|
||||||
|
|
||||||
// Message shown to users when they attempt to perform an action on a song when
|
// Message shown to users when they attempt to perform an action on a song when
|
||||||
// no song is playing.
|
// no song is playing.
|
||||||
const NO_MUSIC_PLAYING_MSG = "There is no music playing at the moment."
|
const NO_MUSIC_PLAYING_MSG = "There is no music playing at the moment."
|
||||||
|
|
Reference in a new issue