private async Task <StreamContext> GetSteamContextFromVideoInfoAsync(VideoId videoId)
        {
            var embedPage = await EmbedPage.GetAsync(_httpClient, videoId);

            var playerConfig =
                embedPage.TryGetPlayerConfig() ??
                throw VideoUnplayableException.Unplayable(videoId);

            var playerSourceUrl = embedPage.TryGetPlayerSourceUrl() ?? playerConfig.GetPlayerSourceUrl();
            var playerSource    = await PlayerSource.GetAsync(_httpClient, playerSourceUrl);

            var cipherOperations = playerSource.GetCipherOperations().ToArray();

            var videoInfoResponse = await VideoInfoResponse.GetAsync(_httpClient, videoId, playerSource.GetSts());

            var playerResponse = videoInfoResponse.GetPlayerResponse();

            var previewVideoId = playerResponse.TryGetPreviewVideoId();

            if (!string.IsNullOrWhiteSpace(previewVideoId))
            {
                throw VideoRequiresPurchaseException.Preview(videoId, previewVideoId);
            }

            if (!playerResponse.IsVideoPlayable())
            {
                throw VideoUnplayableException.Unplayable(videoId, playerResponse.TryGetVideoPlayabilityError());
            }

            if (playerResponse.IsLive())
            {
                throw VideoUnplayableException.LiveStream(videoId);
            }

            var streamInfoProviders = new List <IStreamInfoProvider>();

            // Streams from video info
            streamInfoProviders.AddRange(videoInfoResponse.GetStreams());

            // Streams from player response
            streamInfoProviders.AddRange(playerResponse.GetStreams());

            // Streams from DASH manifest
            var dashManifestUrl = playerResponse.TryGetDashManifestUrl();

            if (!string.IsNullOrWhiteSpace(dashManifestUrl))
            {
                var dashManifest = await GetDashManifestAsync(dashManifestUrl, cipherOperations);

                streamInfoProviders.AddRange(dashManifest.GetStreams());
            }

            return(new StreamContext(streamInfoProviders, cipherOperations));
        }
        public async Task Test_Paginator()
        {
            // Use an object initializer ideally. This code is written the way it is for demonstration purposes.
            var pages = new List <EmbedPage>();

            var p1 = new EmbedPage
            {
                Title       = "First Page",
                Description = "Interesting Information",
            };

            var p2 = new EmbedPage
            {
                Title = "Second Page",
                AlternateAuthorTitle = Context.User.Username,
                AlteranteAuthorIcon  = Context.User.GetAvatarUrl()
            };

            var p3 = new EmbedPage
            {
                ImageUrl = "https://img2.gelbooru.com/samples/a5/9c/sample_a59c7a3eefe67b062ea37825ce6cea83.jpg",
            };

            pages.Add(p1);
            pages.Add(p2);
            pages.Add(p3);

            var options = new PaginatedAppearanceOptions
            {
                InformationText = "This fancy embed is called a Paginator",
                Timeout         = TimeSpan.FromSeconds(30),
            };

            var pagedEmbed = new PaginatedMessage
            {
                Pages          = pages,
                Options        = options,
                FooterOverride = new EmbedFooterBuilder().WithText("Nice Footer")
            };

            await PagedReplyAsync(pagedEmbed, new ReactionList());
        }
Exemple #3
0
        public async Task FetchAnime([Remainder] string query)
        {
            if (query.Length < 3)
            {
                await Context.Channel.SendErrorAsync("Your input must have at least 3 characters !",
                                                     "Please try again!");

                return;
            }

            var animeSearchConfig = new AnimeSearchConfig
            {
                Type = AnimeType.EveryType
            };
            var animeSearchResult = await _jikan.SearchAnime($"{query}", animeSearchConfig);

            var animeSearch = animeSearchResult.Results;

            if (animeSearch == null)
            {
                await Context.Channel.SendErrorJikanAsync($"Not found any anime for {query}",
                                                          "Error ! Please recheck your spelling", Context.User);

                return;
            }

            var animeSearchEntry = EvaluateAnime(query, animeSearch);
            //Computing misses
            //var computing = LevenshteinDistanceComputingService.Evaluation(query.ToLower(), animeSearchEntry.Title.ToLower());
            var percentage = query.Length / (double)animeSearchEntry.Title.Length * 100;

            #region Anime version and spinoff

            /*
             * var animeVer = await _jikan.GetAnime(animeSearchEntry.MalId);
             * var sb = new StringBuilder();
             * if (animeVer.Related.SpinOffs != null)
             *  foreach (var spinOff in animeVer.Related.SpinOffs)
             *      sb.AppendLine("Spinoff : " + spinOff.Name + $"\nMAL link : [Click here]({spinOff.Url})");
             *
             * if (animeVer.Related.Sequels != null)
             *  foreach (var sequel in animeVer.Related.Sequels)
             *      sb.AppendLine("Sequel : " + sequel.Name + $"\nMAL link : [Click here]({sequel.Url})");
             *
             * if (animeVer.Related.AlternativeVersions != null)
             *  foreach (var alter in animeVer.Related.AlternativeVersions)
             *      sb.AppendLine("Alternative : " + alter.Name + $"\nMAL link : [Click here]({alter.Url})");
             *
             * if (animeVer.Related.AlternativeSettings != null)
             *  foreach (var alterS in animeVer.Related.AlternativeSettings)
             *      sb.AppendLine("Alternative : " + alterS.Name + $"\nMAL link : [Click here]({alterS.Url})");
             *
             * if (animeVer.Related.Adaptations != null)
             *  foreach (var adaption in animeVer.Related.Adaptations)
             *      sb.AppendLine("Adaption : " + adaption.Name + $"\nMAL link : [Click here]({adaption.Url})");
             *
             * if (animeVer.Related.Prequels != null)
             *  foreach (var prequel in animeVer.Related.Prequels)
             *      sb.AppendLine("Prequel : " + prequel.Name + $"\nMAL link : [Click here]({prequel.Url})");
             *
             */

            #endregion

            if (percentage >= 33)
            {
                await Context.Channel.SendSuccessAnimeAsync($"Found anime for [{query}]",
                                                            $"{animeSearchEntry.Title}",
                                                            $"{animeSearchEntry.Rated}",
                                                            $"{animeSearchEntry.Score}",
                                                            $"{animeSearchEntry.Episodes}",
                                                            $"{animeSearchEntry.Description}",
                                                            $"{animeSearchEntry.URL}",
                                                            animeSearchEntry.ImageURL, Context.User);
            }
            else
            {
                var pages = new List <EmbedPage>();
                var count = 0;
                foreach (var result in animeSearch)
                {
                    var page = new EmbedPage
                    {
                        Title                = $"**{result.Title}**",
                        Description          = result.Description,
                        AlternateAuthorTitle = "MyAnimeList",
                        AlternateAuthorIcon  = "https://cdn.myanimelist.net/img/sp/icon/apple-touch-icon-256.png",
                        ThumbnailUrl         = result.ImageURL,
                        Url       = result.URL,
                        TimeStamp = Now
                    };
                    count++;
                    if (count == 6)
                    {
                        break;
                    }
                    pages.Add(page);
                }

                var options = new PaginatedAppearanceOptions
                {
                    InformationText = $"**Possible result for [{query}]**",
                    Next            = new Emoji("▶️"),
                    Back            = new Emoji("◀️"),
                    Last            = new Emoji("↪️"),
                    First           = new Emoji("↩️"),
                    Timeout         = TimeSpan.FromSeconds(60)
                };

                var paginatedMessage = new PaginatedMessage
                {
                    Pages   = pages,
                    Content =
                        $"**Showing maximum of 5 possible options for [{query}] since threshold for match is below 33%**",
                    Options        = options,
                    FooterOverride = new EmbedFooterBuilder().WithText($"Requested by {Context.User.Username}")
                                     .WithIconUrl(Context.User.GetAvatarUrl() ?? Context.User.GetDefaultAvatarUrl()),
                    TimeStamp = Now,
                    Color     = new Color(Utils.RandomColor(), Utils.RandomColor(), Utils.RandomColor())
                };
                await PagedReplyAsync(paginatedMessage, new ReactionList());
            }
        }
Exemple #4
0
        public async Task FetchManga([Remainder] string query)
        {
            if (query.Length < 3)
            {
                await Context.Channel.SendErrorAsync("Your input must have at least 3 characters !",
                                                     "Please try again!");

                return;
            }

            var mangaSearchConfig = new MangaSearchConfig
            {
                Type = MangaType.EveryType
            };
            var mangaSearchResult = await _jikan.SearchManga($"{query}", mangaSearchConfig);

            var mangaSearch = mangaSearchResult.Results;

            if (mangaSearch == null)
            {
                await Context.Channel.SendErrorJikanAsync($"Not found any manga for {query}",
                                                          "Error ! Please recheck your spelling", Context.User);

                return;
            }

            var mangaSearchEntry = EvaluateManga(query, mangaSearch);
            var percentage       = query.Length / (double)mangaSearchEntry.Title.Length * 100;

            if (percentage >= 33)
            {
                await Context.Channel.SendSuccessMangaAsync($"Found manga for [{query}]",
                                                            $"{mangaSearchEntry.Title}",
                                                            $"{mangaSearchEntry.Type}",
                                                            $"{mangaSearchEntry.Score}",
                                                            $"{mangaSearchEntry.Description}",
                                                            $"{mangaSearchEntry.URL}",
                                                            mangaSearchEntry.ImageURL, Context.User);
            }
            else
            {
                var pages = new List <EmbedPage>();
                var count = 0;
                foreach (var result in mangaSearch)
                {
                    var page = new EmbedPage
                    {
                        Title                = $"**{result.Title}**",
                        Description          = result.Description,
                        AlternateAuthorTitle = "MyAnimeList",
                        AlternateAuthorIcon  = "https://cdn.myanimelist.net/img/sp/icon/apple-touch-icon-256.png",
                        ThumbnailUrl         = result.ImageURL,
                        Url       = result.URL,
                        TimeStamp = Now
                    };
                    count++;
                    if (count == 6)
                    {
                        break;
                    }
                    pages.Add(page);
                }

                var options = new PaginatedAppearanceOptions
                {
                    InformationText = $"**Possible result for [{query}]**",
                    Next            = new Emoji("▶️"),
                    Back            = new Emoji("◀️"),
                    Last            = new Emoji("↪️"),
                    First           = new Emoji("↩️"),
                    Timeout         = TimeSpan.FromSeconds(60)
                };

                var paginatedMessage = new PaginatedMessage
                {
                    Pages   = pages,
                    Content =
                        $"**Showing maximum of 5 possible options for [{query}] since threshold for match is below 33%**",
                    Options        = options,
                    FooterOverride = new EmbedFooterBuilder().WithText($"Requested by {Context.User.Username}")
                                     .WithIconUrl(Context.User.GetAvatarUrl() ?? Context.User.GetDefaultAvatarUrl()),
                    TimeStamp = Now,
                    Color     = new Color(Utils.RandomColor(), Utils.RandomColor(), Utils.RandomColor())
                };
                await PagedReplyAsync(paginatedMessage, new ReactionList());
            }
        }