Allow playlists larger than 50 items (#159)
This commit ensures that playlists longer than 50 items return successfully when `max_tracks_per_playlist` is set higher than 50. Previously if this value was raised higher than 50 the addition of a playlist with more than 50 items would hang indefinitely.
This commit is contained in:
parent
57eaf7c3db
commit
c85fddcb4f
|
@ -134,9 +134,15 @@ func (yt *YouTube) GetTracks(url string, submitter *gumble.User) ([]interfaces.T
|
|||
maxItems = viper.GetInt("queue.max_tracks_per_playlist")
|
||||
}
|
||||
|
||||
// YouTube playlist searches return a max of 50 results per page
|
||||
maxResults := 50
|
||||
if maxResults > maxItems {
|
||||
maxResults = maxItems
|
||||
}
|
||||
|
||||
pageToken := ""
|
||||
for len(tracks) < maxItems {
|
||||
curResp, curErr := http.Get(fmt.Sprintf(playlistItemsURL, id, maxItems, viper.GetString("api_keys.youtube"), pageToken))
|
||||
curResp, curErr := http.Get(fmt.Sprintf(playlistItemsURL, id, maxResults, viper.GetString("api_keys.youtube"), pageToken))
|
||||
defer curResp.Body.Close()
|
||||
if curErr != nil {
|
||||
// An error occurred, simply skip this track.
|
||||
|
@ -163,6 +169,11 @@ func (yt *YouTube) GetTracks(url string, submitter *gumble.User) ([]interfaces.T
|
|||
break
|
||||
}
|
||||
}
|
||||
|
||||
pageToken, _ = v.GetString("nextPageToken")
|
||||
if pageToken == "" {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if len(tracks) == 0 {
|
||||
|
|
Reference in a new issue