Better youtube searches (no errors)

This commit is contained in:
Master Kwoth
2016-05-03 05:57:15 +02:00
parent 5e4d1ebcf5
commit 081cb44dac
5 changed files with 107 additions and 9 deletions

View File

@ -249,7 +249,7 @@ namespace NadekoBot.Modules.Music.Classes
});
}
var link = await SearchHelper.FindYoutubeUrlByKeywords(query).ConfigureAwait(false);
if (link == String.Empty)
if (string.IsNullOrWhiteSpace(link))
throw new OperationCanceledException("Not a valid youtube query.");
var allVideos = await Task.Factory.StartNew(async () => await YouTube.Default.GetAllVideosAsync(link).ConfigureAwait(false)).Unwrap().ConfigureAwait(false);
var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio);

View File

@ -276,7 +276,13 @@ namespace NadekoBot.Modules.Music
await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false);
return;
}
var ids = await SearchHelper.GetVideoIDs(await SearchHelper.GetPlaylistIdByKeyword(arg).ConfigureAwait(false), 50).ConfigureAwait(false);
var plId = await SearchHelper.GetPlaylistIdByKeyword(arg).ConfigureAwait(false);
if (plId == null)
{
await e.Channel.SendMessage("No search results for that query.");
return;
}
var ids = await SearchHelper.GetVideoIDs(plId, 50).ConfigureAwait(false);
//todo TEMPORARY SOLUTION, USE RESOLVE QUEUE IN THE FUTURE
var idArray = ids as string[] ?? ids.ToArray();
var count = idArray.Count();

View File

@ -67,8 +67,13 @@ $@"🌍 **Weather for** 【{obj["target"]}】
.Do(async e =>
{
if (!(await SearchHelper.ValidateQuery(e.Channel, e.GetArg("query")).ConfigureAwait(false))) return;
var shortUrl = await SearchHelper.ShortenUrl(await SearchHelper.FindYoutubeUrlByKeywords(e.GetArg("query")).ConfigureAwait(false)).ConfigureAwait(false);
var link = await SearchHelper.FindYoutubeUrlByKeywords(e.GetArg("query")).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(link))
{
await e.Channel.SendMessage("No results found for that query.");
return;
}
var shortUrl = await SearchHelper.ShortenUrl(link).ConfigureAwait(false);
await e.Channel.SendMessage(shortUrl).ConfigureAwait(false);
});