Exemplo n.º 1
0
        public override void Execute(DiscordSocketClient client, string[] args, Message message)
        {
            if (!Program.Sessions.ContainsKey(message.Guild))
            {
                message.Channel.SendMessage("Not connected to a voice channel. Use the join command to play music.");
            }
            else
            {
                if (args.Length > 0)
                {
                    if (args[0].IndexOf("?v=") > -1)
                    {
                        string videoId = args[0].Substring(args[0].IndexOf("?v=") + 3, 11);

                        string basePath = $"Cache/{videoId}";
                        string path     = basePath + ".webm";

                        string videoName = null;

                        if (!File.Exists(path))
                        {
                            try
                            {
                                var result = new YouTubeGrabber().GrabAsync(new Uri(args[0])).Result;

                                foreach (var resource in result.Resources)
                                {
                                    if (resource.ResourceUri.Host.Contains("googlevideo.com") && resource.ResourceUri.Query.Contains("mime=audio"))
                                    {
                                        File.WriteAllBytes(path, new HttpClient().GetAsync(resource.ResourceUri.ToString()).Result.Content.ReadAsByteArrayAsync().Result);
                                        File.WriteAllText(basePath + ".txt", result.Title);

                                        videoName = result.Title;

                                        break;
                                    }
                                }
                            }
                            catch
                            {
                                return;
                            }
                        }
                        else
                        {
                            videoName = File.ReadAllText(basePath + ".txt");
                        }

                        message.Channel.SendMessage($"Added \"{videoName}\" to queue.");

                        Program.Sessions[message.Guild].Queue.Enqueue(new Track(videoName, args[0], path));
                    }
                    else
                    {
                        message.Channel.SendMessage($"That appears to not be a valid YouTube video url, <@{message.Author.User.Id}>");
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async void Test_YouTube_Decipher()
        {
            var grabber = new YouTubeGrabber();
            var result  = await grabber.GrabAsync(new Uri("https://www.youtube.com/watch?v=ZR02k-h0lX0"));

            Assert.True(result.IsSecure);
            Assert.Equal(33, result.Resources.Count);
        }
Exemplo n.º 3
0
        public async void Test_YouTube_Normal()
        {
            var grabber = new YouTubeGrabber();
            var result  = await grabber.GrabAsync(new Uri("https://www.youtube.com/watch?v=ThUS9fj-mCA"));

            Assert.False(result.IsSecure);
            Assert.Equal(23, result.Resources.Count);
        }
Exemplo n.º 4
0
 public async void Test_YouTube()
 {
     var grabber = new YouTubeGrabber();
     // var result = await grabber.GrabAsync(new Uri("https://www.youtube.com/watch?v=-BjZmE2gtdo"));
     var result = await grabber.GrabAsync(new Uri("https://www.youtube.com/watch?v=Fpgd3ac3_nM"));
 }