private List <Movie> GetMoviesFromResponse(ApiSearchResponse <MovieInfo> response) { List <Movie> movies; if (response.Results != null) { movies = response.Results.Select(x => new Movie { Title = x.Title, Year = x.ReleaseDate.Year, ImageRemote = x.PosterPath, BackdropRemote = x.BackdropPath, Description = x.Overview, Id = x.Id, Genres = x.Genres.Select(y => y.Name).ToList(), AverageVote = x.VoteAverage }).ToList(); foreach (Movie m in movies) { m.Actors = new List <string>();; m.Runtime = 0; } return(movies); } else { return(new List <Movie>()); } }
public MovieListController(ApiSearchResponse <MovieInfo> response, ImageDownloader downloader, IApiMovieRequest movieApi, MovieCredit[] credits) { this._response = response; this._downloader = downloader; this._movieApi = movieApi; this._credits = credits; }
private async Task GetTopRatedMovies() { var movieApi = MovieDbFactory.Create <IApiMovieRequest>().Value; ApiSearchResponse <MovieInfo> responseMovieInfos = await movieApi.GetTopRatedAsync(); await _movieHelper.GetMovies(responseMovieInfos); _topMoviesList = _movieHelper.MoviesList; // Set image path StorageClient client = new StorageClient(); ImageDownloader downloader = new ImageDownloader(client); foreach (Movie m in _movieHelper.MoviesList) { if (m.ImagePath != null) { string localPath = downloader.LocalPathForFilename(m.ImagePath); // if localPath does not exist then download image if (!File.Exists(localPath)) { await downloader.DownloadImage(m.ImagePath, localPath, new CancellationToken()); } m.setImagePath(localPath); } else { m.setImagePath(""); } } }
public async Task <List <Movie> > getListOfTopRatedMovies() { List <Movie> responseMovieList = new List <Movie>(); ApiSearchResponse <MovieInfo> response = await _movieApi.GetTopRatedAsync(1); foreach (MovieInfo info in response.Results) { ApiQueryResponse <MovieCredit> cast = await _movieApi.GetCreditsAsync(info.Id); List <string> actors = new List <string>(); int number = 3; if (cast.Item.CastMembers.Count < 3) { number = cast.Item.CastMembers.Count; } for (int i = 0; i < number; i++) { actors.Add(cast.Item.CastMembers[i].Name); } responseMovieList.Add(new Movie() { Id = info.Id, Title = info.Title, Year = info.ReleaseDate, Actors = actors, ImageUrl = info.PosterPath }); } return(responseMovieList); }
private Movie GetMovieFromResponse(ApiSearchResponse <MovieInfo> response) { Movie movie; if (response.Results != null) { movie = response.Results.Select(x => new Movie { Title = x.Title, Year = x.ReleaseDate.Year, ImageRemote = x.PosterPath, BackdropRemote = x.BackdropPath, Description = x.Overview, Id = x.Id, Genres = x.Genres.Select(y => y.Name).ToList(), AverageVote = x.VoteAverage }).FirstOrDefault(); movie.Actors = new List <string>(); movie.Runtime = 0; return(movie); } else { return(new Movie()); } }
public async Task <List <Movie> > GetMoviesByTitle(string title) { ApiSearchResponse <MovieInfo> response = await _movieDbApi.SearchByTitleAsync(title); _movies = new List <Movie>(); if (response.Results == null) { return(_movies); } foreach (MovieInfo movie in response.Results) { _movies.Add(new Movie { Id = movie.Id, Title = movie.Title, ReleaseDate = movie.ReleaseDate, ReleaseYear = movie.ReleaseDate.Year, RemoteImageUrl = movie.PosterPath, LocalImageUrl = "", Actors = new List <String>(), Rating = movie.VoteAverage }); } return(_movies); }
public override async void ViewDidLoad() { base.ViewDidLoad(); this.View.BackgroundColor = UIColor.FromRGB(0.714f, 0.98f, 1); this.Title = "Top Rated Movies"; var spinner = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.Gray); spinner.Frame = new CGRect(20, 10, this.View.Bounds.Width - 2 * 20, 50); this.View.AddSubview(spinner); spinner.StartAnimating(); var movieApi = MovieDbFactory.Create <DM.MovieApi.MovieDb.Movies.IApiMovieRequest>().Value; ApiSearchResponse <MovieInfo> res = await movieApi.GetTopRatedAsync(); foreach (var i in res.Results) { Movie movie = new Movie(); await setMovieInfo.setInfo(i, movieApi, movie); this._movieList.Add(movie); } this.TableView.Source = new MovieListSource(this._movieList, OnSelectedMovie); spinner.StopAnimating(); this.TableView.ReloadData(); }
public async Task <List <MovieListViewModel> > GetTopRatedMovies() { ApiSearchResponse <MovieInfo> response = await _movieDbApi.GetTopRatedAsync(); List <MovieListViewModel> movies = new List <MovieListViewModel>(); if (response.Results == null) { return(movies); } foreach (MovieInfo movie in response.Results) { movies.Add(new MovieListViewModel { Id = movie.Id, Title = movie.Title, ReleaseDate = movie.ReleaseDate, ReleaseYear = movie.ReleaseDate.Year, RemoteImageUrl = movie.PosterPath, LocalImageUrl = "", Actors = new List <String>(), Rating = movie.VoteAverage }); } return(movies); }
public async Task <List <MovieDetails> > GetMovieByTitle(string title) { ApiSearchResponse <MovieInfo> response = await _api.SearchByTitleAsync(title); if (_movies == null) { _movies.Clear(); } else { _movies = new List <MovieDetails>(); } foreach (MovieInfo info in response.Results) { _movies.Add(new MovieDetails { id = info.Id, title = info.Title, imageUrl = info.PosterPath, releaseDate = info.ReleaseDate, voteAverage = info.VoteAverage, voteCount = info.VoteCount, posterFilePath = "", runtime = "", genres = new List <String>(), actors = new List <String>() }); } return(_movies); }
public async Task SearchByNameAsync_Milla_Jovovich_Returns_SingleResult_WithExpectedValues() { const string millaJovovich = "Milla Jovovich"; ApiSearchResponse <PersonInfo> response = await _api.SearchByNameAsync(millaJovovich); ApiResponseUtil.AssertErrorIsNull(response); Assert.AreEqual(1, response.TotalResults); Assert.AreEqual(1, response.Results.Count); PersonInfo person = response.Results.Single(); Assert.AreEqual(PersonId_MillaJovovich, person.Id); Assert.AreEqual(millaJovovich, person.Name); Assert.IsFalse(person.IsAdultFilmStar); Assert.AreEqual(3, person.KnownFor.Count); string[] roles = { "The Fifth Element", "Resident Evil: Retribution", "Resident Evil", }; foreach (string role in roles) { PersonInfoRole info = person.KnownFor.SingleOrDefault(x => x.MovieTitle == role); Assert.IsNotNull(info); Assert.AreEqual(MediaType.Movie, info.MediaType); } }
public override void ViewDidLoad() { base.ViewDidLoad(); this.Title = "Movie search"; this.View.BackgroundColor = UIColor.FromRGB(245, 244, 244); this._yCoord = StartY; var prompt = this.CreatePrompt(); var movieField = this.CreateMovieField(); var getMoviesButton = this.CreateButton("Get movies"); getMoviesButton.TouchUpInside += async(sender, args) => { movieField.ResignFirstResponder(); getMoviesButton.Enabled = false; activitySpinner.Frame = new CGRect(HorizontalMargin, this._yCoord, this.View.Bounds.Width - 2 * HorizontalMargin, 50); activitySpinner.AutoresizingMask = UIViewAutoresizing.All; this.View.AddSubview(activitySpinner); activitySpinner.StartAnimating(); // API call to get searched movies var movieApi = MovieDbFactory.Create <IApiMovieRequest>().Value; ApiSearchResponse <MovieInfo> responseMovieInfos = await movieApi.SearchByTitleAsync(movieField.Text == null? "" : movieField.Text); await _movieHelper.GetMovies(responseMovieInfos); // set imgpath StorageClient client = new StorageClient(); ImageDownloader downloader = new ImageDownloader(client); foreach (Movie m in _movieHelper.MoviesList) { if (m.ImagePath != null) { string localPath = downloader.LocalPathForFilename(m.ImagePath); // if localPath does not exist then download image if (!File.Exists(localPath)) { await downloader.DownloadImage(m.ImagePath, localPath, new CancellationToken()); } m.setImagePath(localPath); } else { m.setImagePath(""); } } this.NavigationController.PushViewController(new MovieListController(_movieHelper.MoviesList), true); getMoviesButton.Enabled = true; movieField.Text = null; }; this.View.AddSubview(prompt); this.View.AddSubview(movieField); this.View.AddSubview(getMoviesButton); }
/// <summary> /// Does an online search of film name entered into the Search Box /// Fills the data grid view with all films in Film object format /// </summary> private async void searchByName() { var movieAPI = MovieDbFactory.Create <IApiMovieRequest>().Value; int pageNumber = 1; int totalPages; int numResults = 0; ApiSearchResponse <MovieInfo> response = await movieAPI.SearchByTitleAsync(searchBox.Text, pageNumber); bs.Clear(); foreach (MovieInfo info in response.Results) { Film film = new Film(); film.Name = info.Title; film.Description = info.Overview; film.tmdbID = info.Id; film.tmdbImgUrl = info.PosterPath; film.ReleaseDate = new DateTime(info.ReleaseDate.Year, info.ReleaseDate.Month, info.ReleaseDate.Day); bs.Add(film); dgvOFilms.DataSource = bs; numResults++; numResultsLbl.Text = "Page: " + pageNumber.ToString(); } totalPages = response.TotalPages; if (numResults == 0) { MessageBox.Show("No results found"); } }
private UIButton NavigationButton(UITextField nameField, ApiSearchResponse <MovieInfo> response, ImageDownloader downloader, UIActivityIndicatorView activitySpinner) { var navigateButton = UIButton.FromType(UIButtonType.RoundedRect); navigateButton.Frame = new CoreGraphics.CGRect(margin, spaceBetween * 3, this.View.Bounds.Width - (margin * 2), 50); navigateButton.SetTitle("See Movie list", UIControlState.Normal); navigateButton.TouchUpInside += async(sender, args) => { activitySpinner.StartAnimating(); nameField.ResignFirstResponder(); response = await _movieApi.SearchByTitleAsync(nameField.Text); //Nær í allar upplýsingar tengdum myndunu MovieCredit[] credits = new MovieCredit[response.Results.Count]; for (int i = 0; i < response.Results.Count; i++) { var credit = await _movieApi.GetCreditsAsync(response.Results[i].Id, "en"); credits[i] = credit.Item; } var task = downloader.DownloadImagesFromResponces(response); //Download'ar öllum pósterum await task; activitySpinner.StopAnimating(); this.NavigationController.PushViewController(new MovieListController(response, downloader, _movieApi, credits), true); }; return(navigateButton); }
private async Task <NeoModels.TVShow> apiSeason(string searchQuery, int season) { ApiSearchResponse <TVShowInfo> response = await seasonAPI.SearchByNameAsync(searchQuery); TVShowInfo info = response.Results[0]; ApiQueryResponse <DM.MovieApi.MovieDb.TV.TVShow> metadata = await seasonAPI.FindByIdAsync(info.Id); NeoModels.TVShow tvshow = new NeoModels.TVShow(metadata.Item, season); String plot = tvshow.Overview; String poster = "http://image.tmdb.org/t/p/w342/" + tvshow.Seasons[0].Path; string titleWhole = tvshow.Name + " Season " + season; StorageFolder folder = ApplicationData.Current.LocalFolder; string appPath = folder.Path; appPath += "\\"; appPath += titleWhole; appPath += ".jpg"; await downloadImage(new Uri(poster), appPath); tvshow.Seasons[0].Path = appPath; tvshow.PosterPath = appPath; if (seasonList.Instance.existsInList(tvshow)) { already = true; addSeason = tvshow.Seasons[0]; } return(tvshow); }
private async Task <NeoModels.Movie> ApiMovieAsync(string searchQuery) { ApiSearchResponse <MovieInfo> response = await movieAPI.SearchByTitleAsync(searchQuery); MovieInfo info = response.Results[0]; ApiQueryResponse <DM.MovieApi.MovieDb.Movies.Movie> movieinfo = await movieAPI.FindByIdAsync(info.Id); ApiQueryResponse <DM.MovieApi.MovieDb.Movies.MovieCredit> credits = await movieAPI.GetCreditsAsync(info.Id); NeoModels.Movie movie = new NeoModels.Movie(movieinfo.Item, credits.Item); movie.Title = movie.Title.Replace(':', '-'); String poster = "http://image.tmdb.org/t/p/w342/" + movie.Poster; StorageFolder folder = ApplicationData.Current.LocalFolder; string appPath = folder.Path; appPath += "\\"; appPath += movie.Title; appPath += ".jpg"; await downloadImage(new Uri(poster), appPath); movie.Poster = appPath; return(movie); }
public async Task <List <Movie> > getListOfMoviesMatchingSearch(string nameField) { List <Movie> responseMovieList = new List <Movie>(); if (nameField.Length == 0) { return(responseMovieList); } else { ApiSearchResponse <MovieInfo> response = await _movieApi.SearchByTitleAsync(nameField); var res = response?.Results; if (res != null) { foreach (MovieInfo info in response.Results) { responseMovieList.Add(new Movie("") { Id = info.Id, Title = $"{info.Title} ({info.ReleaseDate:yyyy})", Actors = "", ImageUrl = info.PosterPath, Overview = info.Overview }); } } } return(responseMovieList); }
public async Task GetMostPopularMovies(List <Movie> movieList) { ApiSearchResponse <MovieInfo> response = await _movieDbApi.GetPopularAsync(); if (response.Results == null) { return; } foreach (MovieInfo movie in response.Results) { movieList.Add(new Movie { Id = movie.Id, Title = movie.Title, ReleaseDate = movie.ReleaseDate, ReleaseYear = movie.ReleaseDate.Year, RemoteImageUrl = movie.PosterPath, LocalImageUrl = "", Actors = new List <String>(), Rating = movie.VoteAverage }); } return; }
public async Task <ApiSearchResponse <MovieInfo> > SearchByTitleAsync(string query, int pageNumber = 1, string language = "en") { var param = new Dictionary <string, string> { { "query", query }, { "include_adult", "false" }, { "language", language }, }; const string command = "search/movie"; ApiSearchResponse <MovieInfo> response = await base.SearchAsync <MovieInfo>(command, pageNumber, param); //var config = await GetConfiguration(_settings); //var baseImageUrl = string.Format("{0}{1}", config.Images.SecureRootUrl, config.Images.Posters.Last()); //response.Results.All(movie => { movie.PosterPath = baseImageUrl + movie.PosterPath; return true; }); if (response.Error != null) { return(response); } response.Results.PopulateGenres(_genreApi); return(response); }
public ArrayList Query(string sQuery) { // as the factory returns a Lazy<T> instance, simply grab the Value out of the Lazy<T> // and assign to a local variable. var movieApi = MovieDbFactory.Create <IApiMovieRequest>().Value; //ApiSearchResponse<MovieInfo> response = Task.Run(movieApi.SearchByTitleAsync("Star Trek")).result ; //apiSearchResponse = movieApi.SearchByTitleAsync(sQuery).Result; //Makes async sync... //apiSearchResponse = movieApi.SearchByTitleAsync(sQuery).GetAwaiter().GetResult(); try { apiSearchResponse = Task.Run(() => { return(movieApi.SearchByTitleAsync(sQuery)); }).Result; } catch { return(new ArrayList()); } //Console.WriteLine("Movieimage: https://image.tmdb.org/t/p/original/" + apiSearchResponse.Results[0].PosterPath); ArrayList pArray = new ArrayList(); foreach (MovieInfo pMovie in apiSearchResponse.Results) { DateTime dateTime = pMovie.ReleaseDate; pArray.Add(pMovie.OriginalTitle + " (" + dateTime.Year.ToString() + ")"); } return(pArray); }
public async Task SearchByTitleAsync_RunLolaRun_Returns_SingleResult_WithExpectedValues() { const string runLolaRun = "Run Lola Run"; ApiSearchResponse <MovieInfo> response = await _api.SearchByTitleAsync(runLolaRun); AssertRunLolaRun(response, runLolaRun); }
public async Task GetUpcomingAsync_Returns_ValidResults() { ApiSearchResponse <Movie> response = await _api.GetUpcomingAsync(); ApiResponseUtil.AssertErrorIsNull(response); ApiResponseUtil.AssertMovieStructure(response.Results); }
public MovieListDataSource(ApiSearchResponse <MovieInfo> response, Action <int> onSelectedPerson, ImageDownloader downloader, IApiMovieRequest movieApi, MovieCredit[] credits) { this._response = response; this._onSelectedPerson = onSelectedPerson; this._downloader = downloader; this._movieApi = movieApi; this._credits = credits; }
public async Task SearchByNameAsync_The_Nanny_Returns_ExpectedResults() { const string theNanny = "The Nanny"; ApiSearchResponse <TVShowInfo> response = await _api.SearchByNameAsync(theNanny); AssertTheNanny(response, theNanny); }
protected override void OnAppearing() { popular = _database.getPopular(); if (popular != null) { updateData(); } base.OnAppearing(); }
public async Task SearchByTitleAsync_RunLolaRun_Returns_SingleResult_WithExpectedValues_InGerman() { const string runLolaRun = "Run Lola Run"; const string expectedTitle = "Lola rennt"; ApiSearchResponse <MovieInfo> response = await _api.SearchByTitleAsync(runLolaRun, 1, "de"); AssertRunLolaRun(response, expectedTitle); }
public async Task <List <MovieDetails> > GetTopRatedMovies() { _movies.Clear(); ApiSearchResponse <MovieInfo> response = await _movieApi.GetTopRatedAsync(); _movies = await GetMovies(response.Results); return(_movies); }
protected override void OnAppearing() { topRated = _database.getTopRated(); if (topRated != null) { updateData(); } base.OnAppearing(); }
public async Task GetTopRatedAsync_Returns_ValidResult() { ApiSearchResponse <TVShowInfo> response = await _api.GetTopRatedAsync(); ApiResponseUtil.AssertErrorIsNull(response); IReadOnlyList <TVShowInfo> results = response.Results; ApiResponseUtil.AssertTVShowInformationStructure(results); }
public async Task SearchByNameAsync_The_Nanny_Returns_ExpectedResults_InGerman() { const string theNanny = "Die Nanny"; ApiSearchResponse <TVShowInfo> response = await _api.SearchByNameAsync(theNanny, language : "de"); ApiResponseUtil.AssertErrorIsNull(response); AssertTheNanny(response, theNanny); }
public async Task GetPopularAsync_Returns_ValidResults() { ApiSearchResponse <MovieInfo> response = await _api.GetPopularAsync(); ApiResponseUtil.AssertErrorIsNull(response); IReadOnlyList <MovieInfo> results = response.Results; ApiResponseUtil.AssertMovieInformationStructure(results); }
private void AssertRunLolaRun( ApiSearchResponse<MovieInfo> response, string expectedTitle ) { Assert.AreEqual( 1, response.TotalResults ); Assert.AreEqual( 1, response.Results.Count ); MovieInfo movie = response.Results.Single(); Assert.AreEqual( 104, movie.Id ); Assert.AreEqual( expectedTitle, movie.Title ); Assert.AreEqual( new DateTime( 1998, 08, 20 ), movie.ReleaseDate ); var expectedGenres = new List<Genre> { GenreFactory.Action(), GenreFactory.Drama(), GenreFactory.Thriller(), }; CollectionAssert.AreEquivalent( expectedGenres, movie.Genres.ToList() ); }
private void AssertTheNanny( ApiSearchResponse<TVShowInfo> response, string theNanny ) { const int theNannyId = 2352; const string us = "US"; const string lang = "en"; var firstAirDate = new DateTime( 1993, 11, 03 ); Assert.IsTrue( response.TotalResults > 0 ); Assert.IsTrue( response.Results.Count > 0 ); TVShowInfo show = response.Results.Single( x => x.Id == theNannyId ); Assert.AreEqual( theNanny, show.Name ); Assert.AreEqual( 1, show.OriginCountry.Count ); string country = show.OriginCountry.Single(); Assert.AreEqual( us, country ); Assert.AreEqual( lang, show.OriginalLanguage ); Assert.AreEqual( firstAirDate.Date, show.FirstAirDate.Date ); }