diff --git a/config.gcfg b/config.gcfg index 408f51b..4f75aa9 100644 --- a/config.gcfg +++ b/config.gcfg @@ -26,6 +26,10 @@ DefaultComment = "Hello! I am a bot. Type !help for a list of commands." # Default Value: 0 MaxSongDuration = 0 +# Maximum songs per playlist (0 = unrestricted) +# Default Value: 50 +MaxSongPerPlaylist = 50 + # Is playlist shuffling enabled when the bot starts? # Default Value: false AutomaticShuffleOn = false diff --git a/parseconfig.go b/parseconfig.go index c69e8b3..a4df46b 100644 --- a/parseconfig.go +++ b/parseconfig.go @@ -22,6 +22,7 @@ type DjConfig struct { PlaylistSkipRatio float32 DefaultComment string MaxSongDuration int + MaxSongPerPlaylist int AutomaticShuffleOn bool } Cache struct { diff --git a/service_youtube.go b/service_youtube.go index 56deef0..99dbced 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -173,9 +173,17 @@ func (yt YouTube) NewPlaylist(user *gumble.User, id string) ([]Song, error) { songArray = append(songArray, song) } } - if pageToken, err = apiResponse.String("nextPageToken"); err != nil{ + if pageToken, err = apiResponse.String("nextPageToken"); err != nil || playlistSizeExceeded(songArray) { morePages = false } } + if (dj.conf.General.MaxSongPerPlaylist > 0 && len(songArray) > dj.conf.General.MaxSongPerPlaylist){ + songArray = songArray[:dj.conf.General.MaxSongPerPlaylist] + } return songArray, nil } + +// checks if the number of songs of the playlist exceeds the configured playlist maximum size +func playlistSizeExceeded(songs []Song) bool{ + return dj.conf.General.MaxSongPerPlaylist > 0 && len(songs) > dj.conf.General.MaxSongPerPlaylist +}