Esempio n. 1
0
        private async void ResolveStreamLink()
        {
            string uri = null;

            try {
                if (RadioLink)
                {
                    uri      = Query;
                    Title    = $"{Query}";
                    Provider = "Radio Stream";
                }
                else
                {
                    if (OnResolving != null)
                    {
                        OnResolving();
                    }
                    var links = await DiscordBot.Modules.Searches.FindYoutubeUrlByKeywords(Query);

                    var videos = await YouTube.Default.GetAllVideosAsync(links);

                    var video = videos
                                .Where(v => v.AdaptiveKind == AdaptiveKind.Audio)
                                .OrderByDescending(v => v.AudioBitrate)
                                .FirstOrDefault();

                    if (video == null) // do something with this error
                    {
                        throw new Exception("Could not load any video elements based on the query.");
                    }

                    Title    = video.Title.Substring(0, video.Title.Length - 10); // removing trailing "- You Tube"
                    Provider = "YouTube";
                    uri      = video.Uri;
                }
            } catch (Exception ex) {
                privateState = StreamState.Completed;
                if (OnResolvingFailed != null)
                {
                    OnResolvingFailed(ex.Message);
                }
                Console.WriteLine($"Failed resolving the link.{ex.Message}");
                return;
            }

            musicStreamer = new MusicStreamer(this, uri);
            if (OnQueued != null)
            {
                OnQueued();
            }
        }
Esempio n. 2
0
        private async void ResolveStreamLink() {
            string uri = null;
            try {
                if (RadioLink) {
                    uri = Query;
                    Title = $"Radio Stream - <{Query}>";
                }
                else if (SoundCloud.Default.IsSoundCloudLink(Query)) {
                    if (OnResolving != null)
                        OnResolving();
                    var svideo = await SoundCloud.Default.GetVideoAsync(Query);
                    Title = svideo.FullName + " - SoundCloud";
                    uri = svideo.StreamLink;
                    Console.WriteLine(uri);
                } else {

                    if (OnResolving != null)
                        OnResolving();
                    var links = await Searches.FindYoutubeUrlByKeywords(Query);
                    var videos = await YouTube.Default.GetAllVideosAsync(links);
                    var video = videos
                                .Where(v => v.AdaptiveKind == AdaptiveKind.Audio)
                                .OrderByDescending(v => v.AudioBitrate)
                                .FirstOrDefault();

                    if (video == null) // do something with this error
                        throw new Exception("Could not load any video elements based on the query.");

                    Title = video.Title; //.Substring(0,video.Title.Length-10); // removing trailing "- You Tube"
                    uri = video.Uri;
                }
            } catch (Exception ex) {
                privateState = StreamState.Completed;
                if (OnResolvingFailed != null)
                    OnResolvingFailed(ex.Message);
                Console.WriteLine($"Failed resolving the link.{ex.Message}");
                return;
            }

            musicStreamer = new MusicStreamer(this, uri);
            if (OnQueued != null)
                OnQueued();
        }
Esempio n. 3
0
        public async Task Resolve()
        {
            string uri = null;

            try {
                if (RadioLink)
                {
                    uri      = Query;
                    Title    = $"{Query}";
                    Provider = "Radio Stream";
                }
                else if (SoundCloud.Default.IsSoundCloudLink(Query))
                {
                    if (OnResolving != null)
                    {
                        OnResolving();
                    }
                    var svideo = await SoundCloud.Default.GetVideoAsync(Query);

                    Title    = svideo.FullName;
                    Provider = "SoundCloud";
                    uri      = svideo.StreamLink;
                    Console.WriteLine(uri);
                }
                else
                {
                    if (OnResolving != null)
                    {
                        OnResolving();
                    }
                    var links = await SearchHelper.FindYoutubeUrlByKeywords(Query);

                    var allVideos = await Task.Factory.StartNew(async() => await YouTube.Default.GetAllVideosAsync(links)).Unwrap();

                    var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio);
                    var video  = videos
                                 .Where(v => v.AudioBitrate < 192)
                                 .OrderByDescending(v => v.AudioBitrate)
                                 .FirstOrDefault();

                    if (video == null) // do something with this error
                    {
                        throw new Exception("Could not load any video elements based on the query.");
                    }

                    Title    = video.Title.Substring(0, video.Title.Length - 10); // removing trailing "- You Tube"
                    Provider = "YouTube";
                    uri      = video.Uri;
                }
            }
            catch (Exception ex) {
                privateState = StreamState.Completed;
                if (OnResolvingFailed != null)
                {
                    OnResolvingFailed(ex.Message);
                }
                Console.WriteLine($"Failed resolving the link.{ex.Message}");
                return;
            }

            musicStreamer = new MusicStreamer(this, uri);
            if (OnQueued != null)
            {
                OnQueued();
            }
        }