示例#1
0
        public static YouTubeVideo Search(string search)
        {
            YouTubeVideo video          = new YouTubeVideo();
            var          youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = ConfigUtils.Configuration.YoutubeApiKey,
                ApplicationName = "DankBot"
            });
            var searchListRequest = youtubeService.Search.List("snippet");

            searchListRequest.Q          = search; // Replace with your search term.
            searchListRequest.MaxResults = 10;
            var searchListResponse = searchListRequest.Execute();

            foreach (SearchResult r in searchListResponse.Items)
            {
                if (r.Id.Kind == "youtube#video")
                {
                    video.Title = r.Snippet.Title;
                    video.Url   = $"https://www.youtube.com/watch?v={r.Id.VideoId}";
                    return(video);
                }
            }
            throw new Exception("No results");
        }
示例#2
0
 public static async Task Comment(SocketMessage message, string[] arg, string msg)
 {
     if (arg.Count() > 1)
     {
         try
         {
             YouTubeVideo video = YouTubeHelper.Search(msg.Substring(8));
             CommentThreadListResponse comments = YouTubeHelper.GetComments(video.Url.Substring(32));
             if (comments == null)
             {
                 await message.Channel.SendMessageAsync($":no_entry: `Could not list comments for this video`");
             }
             else
             {
                 await message.Channel.SendMessageAsync("", false, genYtComment(comments.Items.ElementAt(new Random().Next(comments.Items.Count)).Snippet.TopLevelComment.Snippet));
             }
         }
         catch
         {
             await message.Channel.SendMessageAsync($":no_entry: `That video doesn't exist n***a`:joy:");
         }
     }
     else
     {
         await message.Channel.SendMessageAsync($":no_entry: `Please include a video link`");
     }
 }
示例#3
0
        public static void Add(YouTubeVideo video)
        {
            string       videoid = video.Url.Substring(video.Url.LastIndexOf("v=") + 2, 11);
            PlayListItem item    = new PlayListItem();

            item.Title = video.Title;
            item.Url   = video.Url;
            Playlist.files.Add(item);
        }
        public static async Task Play(SocketMessage message, string[] arg, string msg)
        {
            string        url     = msg.Substring(5);
            IAudioChannel channel = null;

            channel = channel ?? (message.Author as IGuildUser)?.VoiceChannel;
            try
            {
                if (!Playlist.Enabled)
                {
                    Playlist.CurrentChannel = channel;
                    if (channel != null)
                    {
                        new Thread(() => {
                            Playlist.JoinChannel(channel).Wait();
                        }).Start();
                        Playlist.Enable();
                    }
                    else
                    {
                        await message.Channel.SendMessageAsync($":no_entry: `Sorry, u aren't in a f*****g audio channel m8`");

                        return;
                    }
                }
                if (Playlist.CurrentChannel == channel)
                {
                    YouTubeVideo video = YouTubeHelper.Search(url);
                    foreach (PlayListItem item in Playlist.files)
                    {
                        if (item.Url == video.Url)
                        {
                            await message.Channel.SendMessageAsync($":no_entry: `Sorry, this video is already in the playlist !`");

                            return;
                        }
                    }
                    string tUpper = video.Title.ToUpper();
                    Playlist.Add(video);
                    await message.Channel.SendMessageAsync($":white_check_mark: `'{video.Title}' has been added to the playlist !`");
                }
                else
                {
                    await message.Channel.SendMessageAsync($":no_entry: `Sorry, you are't in the same audio channel as the bot !`");
                }
            }
            catch
            {
                await message.Channel.SendMessageAsync($":no_entry: `That video doesn't exist n***a`:joy:");
            }
        }