コード例 #1
0
            public void Execute(User executor, List <string> arguments)
            {
                if (arguments.Count <= 0)
                {
                    return;
                }

                var url = arguments[0];

                var regex = new Regex(@"^(https?:\/\/)?(www.)?soundcloud\.com\/[\w\-\.]+(\/)+[\w\-\.]+/?$");

                if (regex.Match(url).Success)
                {
                    try
                    {
                        using (var web = new WebClient())
                        {
                            var info = web.DownloadString(
                                "http://api.soundcloud.com/resolve.json?url=" + url + "&client_id=" + clientID
                                + "&app_version=" + AppID);
                            var b = JsonConvert.DeserializeObject <Track>(info);
                            if (b.streamable && b.kind == "track")
                            {
                                var durl = web.DownloadString(
                                    "https://api.soundcloud.com/tracks/" + b.id + "/streams?client_id=" + clientID
                                    + "&app_version=" + AppID);
                                var urls = JsonConvert.DeserializeObject <DownloadURL>(durl);
                                if (urls.http_mp3_128_url != null)
                                {
                                    if (!Instance.IsMuted)
                                    {
                                        ConsoleSender.SendCommand(
                                            $"{b.title} was added to the queue",
                                            ConsoleSender.Command.Chat);
                                    }

                                    Instance.BackGroundQueue.PlayList.Enqueue(
                                        new Instance.Song(
                                            b.title,
                                            new Mp3MediafoundationDecoder(urls.http_mp3_128_url).ToMono(),
                                            executor));

                                    return;
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        return;
                    }
                }

                var youtube    = new Regex(@"youtube\..+?/watch.*?v=(.*?)(?:&|/|$)");
                var shortregex = new Regex(@"youtu\.be/(.*?)(?:\?|&|/|$)");

                if (youtube.Match(url).Success || shortregex.Match(url).Success)
                {
                    var id            = YoutubeClient.ParseVideoId(url);
                    var client        = new YoutubeClient();
                    var streamInfoSet = client.GetVideoMediaStreamInfosAsync(id);
                    var streamInfo    =
                        streamInfoSet.Result.Audio.FirstOrDefault(n => n.AudioEncoding == AudioEncoding.Aac);
                    if (streamInfo == null)
                    {
                        return;
                    }

                    var ext   = streamInfo.Url;
                    var title = client.GetVideoAsync(id).Result.Title;
                    if (!Instance.IsMuted)
                    {
                        ConsoleSender.SendCommand($"{title} was added to the queue", ConsoleSender.Command.Chat);
                    }

                    Instance.BackGroundQueue.PlayList.Enqueue(new Instance.Song(title, new AacDecoder(ext).ToMono(), executor));
                }
                else
                {
                    if (arguments.Count >= 1)
                    {
                        var text   = arguments.Aggregate(" ", (current, argument) => current + " " + argument);
                        var client = new YoutubeClient();
                        var vids   = client.SearchVideosAsync(text, 1).Result;
                        if (vids.Count > 0)
                        {
                            var streamInfoSet = client.GetVideoMediaStreamInfosAsync(vids[0].Id);
                            var streamInfo    =
                                streamInfoSet.Result.Audio.FirstOrDefault(n => n.AudioEncoding == AudioEncoding.Aac);
                            if (streamInfo == null)
                            {
                                return;
                            }

                            var ext   = streamInfo.Url;
                            var title = client.GetVideoAsync(vids[0].Id).Result.Title;
                            if (!Instance.IsMuted)
                            {
                                ConsoleSender.SendCommand($"{title} was added to the queue",
                                                          ConsoleSender.Command.Chat);
                            }

                            Instance.BackGroundQueue.PlayList.Enqueue(new Instance.Song(title, new AacDecoder(ext).ToMono(),
                                                                                        executor));
                        }
                    }
                }
            }
コード例 #2
0
ファイル: AboutCommand.cs プロジェクト: cymug/RequestifyTF2
 public void Execute(User executor, List <string> arguments)
 {
     ConsoleSender.SendCommand("RequestifyTF2 by cymug/DllMain/nullptr/Weespin", ConsoleSender.Command.Chat);
     ConsoleSender.SendCommand("Download at: github.com/cymug/RequestifyTF2", ConsoleSender.Command.Chat);
 }
コード例 #3
0
            public void Execute(User executor, List <string> arguments)
            {
                if (arguments.Count <= 0)
                {
                    return;
                }

                var url = arguments[0];

                var soundcloudregex = new Regex(@"^(https?:\/\/)?(www.)?soundcloud\.com\/[\w\-\.]+(\/)+[\w\-\.]+/?$");

                if (soundcloudregex.Match(url).Success)
                {
                    try
                    {
                        using (var web = new WebClient())
                        {
                            var info = web.DownloadString(
                                "http://api.soundcloud.com/resolve.json?url=" + url + "&client_id=" + clientID
                                + "&app_version=" + AppID);
                            var b = JsonConvert.DeserializeObject <Track>(info);
                            if (b.streamable && b.kind == "track")
                            {
                                var durl = web.DownloadString(
                                    "https://api.soundcloud.com/tracks/" + b.id + "/streams?client_id=" + clientID
                                    + "&app_version=" + AppID);
                                var urls = JsonConvert.DeserializeObject <DownloadURL>(durl);
                                if (urls.http_mp3_128_url != null)
                                {
                                    Instance.BackgroundEnqueue(Instance.SongType.MP3, urls.http_mp3_128_url,
                                                               executor.Name, b.title);


                                    return;
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        return;
                    }
                }

                var youtube    = new Regex(@"youtube\..+?/watch.*?v=(.*?)(?:&|/|$)");
                var shortregex = new Regex(@"youtu\.be/(.*?)(?:\?|&|/|$)");

                if (youtube.Match(url).Success || shortregex.Match(url).Success)
                {
                    var id            = YoutubeClient.ParseVideoId(url);
                    var client        = new YoutubeClient();
                    var streamInfoSet = client.GetVideoMediaStreamInfosAsync(id);
                    var streamInfo    =
                        streamInfoSet.Result;
                    if (streamInfo == null)
                    {
                        return;
                    }

                    var ext = "";
                    foreach (var ad in streamInfo.Audio)
                    {
                        if (Enum.GetName(typeof(AudioEncoding), ad.AudioEncoding) == "Aac") //Msbuild f**k upped this moment. I cant compare different enums. MSBUILD 16 VS19 RC3
                        {
                            ext = ad.Url;
                            break;
                        }
                    }
                    if (ext == string.Empty)
                    {
                        return;
                    }
                    var title = client.GetVideoAsync(id).Result.Title;
                    ConsoleSender.SendCommand($"{title} was added to the queue", ConsoleSender.Command.Chat);

                    Instance.BackgroundEnqueue(Instance.SongType.AAC, ext,
                                               executor.Name, title);
                }
                else
                {
                    var text   = arguments.Aggregate(" ", (current, argument) => current + " " + argument);
                    var client = new YoutubeClient();
                    var vids   = client.SearchVideosAsync(text, 1).Result;
                    if (vids.Count > 0)
                    {
                        for (int i = 0; i < vids.Count; i++)
                        {
                            var streamInfoSet = client.GetVideoMediaStreamInfosAsync(vids[i].Id).ConfigureAwait(false).GetAwaiter().GetResult();
                            var ext           = "";

                            foreach (var ad in streamInfoSet.Audio)
                            {
                                if (Enum.GetName(typeof(AudioEncoding), ad.AudioEncoding) == "Aac") //Msbuild f**k upped this moment. I cant compare different enums. MSBUILD 16 VS19 RC3
                                {
                                    ext = ad.Url;
                                    break;
                                }
                            }
                            if (ext == string.Empty)
                            {
                                continue;
                            }


                            var title = client.GetVideoAsync(vids[i].Id).Result.Title;


                            Instance.BackgroundEnqueue(Instance.SongType.AAC, ext,
                                                       executor.Name, title);
                            break;
                        }
                    }
                }
            }
コード例 #4
0
        private static void Play()
        {
            while (true)
            {
                // Background stuff (music)
                if (Instance.SoundOutBackground.PlaybackState == PlaybackState.Playing)
                {
                    Instance.SoundOutBackground.Volume =
                        Instance.SoundOutForeground.PlaybackState == PlaybackState.Playing ? ((float)Instance.Config.BaseVolume * 0.005f) : ((float)Instance.Config.BaseVolume * 0.01f);
                    if (Instance.SoundOutBackground.WaveSource != null)
                    {
                        if (Instance.SoundOutBackground.WaveSource.Length
                            - Instance.SoundOutBackground.WaveSource.Position
                            < Instance.SoundOutBackground.WaveSource.WaveFormat.BytesPerSecond / 100)
                        {
                            Instance.SoundOutBackground.Stop();
                            Logger.Write(Logger.Status.Info, "Stopped at Position: " + Instance.SoundOutBackground.WaveSource.Position.ToString() + " Length: " + Instance.SoundOutBackground.WaveSource.Length.ToString());
                        }
                    }
                }

                if (Instance.BackGroundQueue.GetQueueLenght() > 0)
                {
                    if (Instance.SoundOutBackground.PlaybackState == PlaybackState.Stopped && Instance.NewSongLock == false)
                    {
                        Instance.Song s;
                        if (Instance.BackGroundQueue.PlayList.TryDequeue(out s))
                        {
                            Task.Run(
                                () =>
                            {
                                Thread.Sleep(1600);
                                ConsoleSender.SendCommand(
                                    string.Format(Localization.Localization.CORE_PLAYING_TITLE_FROM, s.Title, s.RequestedBy.Name),
                                    ConsoleSender.Command.Chat);
                                Logger.Write(Logger.Status.Info, string.Format(Localization.Localization.CORE_PLAYING_TITLE_FROM, s.Title, s.RequestedBy.Name));
                                Player(s.Source, Instance.SoundOutBackground);
                                Instance.NewSongLock     = true;
                                Instance.CurrentTitle    = s.Title;
                                Instance.CurrentSongFrom = s.RequestedBy.Name;
                                Logger.Write(Logger.Status.Info, "Started at Position: " + Instance.SoundOutBackground.WaveSource.Position.ToString() + " Length: " + Instance.SoundOutBackground.WaveSource.Length.ToString());
                            });
                        }
                    }
                }

                // Check to make sure sound output has actually started (prevent queue skipping)
                if (Instance.SoundOutBackground.PlaybackState == PlaybackState.Playing && Instance.NewSongLock == true)
                {
                    Instance.NewSongLock = false;
                }

                // Foreground stuff (tts)
                if (Instance.SoundOutForeground.PlaybackState == PlaybackState.Playing)
                {
                    if (Instance.SoundOutForeground.WaveSource != null)
                    {
                        if (Instance.SoundOutForeground.WaveSource.Length
                            - Instance.SoundOutForeground.WaveSource.Position
                            < Instance.SoundOutForeground.WaveSource.WaveFormat.BytesPerSecond / 1000)
                        {
                            Instance.SoundOutForeground.Stop();
                        }
                    }
                }

                if (Instance.QueueForeGround.Count > 0)
                {
                    if (Instance.SoundOutForeground.PlaybackState == PlaybackState.Stopped)
                    {
                        IWaveSource s;
                        if (Instance.QueueForeGround.TryDequeue(out s))
                        {
                            Task.Run(() => { Player(s, Instance.SoundOutForeground); });
                        }
                    }
                }

                Thread.Sleep(60);
            }
        }
コード例 #5
0
ファイル: Requestify.cs プロジェクト: cymug/RequestifyTF2
            public void Execute(User executor, List <string> arguments)
            {
                if (arguments.Count <= 0)
                {
                    ConsoleSender.SendCommand("Usage: !request [song name or url]", ConsoleSender.Command.Chat);
                    return;
                }

                var url = arguments[0];

                var soundcloudregex = new Regex(@"^(https?:\/\/)?(www.)?soundcloud\.com\/[\w\-\.]+(\/)+[\w\-\.]+/?$");

                if (soundcloudregex.Match(url).Success)
                {
                    try
                    {
                        using (var web = new WebClient())
                        {
                            var info = web.DownloadString(
                                "http://api.soundcloud.com/resolve.json?url=" + url + "&client_id=" + clientID
                                + "&app_version=" + AppID);
                            var b = JsonConvert.DeserializeObject <Track>(info);
                            if (b.streamable && b.kind == "track")
                            {
                                var durl = web.DownloadString(
                                    "https://api.soundcloud.com/tracks/" + b.id + "/streams?client_id=" + clientID
                                    + "&app_version=" + AppID);
                                var urls = JsonConvert.DeserializeObject <DownloadURL>(durl);
                                if (urls.http_mp3_128_url != null)
                                {
                                    Instance.BackgroundEnqueue(Instance.SongType.MP3, urls.http_mp3_128_url,
                                                               executor.Name, b.title);


                                    return;
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        return;
                    }
                }

                var youtube    = new Regex(@"youtube\..+?/watch.*?v=(.*?)(?:&|/|$)");
                var shortregex = new Regex(@"youtu\.be/(.*?)(?:\?|&|/|$)");

                if (youtube.Match(url).Success || shortregex.Match(url).Success)
                {
                    var client         = new YoutubeClient();
                    var video          = client.Videos.GetAsync(url).Result;
                    var streamManifest = client.Videos.Streams.GetManifestAsync(video.Id).Result;
                    if (streamManifest.Streams.Count == 0)
                    {
                        return;
                    }

                    var streamInfo = streamManifest.GetAudioOnly().Where(n => n.AudioCodec.Contains("mp4"))
                                     .FirstOrDefault();

                    if (streamInfo == null)
                    {
                        return;
                    }

                    var ext = streamInfo.Url;
                    if (ext == string.Empty)
                    {
                        return;
                    }

                    var title = video.Title;
                    ConsoleSender.SendCommand($"{title} was added to the queue", ConsoleSender.Command.Chat);

                    Instance.BackgroundEnqueue(Instance.SongType.AAC, ext,
                                               executor.Name, title);
                }
                else
                {
                    var text   = arguments.Aggregate(" ", (current, argument) => current + " " + argument);
                    var client = new YoutubeClient();
                    var vids   = client.Search.GetVideosAsync(text).BufferAsync(5).Result;

                    if (vids.Count > 0)
                    {
                        for (int i = 0; i < vids.Count; i++)
                        {
                            var streamManifest = client.Videos.Streams.GetManifestAsync(vids[i].Id).Result;
                            if (streamManifest.Streams.Count == 0)
                            {
                                return;
                            }

                            var streamInfo = streamManifest.GetAudioOnly().Where(n => n.AudioCodec.Contains("mp4"))
                                             .FirstOrDefault();

                            if (streamInfo == null)
                            {
                                return;
                            }

                            var ext = streamInfo.Url;
                            if (ext == string.Empty)
                            {
                                return;
                            }

                            var title = client.Videos.GetAsync(vids[i].Id).Result.Title;
                            Instance.BackgroundEnqueue(Instance.SongType.AAC, ext,
                                                       executor.Name, title);
                            break;
                        }
                    }
                }
            }