Ejemplo n.º 1
0
        public static async Task <Tuple <string, string> > GetYoutubeVideo(string[] words, IMessageChannel chan, int maxResult = 1)
        {
            if (words.Length == 0)
            {
                await chan.SendMessageAsync(Sentences.youtubeHelp((chan as ITextChannel).GuildId));

                return(null);
            }
            var searchListRequest = Program.p.youtubeService.Search.List("snippet");

            searchListRequest.Q          = Program.addArgs(words);
            searchListRequest.MaxResults = maxResult;
            var searchListResponse = await searchListRequest.ExecuteAsync();

            if (searchListResponse.Items.Count < maxResult)
            {
                await chan.SendMessageAsync(Sentences.youtubeNotFound((chan as ITextChannel).GuildId));

                return(null);
            }
            Google.Apis.YouTube.v3.Data.SearchResult sr = searchListResponse.Items[maxResult - 1];
            if (sr.Id.Kind != "youtube#video")
            {
                return(await GetYoutubeVideo(words, chan, maxResult + 1));
            }
            else
            {
                return(new Tuple <string, string>("https://www.youtube.com/watch?v=" + sr.Id.VideoId, sr.Snippet.Title));
            }
        }