Example #1
0
        public IActionResult WebSearch(string query, int page)
        {
            // Accepts a search query and passes it to TMDb.org's API and accepts the search results.

            int currentPage = 1;
            int lastPage    = 1;

            List <Movie> movies = new List <Movie>();

            // This is the request to the TMDb API.  It returns a container of movies.
            // Null is returned if the site cannot be reached and/or there is an exception.
            SearchContainer <SearchMovie> results = TMDbSearch(client, query, page);

            // Credits, Video, and Image information is pulled for each movie in the search results.
            if (results != null && results.Results != null)
            {
                lastPage    = results.TotalPages;
                currentPage = page;

                foreach (var result in results.Results)
                {
                    Movie aMovie = GetTMDbMovieInfo(result.Id);
                    if (aMovie != null)
                    {
                        movies.Add(aMovie);
                    }
                }
            }
            SearchViewModel searchViewModel = new SearchViewModel(movies);

            searchViewModel.CurrentPage = currentPage;
            searchViewModel.LastPage    = lastPage;
            searchViewModel.Query       = query;
            return(View("Results", searchViewModel));
        }
Example #2
0
        private void MakePeopleEmbed(int count, SearchContainer <SearchPerson> results, EmbedBuilder builder, string searchTerm, List <EmbedBuilder> builders)
        {
            for (var i = 0; i < count; i++)
            {
                try
                {
                    if (results.Results[i].Name != string.Empty)
                    {
                        builder.AddField("Title", results.Results[i].Name);
                        if (results.Results.Count <= 5)
                        {
                            builder.AddField("URL", $"https://www.themoviedb.org/movie/{results.Results[i].Id}-{results.Results[i].Name.Replace(" ", "-")}language=en-US");
                        }
                    }

                    builder.Title = $"Search Results for {searchTerm}";
                }
                catch (Exception e)
                {
                    builders.Add(new EmbedBuilder()
                    {
                        Title = $"Title:{results.Results[i].Name}"
                    });
                }
            }
        }
Example #3
0
        public void TestMoviesList()
        {
            //GetMovieList(MovieListType type, string language, int page = -1)
            foreach (MovieListType type in Enum.GetValues(typeof(MovieListType)).OfType <MovieListType>())
            {
                SearchContainer <MovieResult> list = _config.Client.GetMovieList(type);

                Assert.IsNotNull(list);
                Assert.IsTrue(list.Results.Count > 0);
                Assert.AreEqual(1, list.Page);

                SearchContainer <MovieResult> listPage2 = _config.Client.GetMovieList(type, 2);

                Assert.IsNotNull(listPage2);
                Assert.IsTrue(listPage2.Results.Count > 0);
                Assert.AreEqual(2, listPage2.Page);

                SearchContainer <MovieResult> listDe = _config.Client.GetMovieList(type, "de");

                Assert.IsNotNull(listDe);
                Assert.IsTrue(listDe.Results.Count > 0);
                Assert.AreEqual(1, listDe.Page);

                // At least one title should differ
                Assert.IsTrue(list.Results.Any(s => listDe.Results.Any(x => x.Title != s.Title)));
            }
        }
Example #4
0
        public void TestTvShowSimilars()
        {
            SearchContainer <SearchTv> tvShow = _config.Client.GetTvShowSimilarAsync(1668).Result;

            Assert.IsNotNull(tvShow);
            Assert.IsNotNull(tvShow.Results);

            SearchTv item = tvShow.Results.SingleOrDefault(s => s.Id == 1100);

            Assert.IsNotNull(item);

            Assert.IsTrue(TestImagesHelpers.TestImagePath(item.BackdropPath), "item.BackdropPath was not a valid image path, was: " + item.BackdropPath);
            Assert.AreEqual(1100, item.Id);
            Assert.AreEqual("How I Met Your Mother", item.OriginalName);
            Assert.AreEqual(new DateTime(2005, 09, 19), item.FirstAirDate);
            Assert.IsTrue(TestImagesHelpers.TestImagePath(item.PosterPath), "item.PosterPath was not a valid image path, was: " + item.PosterPath);
            Assert.IsTrue(item.Popularity > 0);
            Assert.AreEqual("How I Met Your Mother", item.Name);
            Assert.IsTrue(item.VoteAverage > 0);
            Assert.IsTrue(item.VoteCount > 0);

            Assert.IsNotNull(item.OriginCountry);
            Assert.AreEqual(1, item.OriginCountry.Count);
            Assert.IsTrue(item.OriginCountry.Contains("US"));
        }
Example #5
0
        public void TestMoviesTopRatedList()
        {
            // Ignore missing json
            IgnoreMissingJson("results[array] / media_type");

            SearchContainer <SearchMovie> list = Config.Client.GetMovieTopRatedListAsync().Result;

            Assert.NotNull(list);
            Assert.True(list.Results.Count > 0);
            Assert.Equal(1, list.Page);

            SearchContainer <SearchMovie> listPage2 = Config.Client.GetMovieTopRatedListAsync(page: 2).Result;

            Assert.NotNull(listPage2);
            Assert.True(listPage2.Results.Count > 0);
            Assert.Equal(2, listPage2.Page);

            SearchContainer <SearchMovie> listDe = Config.Client.GetMovieTopRatedListAsync("de").Result;

            Assert.NotNull(listDe);
            Assert.True(listDe.Results.Count > 0);
            Assert.Equal(1, listDe.Page);

            // At least one title should differ
            Assert.True(list.Results.Any(s => listDe.Results.Any(x => x.Title != s.Title)));

            SearchContainer <SearchMovie> listRegion = Config.Client.GetMovieTopRatedListAsync(region: "de").Result;

            Assert.NotNull(listRegion);
            Assert.True(listRegion.Results.Count > 0);
            Assert.Equal(1, listRegion.Page);

            // At least one title should differ
            Assert.True(listDe.Results.Any(s => listRegion.Results.Any(x => x.Title != s.Title)));
        }
Example #6
0
        public ActionResult Discover(string type, int page = 1)
        {
            var results = new SearchContainer<MovieResult>();

            ViewBag.UserMovies = getListMovies();
            ViewBag.UserLists = getUserLists();

            switch (type)
            {
                case POPULAR:
                    results = Client.GetMovieList(MovieListType.Popular, page);
                    break;
                case RATED:
                    results = Client.GetMovieList(MovieListType.TopRated, page);
                    break;
                case UPCOMING:
                    results = Client.GetMovieList(MovieListType.Upcoming, page);
                    break;
                case NOWPLAYING:
                    results = Client.GetMovieList(MovieListType.NowPlaying, page);
                    break;
                default:
                    results = Client.GetMovieList(MovieListType.Popular, page);
                    break;
            }
            return PartialView("../Partials/_SearchResults", results);
        }
        private async Task <Entities.Movie> SearchMovie(FileInfo file, IEnumerable <TMDbLib.Objects.General.Genre> movieGenres, Action <Entities.Movie, FileInfo> callback, Action <int, string> progressReportCallback)
        {
            SearchContainer <SearchMovie> searchResult = await _tmdbClient.SearchMovieAsync(Path.GetFileNameWithoutExtension(file.Name), includeAdult : true);

            IncrementRequestCount();
            AddProgress(1, $"Retrieving info for '{Path.GetFileNameWithoutExtension(file.Name)}'");

            SearchMovie foundMovie = searchResult.Results.FirstOrDefault();

            if (foundMovie == null)
            {
                return(null);
            }

            Entities.Movie movie = new Entities.Movie(foundMovie);

            movie.ItemGenres = movieGenres
                               .Where(g => foundMovie.GenreIds.Contains(g.Id))
                               .Select(g => new ItemGenre {
                Item  = movie,
                Genre = new Entities.Genre(g)
            }).ToList();

            callback(movie, file);

            return(movie);
        }
Example #8
0
        public void TestSearchMulti()
        {
            TestHelpers.SearchPages(i => _config.Client.SearchMulti("Arrow", i).Result);

            SearchContainer <SearchMulti> result = _config.Client.SearchMulti("Arrow").Result;

            Assert.IsTrue(result.Results.Any());
            SearchMulti item = result.Results.SingleOrDefault(s => s.Id == 1412);

            Assert.IsNotNull(item);
            Assert.AreEqual(1412, item.Id);
            Assert.AreEqual("/dXTyVDTIgeByvUOUEiHjbi8xX9A.jpg", item.BackdropPath);
            Assert.AreEqual(new DateTime(2012, 10, 10), item.FirstAirDate);
            Assert.AreEqual(MediaType.TVShow, item.Type);
            Assert.AreEqual("Arrow", item.Name);
            Assert.AreEqual("Arrow", item.OriginalName);
            Assert.AreEqual("/mo0FP1GxOFZT4UDde7RFDz5APXF.jpg", item.PosterPath);
            Assert.IsTrue(item.Popularity > 0);
            Assert.IsTrue(item.VoteAverage > 0);
            Assert.IsTrue(item.VoteCount > 0);
            Assert.IsTrue(item.GenreIds.Any());

            Assert.IsNotNull(item.OriginCountry);
            Assert.AreEqual(2, item.OriginCountry.Count);
            Assert.IsTrue(item.OriginCountry.Contains("US"));
            Assert.IsTrue(item.OriginCountry.Contains("CA"));
        }
Example #9
0
 protected override FlowContainer <SettingsSection> CreateScrollContentContainer()
 => SearchContainer = new SearchContainer <SettingsSection>
 {
     AutoSizeAxes     = Axes.Y,
     RelativeSizeAxes = Axes.X,
     Direction        = FillDirection.Vertical,
 };
Example #10
0
        public void TestMoviesGetMovieRecommendationsMovies()
        {
            // Ignore missing json
            IgnoreMissingJson("results[array] / media_type");

            SearchContainer <SearchMovie> resp = Config.Client.GetMovieRecommendationsAsync(IdHelper.AGoodDayToDieHard).Result;

            Assert.NotNull(resp);

            SearchContainer <SearchMovie> respGerman = Config.Client.GetMovieRecommendationsAsync(IdHelper.AGoodDayToDieHard, language: "de").Result;

            Assert.NotNull(respGerman);

            Assert.Equal(resp.Results.Count, respGerman.Results.Count);

            int differentTitles = 0;

            for (int i = 0; i < resp.Results.Count; i++)
            {
                Assert.Equal(resp.Results[i].Id, respGerman.Results[i].Id);

                // At least one title should be different, as German is a big language and they dub all their titles.
                differentTitles++;
            }

            Assert.True(differentTitles > 0);
        }
Example #11
0
        public void TestTvShowSimilars()
        {
            SearchContainer <SearchTv> tvShow = _config.Client.GetTvShowSimilar(1668).Result;

            Assert.IsNotNull(tvShow);
            Assert.IsNotNull(tvShow.Results);

            SearchTv item = tvShow.Results.SingleOrDefault(s => s.Id == 1100);

            Assert.IsNotNull(item);

            Assert.AreEqual("/wfe7Xf7tc0zmnkoNyN3xor0xR8m.jpg", item.BackdropPath);
            Assert.AreEqual(1100, item.Id);
            Assert.AreEqual("How I Met Your Mother", item.OriginalName);
            Assert.AreEqual(new DateTime(2005, 09, 19), item.FirstAirDate);
            Assert.AreEqual("/izncB6dCLV7LBQ5MsOPyMx9mUDa.jpg", item.PosterPath);
            Assert.IsTrue(item.Popularity > 0);
            Assert.AreEqual("How I Met Your Mother", item.Name);
            Assert.IsTrue(item.VoteAverage > 0);
            Assert.IsTrue(item.VoteCount > 0);

            Assert.IsNotNull(item.OriginCountry);
            Assert.AreEqual(1, item.OriginCountry.Count);
            Assert.IsTrue(item.OriginCountry.Contains("US"));
        }
Example #12
0
        public static List <MovieDB_Movie_Result> Search(string criteria)
        {
            List <MovieDB_Movie_Result> results = new List <MovieDB_Movie_Result>();

            try
            {
                TMDbClient client = new TMDbClient(apiKey);
                SearchContainer <SearchMovie> resultsTemp = client.SearchMovie(criteria);

                Console.WriteLine("Got {0} of {1} results", resultsTemp.Results.Count, resultsTemp.TotalResults);
                foreach (SearchMovie result in resultsTemp.Results)
                {
                    MovieDB_Movie_Result searchResult = new MovieDB_Movie_Result();
                    Movie        movie = client.GetMovie(result.Id);
                    ImagesWithId imgs  = client.GetMovieImages(result.Id);
                    searchResult.Populate(movie, imgs);
                    results.Add(searchResult);
                    SaveMovieToDatabase(searchResult, false, false);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error in MovieDB Search: " + ex.Message);
            }

            return(results);
        }
Example #13
0
        public void TestSearchMulti()
        {
            TestHelpers.SearchPages(i => Config.Client.SearchMultiAsync("Arrow", i).Result);

            SearchContainer <SearchBase> result = Config.Client.SearchMultiAsync("Arrow").Result;

            Assert.True(result.Results.Any());
            SearchTv item = result.Results.OfType <SearchTv>().SingleOrDefault(s => s.Id == 1412);

            Assert.NotNull(item);
            Assert.Equal(1412, item.Id);
            Assert.True(TestImagesHelpers.TestImagePath(item.BackdropPath), "item.BackdropPath was not a valid image path, was: " + item.BackdropPath);
            Assert.Equal(new DateTime(2012, 10, 10), item.FirstAirDate);
            Assert.Equal(MediaType.Tv, item.MediaType);
            Assert.Equal("Arrow", item.Name);
            Assert.Equal("Arrow", item.OriginalName);
            Assert.True(TestImagesHelpers.TestImagePath(item.PosterPath), "item.PosterPath was not a valid image path, was: " + item.PosterPath);
            Assert.True(item.Popularity > 0);
            Assert.True(item.VoteAverage > 0);
            Assert.True(item.VoteCount > 0);

            Assert.NotNull(item.OriginCountry);
            Assert.Equal(2, item.OriginCountry.Count);
            Assert.True(item.OriginCountry.Contains("US"));
            Assert.True(item.OriginCountry.Contains("CA"));
        }
Example #14
0
        //Fetch Movies with search string
        private static async Task <PagedResult <Movie> > FetchMovies(TMDbClient client, string query, int page)
        {
            SearchContainer <SearchMovie> results = await client.SearchMovieAsync(query, page);

            var getMovies = (from result in results.Results
                             select new
            {
                Title = result.Title,
                PosterPath = result.PosterPath,
                Id = result.Id
            }).ToList().Select(p => new Movie()
            {
                Title      = p.Title,
                PosterPath = p.PosterPath,
                Id         = p.Id
            });

            var pagedMovie = new PagedResult <Movie>
            {
                Data       = getMovies.ToList(),
                TotalItems = results.TotalResults,
                PageNumber = page,
                PageSize   = 21
            };

            return(pagedMovie);
        }
Example #15
0
        public void TestSearchTvShow()
        {
            // Ignore missing json
            IgnoreMissingJson("results[array] / media_type");

            TestHelpers.SearchPages(i => Config.Client.SearchTvShowAsync("Breaking Bad", i).Result);

            SearchContainer <SearchTv> result = Config.Client.SearchTvShowAsync("Breaking Bad").Result;

            Assert.True(result.Results.Any());
            SearchTv item = result.Results.SingleOrDefault(s => s.Id == 1396);

            Assert.NotNull(item);
            Assert.Equal(1396, item.Id);
            Assert.True(TestImagesHelpers.TestImagePath(item.BackdropPath), "item.BackdropPath was not a valid image path, was: " + item.BackdropPath);
            Assert.Equal(new DateTime(2008, 1, 19), item.FirstAirDate);
            Assert.Equal("Breaking Bad", item.Name);
            Assert.Equal("Breaking Bad", item.OriginalName);
            Assert.Equal("en", item.OriginalLanguage);
            Assert.True(TestImagesHelpers.TestImagePath(item.PosterPath), "item.PosterPath was not a valid image path, was: " + item.PosterPath);
            Assert.Equal("Breaking Bad is an American crime drama television series created and produced by Vince Gilligan. Set and produced in Albuquerque, New Mexico, Breaking Bad is the story of Walter White, a struggling high school chemistry teacher who is diagnosed with inoperable lung cancer at the beginning of the series. He turns to a life of crime, producing and selling methamphetamine, in order to secure his family's financial future before he dies, teaming with his former student, Jesse Pinkman. Heavily serialized, the series is known for positioning its characters in seemingly inextricable corners and has been labeled a contemporary western by its creator.", item.Overview);
            Assert.True(item.Popularity > 0);
            Assert.True(item.VoteAverage > 0);
            Assert.True(item.VoteCount > 0);

            Assert.NotNull(item.GenreIds);
            Assert.Equal(1, item.GenreIds.Count);
            Assert.Equal(18, item.GenreIds[0]);

            Assert.NotNull(item.OriginCountry);
            Assert.Equal(1, item.OriginCountry.Count);
            Assert.Equal("US", item.OriginCountry[0]);
        }
Example #16
0
        public void TestSearchMovie()
        {
            TestHelpers.SearchPages(i => Config.Client.SearchMovieAsync("007", i).Result);

            // Search pr. Year
            // 1962: First James Bond movie, "Dr. No"
            SearchContainer <SearchMovie> result = Config.Client.SearchMovieAsync("007", year: 1962).Result;

            Assert.True(result.Results.Any());
            SearchMovie item = result.Results.SingleOrDefault(s => s.Id == 646);

            Assert.NotNull(item);
            Assert.Equal(646, item.Id);
            Assert.Equal(false, item.Adult);
            Assert.True(TestImagesHelpers.TestImagePath(item.BackdropPath), "item.BackdropPath was not a valid image path, was: " + item.BackdropPath);
            Assert.Equal("en", item.OriginalLanguage);
            Assert.Equal("Dr. No", item.OriginalTitle);
            Assert.Equal("In the film that launched the James Bond saga, Agent 007 (Sean Connery) battles mysterious Dr. No, a scientific genius bent on destroying the U.S. space program. As the countdown to disaster begins, Bond must go to Jamaica, where he encounters beautiful Honey Ryder (Ursula Andress), to confront a megalomaniacal villain in his massive island headquarters.", item.Overview);
            Assert.Equal(false, item.Video);
            Assert.True(TestImagesHelpers.TestImagePath(item.PosterPath), "item.PosterPath was not a valid image path, was: " + item.PosterPath);
            Assert.Equal(new DateTime(1962, 10, 4), item.ReleaseDate);
            Assert.Equal("Dr. No", item.Title);
            Assert.True(item.Popularity > 0);
            Assert.True(item.VoteAverage > 0);
            Assert.True(item.VoteCount > 0);

            Assert.NotNull(item.GenreIds);
            Assert.True(item.GenreIds.Contains(12));
            Assert.True(item.GenreIds.Contains(28));
            Assert.True(item.GenreIds.Contains(53));
        }
Example #17
0
        public void TestPersonsList()
        {
            foreach (PersonListType type in Enum.GetValues(typeof(PersonListType)).OfType <PersonListType>())
            {
                SearchContainer <PersonResult> list = Config.Client.GetPersonListAsync(type).Result;

                Assert.NotNull(list);
                Assert.True(list.Results.Count > 0);
                Assert.Equal(1, list.Page);

                SearchContainer <PersonResult> listPage2 = Config.Client.GetPersonListAsync(type, 2).Result;

                Assert.NotNull(listPage2);
                Assert.True(listPage2.Results.Count > 0);
                Assert.Equal(2, listPage2.Page);

                SearchContainer <PersonResult> list2 = Config.Client.GetPersonListAsync(type).Result;

                Assert.NotNull(list2);
                Assert.True(list2.Results.Count > 0);
                Assert.Equal(1, list2.Page);

                // At least one person should differ
                Assert.True(list.Results.Any(s => list2.Results.Any(x => x.Name != s.Name)));
            }
        }
Example #18
0
        public void TestPersonsGetPersonChanges()
        {
            // Not all ChangeItem's have an iso_639_1
            IgnoreMissingJson(" / iso_639_1");

            // FindAsync latest changed person
            SearchContainer <ChangesListItem> latestChanges = Config.Client.GetChangesPeopleAsync().Sync();
            int latestChanged = latestChanges.Results.Last().Id;

            // Fetch changelog
            DateTime      lower     = DateTime.UtcNow.AddDays(-14);
            DateTime      higher    = DateTime.UtcNow;
            List <Change> respRange = Config.Client.GetPersonChangesAsync(latestChanged, lower, higher).Result;

            Assert.NotNull(respRange);
            Assert.True(respRange.Count > 0);

            // As TMDb works in days, we need to adjust our values also
            lower  = lower.AddDays(-1);
            higher = higher.AddDays(1);

            foreach (Change change in respRange)
            {
                foreach (ChangeItemBase changeItem in change.Items)
                {
                    DateTime date = changeItem.Time;
                    Assert.True(lower <= date);
                    Assert.True(date <= higher);
                }
            }
        }
        private async Task <SearchContainer <ChangesListItem> > GetChanges(string type, int page = 0, DateTime?startDate = null, DateTime?endDate = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            RestRequest req = _client.Create("{type}/changes");

            req.AddUrlSegment("type", type);

            if (page >= 1)
            {
                req.AddParameter("page", page.ToString());
            }
            if (startDate.HasValue)
            {
                req.AddParameter("start_date", startDate.Value.ToString("yyyy-MM-dd"));
            }
            if (endDate != null)
            {
                req.AddParameter("end_date", endDate.Value.ToString("yyyy-MM-dd"));
            }

            RestResponse <SearchContainer <ChangesListItem> > resp = await req.ExecuteGet <SearchContainer <ChangesListItem> >(cancellationToken).ConfigureAwait(false);

            SearchContainer <ChangesListItem> res = await resp.GetDataObject().ConfigureAwait(false);

            // https://github.com/LordMike/TMDbLib/issues/296
            res.Results.RemoveAll(s => s.Id == 0);

            return(res);
        }
Example #20
0
        public void TestSearchMovie()
        {
            TestHelpers.SearchPages(i => _config.Client.SearchMovie("007", i).Result);

            // Search pr. Year
            // 1962: First James Bond movie, "Dr. No"
            SearchContainer <SearchMovie> result = _config.Client.SearchMovie("007", year: 1962).Result;

            Assert.IsTrue(result.Results.Any());
            SearchMovie item = result.Results.SingleOrDefault(s => s.Id == 646);

            Assert.IsNotNull(item);
            Assert.AreEqual(646, item.Id);
            Assert.AreEqual(false, item.Adult);
            Assert.AreEqual("/bplDiT5JhaXf9S5arO8g5QsFtDi.jpg", item.BackdropPath);
            Assert.AreEqual("en", item.OriginalLanguage);
            Assert.AreEqual("Dr. No", item.OriginalTitle);
            Assert.AreEqual("When Strangways, the British SIS Station Chief in Jamaica goes missing, MI6 send James Bond - Agent 007 to investigate. His investigation leads him to the mysterious Crab Key; the secret base of Dr No who he suspects is trying to sabotage the American space program using a radio beam. With the assistance of local fisherman Quarrel, who had been helping Strangways, Bond sneaks onto Crab Key where he meets the beautiful Honey Ryder. Can the three of them defeat an army of henchmen and a \"fire breathing dragon\" in order to stop Dr No, save the space program and get revenge for Strangways? Dr. No is the first film of legendary James Bond series starring Sean Connery in the role of Fleming's British super agent.", item.Overview);
            Assert.AreEqual(false, item.Video);
            Assert.AreEqual("/gRdfLVVf6FheOw6mw6wOsKhZG1l.jpg", item.PosterPath);
            Assert.AreEqual(new DateTime(1962, 10, 5), item.ReleaseDate);
            Assert.AreEqual("Dr. No", item.Title);
            Assert.IsTrue(item.Popularity > 0);
            Assert.IsTrue(item.VoteAverage > 0);
            Assert.IsTrue(item.VoteCount > 0);

            Assert.IsNotNull(item.GenreIds);
            Assert.IsTrue(item.GenreIds.Contains(12));
            Assert.IsTrue(item.GenreIds.Contains(28));
            Assert.IsTrue(item.GenreIds.Contains(53));
        }
Example #21
0
        private async Task <SearchContainer <T> > GetAccountList <T>(int page, AccountSortBy sortBy, SortOrder sortOrder, string language, AccountListsMethods method)
        {
            RequireSessionId(SessionType.UserSession);

            RestRequest request = _client.Create("account/{accountId}/" + method.GetDescription());

            request.AddUrlSegment("accountId", ActiveAccount.Id.ToString(CultureInfo.InvariantCulture));
            AddSessionId(request, SessionType.UserSession);

            if (page > 1)
            {
                request.AddParameter("page", page.ToString());
            }

            if (sortBy != AccountSortBy.Undefined)
            {
                request.AddParameter("sort_by", sortBy.GetDescription());
            }

            if (sortOrder != SortOrder.Undefined)
            {
                request.AddParameter("sort_order", sortOrder.GetDescription());
            }

            language = language ?? DefaultLanguage;
            if (!string.IsNullOrWhiteSpace(language))
            {
                request.AddParameter("language", language);
            }

            SearchContainer <T> response = await request.ExecuteGet <SearchContainer <T> >().ConfigureAwait(false);

            return(response);
        }
Example #22
0
        public virtual SearchMovie GetFilmSuggestionBasedOnGenre(List <int> genreIds)
        {
            try
            {
                SearchContainer <SearchMovie> movies = client.DiscoverMoviesAsync()
                                                       .IncludeVideoMovies(false)
                                                       .IncludeAdultMovies(false)
                                                       .IncludeWithAllOfGenre(genreIds)
                                                       .Query(RandomNumber(500)).Result;

                if (movies == null)
                {
                    return(GetFilmSuggestionBasedOnGenre(genreIds));
                }

                var movie = movies.Results.Skip(RandomNumber(19)).Take(1).SingleOrDefault();

                if (movie == null)
                {
                    return(GetFilmSuggestionBasedOnGenre(genreIds));
                }

                return(movie);
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.Flatten().InnerExceptions)
                {
                    Console.WriteLine(e.Message);
                }
                throw new Exception("Try again later.");
            }
        }
Example #23
0
        public static void SearchPages <T>(Func <int, SearchContainer <T> > getter)
        {
            // Check page 1
            SearchContainer <T> results = getter(1);

            Assert.NotNull(results);
            Assert.NotNull(results.Results);
            Assert.Equal(1, results.Page);
            Assert.True(results.Results.Count > 0);
            Assert.True(results.TotalResults > 0);
            Assert.True(results.TotalPages > 0);

            // Check page 2
            SearchContainer <T> results2 = getter(2);

            Assert.NotNull(results2);
            Assert.NotNull(results2.Results);
            Assert.Equal(2, results2.Page);
            // The page counts often don't match due to caching on the api
            //Assert.AreEqual(results.TotalResults, results2.TotalResults);
            //Assert.AreEqual(results.TotalPages, results2.TotalPages);

            if (results.Results.Count == results.TotalResults)
            {
                Assert.Equal(0, results2.Results.Count);
            }
            else
            {
                Assert.NotEqual(0, results2.Results.Count);
            }
        }
Example #24
0
        //Discover Movie through filtering
        private static PagedResult <Movie> FilterMovies(TMDbClient client, int[] genre, int page, DiscoverMovieSortBy sortby, int year)
        {
            DiscoverMovie query = client.DiscoverMoviesAsync().IncludeWithAllOfGenre(genre).WherePrimaryReleaseIsInYear(year).OrderBy(sortby);

            SearchContainer <SearchMovie> results = query.Query(page).Result;

            var getMovies = (from result in results.Results
                             select new
            {
                Title = result.Title,
                PosterPath = result.PosterPath,
                Id = result.Id
            }).ToList().Select(p => new Movie()
            {
                Title      = p.Title,
                PosterPath = p.PosterPath,
                Id         = p.Id
            });
            var pagedMovie = new PagedResult <Movie>
            {
                Data       = getMovies.ToList(),
                TotalItems = results.TotalResults,
                PageNumber = page,
                PageSize   = 21
            };

            return(pagedMovie);
        }
Example #25
0
        ObservableCollection <Film> PopulateList()
        {
            ObservableCollection <Film> ApiMovieList = new ObservableCollection <Film>();
            TMDbClient client = new TMDbClient("7ab50ea9619bac2c618bbd67a7c80cc5");

            for (int i = 1; i < 5; i++)
            {
                SearchContainer <SearchMovie> list = client.GetMoviePopularListAsync("pl", i).Result;
                foreach (SearchMovie movie in list.Results)
                {
                    Film film = new Film
                    {
                        Id           = movie.Id,
                        Title        = movie.Title,
                        Overview     = movie.Overview,
                        BackdropPath = movie.BackdropPath,
                        PosterPath   = movie.PosterPath,
                        VoteAverage  = movie.VoteAverage.ToString()
                    };
                    ApiMovieList.Add(film);
                }
            }
            _movieTitleList = ApiMovieList;
            return(_movieTitleList);
        }
Example #26
0
 protected override Container <Drawable> CreateScrollContentContainer()
 => SearchContainer = new SearchContainer
 {
     AutoSizeAxes     = Axes.Y,
     RelativeSizeAxes = Axes.X,
     Direction        = FillDirection.Vertical,
 };
        public override async Task <IList <SearchResult> > GetSearchResultsAsync(string searchQuery, CancellationToken cancellationToken, IProgress <double> progress = null)
        {
            progress?.Report(0);
            Logger?.LogInfo($"Searching for \"{searchQuery}\"...");

            var res = new SearchContainer <SearchBase>();

            try
            {
                res = await _client.SearchMultiAsync(searchQuery, cancellationToken : cancellationToken);
            }
            catch (Exception e)
            {
                Logger?.LogError($"An error occured while searching for \"{searchQuery}\".", e);
            }

            Logger?.LogInfo($"Search for \"{searchQuery}\" landed {res.Results.Count} results.");

            progress?.Report(0.5);

            var results = new List <SearchResult>();

            foreach (var searchBase in res.Results)
            {
                var searchResult = _tmdbConverter.Convert(searchBase);
                results.Add(searchResult);
            }

            progress?.Report(1);
            return(results);
        }
Example #28
0
        private static async Task FetchMovieExample(TMDbClient client)
        {
            string query = "10x10";

            // This example shows the fetching of a movie.
            // Say the user searches for "Thor" in order to find "Thor: The Dark World" or "Thor"
            SearchContainer <SearchMovie> results = await client.SearchMovieAsync(query);

            // The results is a list, currently on page 1 because we didn't specify any page.
            Console.WriteLine("Searched for movies: '" + query + "', found " + results.TotalResults + " results in " +
                              results.TotalPages + " pages");

            // Let's iterate the first few hits
            foreach (SearchMovie result in results.Results.Take(3))
            {
                // Print out each hit
                Console.WriteLine(result.Id + ": " + result.Title);
                Console.WriteLine("\t Original Title: " + result.OriginalTitle);
                Console.WriteLine("\t Release date  : " + result.ReleaseDate);
                Console.WriteLine("\t Popularity    : " + result.Popularity);
                Console.WriteLine("\t Vote Average  : " + result.VoteAverage);
                Console.WriteLine("\t Vote Count    : " + result.VoteCount);
                Console.WriteLine();
                Console.WriteLine("\t Backdrop Path : " + result.BackdropPath);
                Console.WriteLine("\t Poster Path   : " + result.PosterPath);

                Console.WriteLine();
            }

            Spacer();
        }
Example #29
0
        public void TestChangesMovies()
        {
            // Basic check
            SearchContainer <ChangesListItem> changesPage1 = _config.Client.GetChangesMovies();

            Assert.IsNotNull(changesPage1);
            Assert.IsTrue(changesPage1.Results.Count > 0);
            Assert.IsTrue(changesPage1.TotalResults > changesPage1.Results.Count);
            Assert.AreEqual(1, changesPage1.Page);

            // Page 2
            SearchContainer <ChangesListItem> changesPage2 = _config.Client.GetChangesMovies(2);

            Assert.IsNotNull(changesPage2);
            Assert.AreEqual(2, changesPage2.Page);

            // Check date range (max)
            DateTime higher = DateTime.UtcNow.AddDays(-7);
            SearchContainer <ChangesListItem> changesMaxDate = _config.Client.GetChangesMovies(endDate: higher);

            Assert.IsNotNull(changesMaxDate);
            Assert.AreEqual(1, changesMaxDate.Page);
            Assert.AreNotEqual(changesPage1.TotalResults, changesMaxDate.TotalResults);

            // Check date range (lower)
            DateTime lower = DateTime.UtcNow.AddDays(-6);       // Use 6 days to avoid clashes with the 'higher'
            SearchContainer <ChangesListItem> changesLowDate = _config.Client.GetChangesMovies(startDate: lower);

            Assert.IsNotNull(changesLowDate);
            Assert.AreEqual(1, changesLowDate.Page);
            Assert.AreNotEqual(changesPage1.TotalResults, changesLowDate.TotalResults);
        }
Example #30
0
        public void TestTvShowRecommendations()
        {
            // Ignore missing json
            IgnoreMissingJson("results[array] / media_type");

            SearchContainer <SearchTv> tvShow = Config.Client.GetTvShowRecommendationsAsync(1668).Result;

            Assert.NotNull(tvShow);
            Assert.NotNull(tvShow.Results);

            SearchTv item = tvShow.Results.SingleOrDefault(s => s.Id == 1100);

            Assert.NotNull(item);

            Assert.True(TestImagesHelpers.TestImagePath(item.BackdropPath), "item.BackdropPath was not a valid image path, was: " + item.BackdropPath);
            Assert.Equal(1100, item.Id);
            Assert.Equal("How I Met Your Mother", item.OriginalName);
            Assert.Equal(new DateTime(2005, 09, 19), item.FirstAirDate);
            Assert.True(TestImagesHelpers.TestImagePath(item.PosterPath), "item.PosterPath was not a valid image path, was: " + item.PosterPath);
            Assert.True(item.Popularity > 0);
            Assert.Equal("How I Met Your Mother", item.Name);
            Assert.True(item.VoteAverage > 0);
            Assert.True(item.VoteCount > 0);

            Assert.NotNull(item.OriginCountry);
            Assert.Equal(1, item.OriginCountry.Count);
            Assert.True(item.OriginCountry.Contains("US"));
        }
Example #31
0
        public void TestSearchTvShow()
        {
            TestHelpers.SearchPages(i => _config.Client.SearchTvShow("Breaking Bad", i).Result);

            SearchContainer <SearchTv> result = _config.Client.SearchTvShow("Breaking Bad").Result;

            Assert.IsTrue(result.Results.Any());
            SearchTv item = result.Results.SingleOrDefault(s => s.Id == 1396);

            Assert.IsNotNull(item);
            Assert.AreEqual(1396, item.Id);
            Assert.AreEqual("/eSzpy96DwBujGFj0xMbXBcGcfxX.jpg", item.BackdropPath);
            Assert.AreEqual(new DateTime(2008, 1, 19), item.FirstAirDate);
            Assert.AreEqual("Breaking Bad", item.Name);
            Assert.AreEqual("Breaking Bad", item.OriginalName);
            Assert.AreEqual("en", item.OriginalLanguage);
            // has been replaced
            // Assert.AreEqual("/4yMXf3DW6oCL0lVPZaZM2GypgwE.jpg", item.PosterPath);
            Assert.IsNotNull(item.PosterPath);
            Assert.AreEqual("Breaking Bad is an American crime drama television series created and produced by Vince Gilligan. Set and produced in Albuquerque, New Mexico, Breaking Bad is the story of Walter White, a struggling high school chemistry teacher who is diagnosed with inoperable lung cancer at the beginning of the series. He turns to a life of crime, producing and selling methamphetamine, in order to secure his family's financial future before he dies, teaming with his former student, Jesse Pinkman. Heavily serialized, the series is known for positioning its characters in seemingly inextricable corners and has been labeled a contemporary western by its creator.", item.Overview);
            Assert.IsTrue(item.Popularity > 0);
            Assert.IsTrue(item.VoteAverage > 0);
            Assert.IsTrue(item.VoteCount > 0);

            Assert.IsNotNull(item.GenreIds);
            Assert.AreEqual(1, item.GenreIds.Count);
            Assert.AreEqual(18, item.GenreIds[0]);

            Assert.IsNotNull(item.OriginCountry);
            Assert.AreEqual(1, item.OriginCountry.Count);
            Assert.AreEqual("US", item.OriginCountry[0]);
        }
Example #32
0
 private Movies ToMovies(SearchContainer<MovieResult> resultContainer)
 {
     return new Movies
            {
                TotalResults = resultContainer.TotalResults,
                Results = resultContainer.Results
                    .Select(ToMovie)
            };
 }
Example #33
0
 public SelectMovie(SearchContainer<SearchMovie> movies)
 {
     this.isMovie = true;
     this.movies = movies.Results;
     InitializeComponent();
     foreach(SearchMovie movie in movies.Results)
     {
         if (movie.ReleaseDate != null)
         {
             DateTime date = (DateTime)movie.ReleaseDate;
             listBox1.Items.Add(movie.Title + " " + date.Year);
         }
         else
         {
             listBox1.Items.Add(movie.Title + " Unknown Year");
         }
     }
 }