fix #470 , !!ap now takes a random video out of 4 related ones
This commit is contained in:
parent
93af77778e
commit
31b2558523
@ -175,7 +175,7 @@ namespace NadekoBot.Classes
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<string> GetRelatedVideoId(string id)
|
public static async Task<IEnumerable<string>> GetRelatedVideoIds(string id, int count = 1)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(id))
|
if (string.IsNullOrWhiteSpace(id))
|
||||||
throw new ArgumentNullException(nameof(id));
|
throw new ArgumentNullException(nameof(id));
|
||||||
@ -186,20 +186,14 @@ namespace NadekoBot.Classes
|
|||||||
}
|
}
|
||||||
var response = await GetResponseStringAsync(
|
var response = await GetResponseStringAsync(
|
||||||
$"https://www.googleapis.com/youtube/v3/search?" +
|
$"https://www.googleapis.com/youtube/v3/search?" +
|
||||||
$"part=snippet&maxResults=1&type=video" +
|
$"part=snippet&maxResults={count}&type=video" +
|
||||||
$"&relatedToVideoId={id}" +
|
$"&relatedToVideoId={id}" +
|
||||||
$"&key={NadekoBot.Creds.GoogleAPIKey}").ConfigureAwait(false);
|
$"&key={NadekoBot.Creds.GoogleAPIKey}").ConfigureAwait(false);
|
||||||
JObject obj = JObject.Parse(response);
|
JObject obj = JObject.Parse(response);
|
||||||
|
|
||||||
var data = JsonConvert.DeserializeObject<YoutubeVideoSearch>(response);
|
var data = JsonConvert.DeserializeObject<YoutubeVideoSearch>(response);
|
||||||
|
|
||||||
if (data.items.Length > 0)
|
return data.items.Select(v => "http://www.youtube.com/watch?v=" + v.id.videoId);
|
||||||
{
|
|
||||||
var toReturn = "http://www.youtube.com/watch?v=" + data.items[0].id.videoId.ToString();
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<string> GetPlaylistIdByKeyword(string query)
|
public static async Task<string> GetPlaylistIdByKeyword(string query)
|
||||||
|
@ -48,8 +48,8 @@ namespace NadekoBot.Classes.Help.Commands
|
|||||||
public Action<CommandEventArgs> DoGitFunc() => e =>
|
public Action<CommandEventArgs> DoGitFunc() => e =>
|
||||||
{
|
{
|
||||||
string helpstr =
|
string helpstr =
|
||||||
$@"######For more information and how to setup your own NadekoBot, go to: **http://github.com/Kwoth/NadekoBot/**
|
$@"######For more information and how to setup your own NadekoBot, go to: <http://github.com/Kwoth/NadekoBot/wiki>
|
||||||
######You can donate on patreon: `https://patreon.com/nadekobot`
|
######You can donate on patreon: <https://patreon.com/nadekobot>
|
||||||
######or paypal: `nadekodiscordbot@gmail.com`
|
######or paypal: `nadekodiscordbot@gmail.com`
|
||||||
|
|
||||||
#NadekoBot List Of Commands
|
#NadekoBot List Of Commands
|
||||||
|
@ -773,11 +773,13 @@ namespace NadekoBot.Modules.Music
|
|||||||
{
|
{
|
||||||
await e.Channel.SendMessage("Could not select song, likely wrong index");
|
await e.Channel.SendMessage("Could not select song, likely wrong index");
|
||||||
|
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
await e.Channel.SendMessage($"🎶`Selected song {selSong.SongInfo.Title}:` <{selSong.SongInfo.Query}>").ConfigureAwait(false);
|
await e.Channel.SendMessage($"🎶`Selected song {selSong.SongInfo.Title}:` <{selSong.SongInfo.Query}>").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
var curSong = musicPlayer.CurrentSong;
|
var curSong = musicPlayer.CurrentSong;
|
||||||
if (curSong == null)
|
if (curSong == null)
|
||||||
@ -837,7 +839,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
lastFinishedMessage = await textCh.SendMessage($"🎵`Finished`{song.PrettyName}").ConfigureAwait(false);
|
lastFinishedMessage = await textCh.SendMessage($"🎵`Finished`{song.PrettyName}").ConfigureAwait(false);
|
||||||
if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.Provider == "YouTube")
|
if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.Provider == "YouTube")
|
||||||
{
|
{
|
||||||
await QueueSong(queuer, textCh, voiceCh, await SearchHelper.GetRelatedVideoId(song.SongInfo.Query), silent, musicType).ConfigureAwait(false);
|
await QueueSong(queuer, textCh, voiceCh, (await SearchHelper.GetRelatedVideoIds(song.SongInfo.Query, 4)).ToList().Shuffle().FirstOrDefault(), silent, musicType).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
Loading…
Reference in New Issue
Block a user