Playlist queue limit has been raised to 500. Closes #286
This commit is contained in:
parent
bb19551768
commit
28af70a823
@ -197,24 +197,37 @@ namespace NadekoBot.Classes
|
|||||||
return data.items.Length > 0 ? data.items[0].id.playlistId.ToString() : null;
|
return data.items.Length > 0 ? data.items[0].id.playlistId.ToString() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<IEnumerable<string>> GetVideoIDs(string playlist, int number = 50)
|
public static async Task<IList<string>> GetVideoIDs(string playlist, int number = 50)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(NadekoBot.Creds.GoogleAPIKey))
|
if (string.IsNullOrWhiteSpace(NadekoBot.Creds.GoogleAPIKey))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(playlist));
|
throw new ArgumentNullException(nameof(playlist));
|
||||||
}
|
}
|
||||||
if (number < 1 || number > 100)
|
if (number < 1)
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
|
|
||||||
|
string nextPageToken = null;
|
||||||
|
|
||||||
|
List<string> toReturn = new List<string>();
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
var toGet = number > 50 ? 50 : number;
|
||||||
|
number -= toGet;
|
||||||
var link =
|
var link =
|
||||||
$"https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails" +
|
$"https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails" +
|
||||||
$"&maxResults={number}" +
|
$"&maxResults={toGet}" +
|
||||||
$"&playlistId={playlist}" +
|
$"&playlistId={playlist}" +
|
||||||
$"&key={NadekoBot.Creds.GoogleAPIKey}";
|
$"&key={NadekoBot.Creds.GoogleAPIKey}";
|
||||||
|
if (!string.IsNullOrWhiteSpace(nextPageToken))
|
||||||
|
link += $"&pageToken={nextPageToken}";
|
||||||
var response = await GetResponseStringAsync(link).ConfigureAwait(false);
|
var response = await GetResponseStringAsync(link).ConfigureAwait(false);
|
||||||
var obj = await Task.Run(() => JObject.Parse(response)).ConfigureAwait(false);
|
var data = await Task.Run(() => JsonConvert.DeserializeObject<PlaylistItemsSearch>(response)).ConfigureAwait(false);
|
||||||
|
nextPageToken = data.nextPageToken;
|
||||||
|
toReturn.AddRange(data.items.Select(i => i.contentDetails.videoId));
|
||||||
|
} while (number > 0 && !string.IsNullOrWhiteSpace(nextPageToken));
|
||||||
|
|
||||||
return obj["items"].Select(item => "http://www.youtube.com/watch?v=" + item["contentDetails"]["videoId"]);
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -282,10 +282,15 @@ namespace NadekoBot.Modules.Music
|
|||||||
await e.Channel.SendMessage("No search results for that query.");
|
await e.Channel.SendMessage("No search results for that query.");
|
||||||
return;
|
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
|
//todo TEMPORARY SOLUTION, USE RESOLVE QUEUE IN THE FUTURE
|
||||||
var idArray = ids as string[] ?? ids.ToArray();
|
var idArray = ids as string[] ?? ids.ToArray();
|
||||||
var count = idArray.Count();
|
var count = idArray.Length;
|
||||||
var msg =
|
var msg =
|
||||||
await e.Channel.SendMessage($"🎵 `Attempting to queue {count} songs".SnPl(count) + "...`").ConfigureAwait(false);
|
await e.Channel.SendMessage($"🎵 `Attempting to queue {count} songs".SnPl(count) + "...`").ConfigureAwait(false);
|
||||||
foreach (var id in idArray)
|
foreach (var id in idArray)
|
||||||
|
@ -46,6 +46,15 @@ namespace NadekoBot.Classes.JSONModels
|
|||||||
public string kind { get; set; }
|
public string kind { get; set; }
|
||||||
public string videoId { 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
|
#region wikpedia example
|
||||||
// {
|
// {
|
||||||
|
Loading…
Reference in New Issue
Block a user