예제 #1
0
        public async void TestGetItemByIdBad()
        {
            var omdb = new AsyncOmdbClient(TestData.apikey);
            await Assert.ThrowsAsync <ArgumentException>(() => omdb.GetItemByIdAsync(null));

            await Assert.ThrowsAsync <ArgumentException>(() => omdb.GetItemByIdAsync(""));

            await Assert.ThrowsAsync <ArgumentException>(() => omdb.GetItemByIdAsync(" "));

            await Assert.ThrowsAsync <HttpRequestException>(() => omdb.GetItemByIdAsync("wrongID"));
        }
예제 #2
0
        public async void TestGetItemByIdGood()
        {
            var omdb  = new AsyncOmdbClient(TestData.apikey);
            var movie = await omdb.GetItemByIdAsync("tt0076759", true);

            var ratings = movie.Ratings.ToArray();

            Assert.Equal("Internet Movie Database", ratings[0].Source);
            Assert.Equal("Rotten Tomatoes", ratings[1].Source);
            Assert.Equal("Metacritic", ratings[2].Source);

            Assert.Equal("Star Wars: Episode IV - A New Hope", movie.Title);
            Assert.Equal("1977", movie.Year);
            Assert.Equal("PG", movie.Rated);
            Assert.Equal("25 May 1977", movie.Released);
            Assert.Equal("121 min", movie.Runtime);
            Assert.Equal("George Lucas", movie.Director);
            Assert.Equal("George Lucas", movie.Writer);
            Assert.Equal("English", movie.Language);
            Assert.Equal("USA", movie.Country);
            Assert.Equal("movie", movie.Type);
            Assert.Equal("21 Sep 2004", movie.Dvd);
            Assert.Equal("N/A", movie.BoxOffice);
            Assert.Equal("20th Century Fox", movie.Production);
            Assert.Equal("http://www.starwars.com/episode-iv/", movie.Website);
            Assert.Equal("True", movie.Response);
        }
예제 #3
0
        public string GetAsset(Media media)
        {
            var imdb = (media as Episode)?.ShowId.IMDB ?? media.Id?.IMDB;

            if (!string.IsNullOrEmpty(imdb))
            {
                return(omdb.GetItemByIdAsync(imdb).Result?.Poster);
            }
            return(null);
        }
예제 #4
0
        public async void TestGetItemByIdGood2()
        {
            var omdb = new AsyncOmdbClient(TestData.apikey, true);
            var game = await omdb.GetItemByIdAsync("tt1814884");

            Assert.Equal("The Elder Scrolls V: Skyrim", game.Title);
            Assert.Equal("2011", game.Year);
            Assert.Equal("N/A", game.Rated);
            Assert.Equal("11 Nov 2011", game.Released);
            Assert.Equal("N/A", game.Runtime);
        }
예제 #5
0
        public async Task ImdbCmdAsync([Remainder] string query)
        {
            var author = new EmbedAuthorBuilder()
                         .WithName("IMDb")
                         .WithIconUrl("http://files.softicons.com/download/social-media-icons/flat-gradient-social-icons-by-guilherme-lima/png/512x512/IMDb.png")
                         .WithUrl("https://www.imdb.com/");
            var list = await _omdb.GetSearchListAsync(query).ConfigureAwait(false);

            if (!string.IsNullOrEmpty(list.Error))
            {
                await Context.MarkCmdFailedAsync($"OMDB: {list.Error}").ConfigureAwait(false);

                return;
            }
            if (list.SearchResults.Count == 1)
            {
                var item = await _omdb.GetItemByIdAsync(list.SearchResults[0].ImdbId).ConfigureAwait(false);

                var embed = new EmbedBuilder()
                            .WithColor(new Color(248, 231, 28))
                            .WithCurrentTimestamp()
                            .WithTitle($"{item.Title} ({item.Year})")
                            .WithDescription($"{item.Plot} ({item.Runtime})")
                            .WithUrl($"https://www.imdb.com/title/{ item.ImdbId}")
                            .WithImageUrl(item.Poster)
                            .WithAuthor(author)
                            .AddField("Rating", $"{item.ImdbRating}\nMetascore: {item.Metascore}")
                            .AddField("Info", $"Director: {item.Director}\nWriter: {item.Writer}\nCast: {item.Actors}\nGenre: {item.Genre}\nCountry: {item.Country}")
                            .AddField("Release dates", $"Released: {item.Released}\nDVD: {item.Dvd}", true)
                            .AddField("Trivia", $"Box office: {item.BoxOffice}\nAwards: {item.Awards}")
                            .Build();
                await ReplyAsync(embed : embed).ConfigureAwait(false);

                return;
            }
            var pages = new List <string>();

            foreach (var result in list.SearchResults)
            {
                var item = await _omdb.GetItemByIdAsync(result.ImdbId).ConfigureAwait(false);

                var str = $@"{$"{item.Title} ({item.Year})".Bold().Hyperlink(Helpers.BuildSafeUrl($"https://www.imdb.com/title/{item.ImdbId}"))}
{item.Plot} ({item.Runtime})
{"Rating".Bold()}
{item.ImdbRating}
Metascore: {item.Metascore}
{"Info".Bold()}
Director: {item.Director}
Writer: {item.Writer}
Cast: {item.Actors}
Genre: {item.Genre}
Country: {item.Country}
{"Release dates".Bold()}
Released: {item.Released}
DVD: {item.Dvd}
{"Trivia".Bold()}
Box office: {item.BoxOffice}
Awards: {item.Awards}";
                pages.Add(str);
            }
            var msg = new PaginatedMessage()
            {
                Title = $"Search results for {query.Italics()}", Author = author, Color = new Color(248, 231, 28), Pages = pages
            };

            await PagedReplyAsync(msg, false).ConfigureAwait(false);
        }