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();
|
||||||
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);
|
string nextPageToken = null;
|
||||||
var obj = await Task.Run(() => JObject.Parse(response)).ConfigureAwait(false);
|
|
||||||
|
|
||||||
return obj["items"].Select(item => "http://www.youtube.com/watch?v=" + item["contentDetails"]["videoId"]);
|
List<string> toReturn = new List<string>();
|
||||||
|
|
||||||
|
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<PlaylistItemsSearch>(response)).ConfigureAwait(false);
|
||||||
|
nextPageToken = data.nextPageToken;
|
||||||
|
toReturn.AddRange(data.items.Select(i => i.contentDetails.videoId));
|
||||||
|
} while (number > 0 && !string.IsNullOrWhiteSpace(nextPageToken));
|
||||||
|
|
||||||
|
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)
|
||||||
|
@ -81,14 +81,14 @@ namespace NadekoBot.Classes.JSONModels
|
|||||||
"Calling %target%"
|
"Calling %target%"
|
||||||
} },
|
} },
|
||||||
{"%mention% disguise", new List<string>() {
|
{"%mention% disguise", new List<string>() {
|
||||||
"https://cdn.discordapp.com/attachments/140007341880901632/156721710458994690/Cc5mixjUYAADgBs.jpg",
|
"https://cdn.discordapp.com/attachments/140007341880901632/156721710458994690/Cc5mixjUYAADgBs.jpg",
|
||||||
"https://cdn.discordapp.com/attachments/140007341880901632/156721715831898113/hqdefault.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/156721724430352385/okawari_01_haruka_weird_mask.jpg",
|
||||||
"https://cdn.discordapp.com/attachments/140007341880901632/156721728763068417/mustache-best-girl.png"
|
"https://cdn.discordapp.com/attachments/140007341880901632/156721728763068417/mustache-best-girl.png"
|
||||||
|
|
||||||
} }
|
} }
|
||||||
};
|
};
|
||||||
|
|
||||||
public List<string> RotatingStatuses { get; set; } = new List<string>();
|
public List<string> RotatingStatuses { get; set; } = new List<string>();
|
||||||
public CommandPrefixesModel CommandPrefixes { get; set; } = new CommandPrefixesModel();
|
public CommandPrefixesModel CommandPrefixes { get; set; } = new CommandPrefixesModel();
|
||||||
public HashSet<ulong> ServerBlacklist { get; set; } = new HashSet<ulong>();
|
public HashSet<ulong> ServerBlacklist { get; set; } = new HashSet<ulong>();
|
||||||
|
@ -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