diff --git a/NadekoBot/Classes/SearchHelper.cs b/NadekoBot/Classes/SearchHelper.cs index ed233841..60bf22ba 100644 --- a/NadekoBot/Classes/SearchHelper.cs +++ b/NadekoBot/Classes/SearchHelper.cs @@ -197,24 +197,37 @@ namespace NadekoBot.Classes return data.items.Length > 0 ? data.items[0].id.playlistId.ToString() : null; } - public static async Task> GetVideoIDs(string playlist, int number = 50) + public static async Task> GetVideoIDs(string playlist, int number = 50) { if (string.IsNullOrWhiteSpace(NadekoBot.Creds.GoogleAPIKey)) { throw new ArgumentNullException(nameof(playlist)); } - if (number < 1 || number > 100) + if (number < 1) throw new ArgumentOutOfRangeException(); - var link = - $"https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails" + - $"&maxResults={number}" + - $"&playlistId={playlist}" + - $"&key={NadekoBot.Creds.GoogleAPIKey}"; - var response = await GetResponseStringAsync(link).ConfigureAwait(false); - var obj = await Task.Run(() => JObject.Parse(response)).ConfigureAwait(false); + string nextPageToken = null; - return obj["items"].Select(item => "http://www.youtube.com/watch?v=" + item["contentDetails"]["videoId"]); + List toReturn = new List(); + + do + { + var toGet = number > 50 ? 50 : number; + number -= toGet; + var link = + $"https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails" + + $"&maxResults={toGet}" + + $"&playlistId={playlist}" + + $"&key={NadekoBot.Creds.GoogleAPIKey}"; + if (!string.IsNullOrWhiteSpace(nextPageToken)) + link += $"&pageToken={nextPageToken}"; + var response = await GetResponseStringAsync(link).ConfigureAwait(false); + var data = await Task.Run(() => JsonConvert.DeserializeObject(response)).ConfigureAwait(false); + nextPageToken = data.nextPageToken; + toReturn.AddRange(data.items.Select(i => i.contentDetails.videoId)); + } while (number > 0 && !string.IsNullOrWhiteSpace(nextPageToken)); + + return toReturn; } diff --git a/NadekoBot/Modules/Music/MusicModule.cs b/NadekoBot/Modules/Music/MusicModule.cs index d69f63b5..cecf4555 100644 --- a/NadekoBot/Modules/Music/MusicModule.cs +++ b/NadekoBot/Modules/Music/MusicModule.cs @@ -282,10 +282,15 @@ namespace NadekoBot.Modules.Music await e.Channel.SendMessage("No search results for that query."); return; } - var ids = await SearchHelper.GetVideoIDs(plId, 50).ConfigureAwait(false); + var ids = await SearchHelper.GetVideoIDs(plId, 500).ConfigureAwait(false); + if (ids == null || ids.Count == 0) + { + await e.Channel.SendMessage($"🎵`Failed to find any songs.`"); + return; + } //todo TEMPORARY SOLUTION, USE RESOLVE QUEUE IN THE FUTURE var idArray = ids as string[] ?? ids.ToArray(); - var count = idArray.Count(); + var count = idArray.Length; var msg = await e.Channel.SendMessage($"🎵 `Attempting to queue {count} songs".SnPl(count) + "...`").ConfigureAwait(false); foreach (var id in idArray) diff --git a/NadekoBot/_Models/JSONModels/Configuration.cs b/NadekoBot/_Models/JSONModels/Configuration.cs index e03286d5..2eaea57f 100644 --- a/NadekoBot/_Models/JSONModels/Configuration.cs +++ b/NadekoBot/_Models/JSONModels/Configuration.cs @@ -81,14 +81,14 @@ namespace NadekoBot.Classes.JSONModels "Calling %target%" } }, {"%mention% disguise", new List() { - "https://cdn.discordapp.com/attachments/140007341880901632/156721710458994690/Cc5mixjUYAADgBs.jpg", - "https://cdn.discordapp.com/attachments/140007341880901632/156721715831898113/hqdefault.jpg", - "https://cdn.discordapp.com/attachments/140007341880901632/156721724430352385/okawari_01_haruka_weird_mask.jpg", - "https://cdn.discordapp.com/attachments/140007341880901632/156721728763068417/mustache-best-girl.png" + "https://cdn.discordapp.com/attachments/140007341880901632/156721710458994690/Cc5mixjUYAADgBs.jpg", + "https://cdn.discordapp.com/attachments/140007341880901632/156721715831898113/hqdefault.jpg", + "https://cdn.discordapp.com/attachments/140007341880901632/156721724430352385/okawari_01_haruka_weird_mask.jpg", + "https://cdn.discordapp.com/attachments/140007341880901632/156721728763068417/mustache-best-girl.png" } } }; - + public List RotatingStatuses { get; set; } = new List(); public CommandPrefixesModel CommandPrefixes { get; set; } = new CommandPrefixesModel(); public HashSet ServerBlacklist { get; set; } = new HashSet(); diff --git a/NadekoBot/_Models/JSONModels/_JSONModels.cs b/NadekoBot/_Models/JSONModels/_JSONModels.cs index 7ac158ca..c47346cd 100644 --- a/NadekoBot/_Models/JSONModels/_JSONModels.cs +++ b/NadekoBot/_Models/JSONModels/_JSONModels.cs @@ -46,6 +46,15 @@ namespace NadekoBot.Classes.JSONModels public string kind { get; set; } public string videoId { get; set; } } + public class PlaylistItemsSearch + { + public string nextPageToken { get; set; } + public PlaylistItem[] items { get; set; } + } + public class PlaylistItem + { + public YtVideoId contentDetails { get; set; } + } #region wikpedia example // {