public WaveStream AudioFromYT(EditNull n, IMessage m, string YouTubeVideoURL)
        {
            if (m.Author.Id != Program.Master.Id)
            {
                throw new Exception("u r not allowed");
            }

            MemoryStream mem = new MemoryStream();

            using Process P = MultiMediaHelper.GetAudioStreamFromYouTubeVideo(YouTubeVideoURL, "mp3");
            P.StandardOutput.BaseStream.CopyTo(mem);
            return(WaveFormatConversionStream.CreatePcmStream(new StreamMediaFoundationReader(mem)));
        }
Esempio n. 2
0
        public override async void Execute(IMessage message)
        {
            if (!message.Content.Contains(" "))
            {
                DiscordNETWrapper.SendEmbed(HelpMenu, message.Channel).Wait();
                return;
            }

            SocketGuild         g       = Program.GetGuildFromChannel(message.Channel);
            ISocketAudioChannel channel = g.VoiceChannels.FirstOrDefault(x => x.Users.Select(y => y.Id).Contains(message.Author.Id));

            string videoURL = message.Content.Split(' ')[1];

            if (!videoURL.StartsWith("https://www.youtube.com/watch?"))
            {
                DiscordNETWrapper.SendText("That doesn't look like a youtube video link :thinking:", message.Channel).Wait();
                return;
            }

            if (channel != null)
            {
                try { channel.DisconnectAsync().Wait(); } catch { }

                IAudioClient client = await channel.ConnectAsync();

                using (Process P = MultiMediaHelper.GetAudioStreamFromYouTubeVideo(videoURL, "mp3"))
                    using (MemoryStream mem = new MemoryStream())
                    {
                        while (true)
                        {
                            Task.Delay(1001).Wait();
                            if (string.IsNullOrWhiteSpace(P.StandardError.ReadLine()))
                            {
                                break;
                            }
                        }
                        P.StandardOutput.BaseStream.CopyTo(mem);
                        using (WaveStream naudioStream = WaveFormatConversionStream.CreatePcmStream(new StreamMediaFoundationReader(mem)))
                            MultiMediaHelper.SendAudioAsync(client, naudioStream).Wait();
                    }

                try { channel.DisconnectAsync().Wait(); } catch { }
            }
            else
            {
                DiscordNETWrapper.SendText("You are not in an AudioChannel on this server!", message.Channel).Wait();
                return;
            }
        }