/// <summary> /// Translate movie informations (title, description, ...) /// </summary> /// <param name="movieToTranslate">Movie to translate</param> /// <param name="ct">Used to cancel translation</param> /// <returns>Task</returns> public async Task TranslateMovieShortAsync(MovieShort movieToTranslate, CancellationToken ct) { var watch = Stopwatch.StartNew(); try { await Task.Run(() => { var movie = TmdbClient.GetMovie(movieToTranslate.ImdbCode, MovieMethods.Credits); movieToTranslate.Title = movie?.Title; movieToTranslate.Genres = movie?.Genres?.Select(a => a.Name).ToList(); }, ct); } catch (Exception exception) when(exception is TaskCanceledException) { Logger.Debug( "TranslateMovieShortAsync cancelled."); } catch (Exception exception) { Logger.Error( $"TranslateMovieShortAsync: {exception.Message}"); throw; } finally { watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Logger.Debug( $"TranslateMovieShortAsync ({movieToTranslate.ImdbCode}) in {elapsedMs} milliseconds."); } }
public async Task <List <MovieShort> > GetRecommendedMovies(Guid userId) { var movies = await _dataContext.Users_Movies.Where( uM => uM.UserId == userId && uM.Category.Equals("Favorites")).ToListAsync(); var genreCount = await GetGenresCount(movies); var topGenre = genreCount.OrderByDescending(x => x.Value).FirstOrDefault(); var genreId = await GetGenreIdByName(topGenre.Key); var movieIdsFromFavoriteGenre = await _dataContext.Movies_Genres.Where(mG => mG.GenreId == genreId).ToListAsync(); var moviesFromFavoriteGenre = new List <Movie>(); foreach (var moviesGenre in movieIdsFromFavoriteGenre) { moviesFromFavoriteGenre.Add(await GetMovieById(moviesGenre.MovieId)); } var distinctMovieIds = await GetDistinctMovieIdsForUser(userId); foreach (var distinctMovieId in distinctMovieIds) { moviesFromFavoriteGenre.Remove(moviesFromFavoriteGenre.SingleOrDefault(m => m.Id == distinctMovieId)); } var moviesRange = moviesFromFavoriteGenre.Take(15).ToList(); return(MovieShort.ShortenRange(moviesRange)); }
public void GetHashCode_DifferentMovies_ReturnsDifferentHashCode() { var fixture = new Fixture(); var id1 = fixture.Create <int>(); var dateUploadedUnix1 = fixture.Create <int>(); var id2 = fixture.Create <int>(); var dateUploadedUnix2 = fixture.Create <int>(); var movie1 = new MovieShort { Id = id1, DateUploadedUnix = dateUploadedUnix1 }; var movie2 = new MovieShort { Id = id2, DateUploadedUnix = dateUploadedUnix2 }; Assert.AreNotEqual( _comparer.GetHashCode(movie1), _comparer.GetHashCode(movie2)); }
public void Equals_DifferentMovies_ReturnsFalse() { var fixture = new Fixture(); var id1 = fixture.Create <int>(); var dateUploadedUnix1 = fixture.Create <int>(); var id2 = fixture.Create <int>(); var dateUploadedUnix2 = fixture.Create <int>(); var movie1 = new MovieShort { Id = id1, DateUploadedUnix = dateUploadedUnix1 }; var movie2 = new MovieShort { Id = id2, DateUploadedUnix = dateUploadedUnix2 }; Assert.AreEqual( _comparer.Equals(movie1, movie2), false); Assert.AreEqual( _comparer.Equals(movie1, null), false); Assert.AreEqual( _comparer.Equals(movie2, null), false); }
/// <summary> /// Translate movie informations (title, description, ...) /// </summary> /// <param name="movieToTranslate">Movie to translate</param> /// <returns>Task</returns> public async Task TranslateMovieShortAsync(MovieShort movieToTranslate) { var watch = Stopwatch.StartNew(); await Task.Run(() => { try { var movie = TmdbClient.GetMovie(movieToTranslate.ImdbCode, MovieMethods.Credits); movieToTranslate.Title = movie.Title; movieToTranslate.Genres = movie.Genres.Select(a => a.Name).ToList(); } catch (Exception ex) when(ex is SocketException || ex is WebException) { Messenger.Default.Send(new ManageExceptionMessage(ex)); } }); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Logger.Debug( $"TranslateMovieShort ({movieToTranslate.ImdbCode}) in {elapsedMs} milliseconds."); }
public PredictionResultViewModel(MovieShort movie, IPageService pageService) { _pageService = pageService; GoHomePageCommand = new Command(async() => await GoToHomePage()); Pageinitialization(movie); }
/// <summary> /// Gets all the movies and orders them by descending order by the ratings of the movies. /// </summary> /// <returns>Instance of class <see cref="MovieShort"/> with information about the movies.</returns> public async Task <List <MovieShort> > GetTopRatedMovies() { var movies = await _dataContext.Movies .OrderByDescending(m => double.Parse(m.Rating)) .Take(50) .OrderBy(a => Guid.NewGuid()) .Take(15).ToListAsync(); return(MovieShort.ShortenRange(movies)); }
public MovieInfoViewModel(MovieShort movieIntro) { FilmInfo = movieIntro; var movie = Mapper.Map <HistoryPreview>(movieIntro); App.Database.SaveItem(movie); GetMovieCredits(FilmInfo.Id); }
public void Startup() { _movieShort = new MovieShort { ImdbID = "1", Title = "air", Year = "2000", Type = "movie", Poster = "poster" }; }
public async Task <IObservable <MovieShort> > GetAllMovies(MovieShort movie) { var firebase = new FirebaseClient(LinksContainer.PredixFirebase); var uniqueUserToken = Application.Current.Properties[ApplicationProperties.UserId].ToString(); return(await Task.Run(() => { var history = firebase.Child(uniqueUserToken).AsObservable <MovieShort>(); return (IObservable <MovieShort>)history; })); }
private async Task ItemSelected(MovieShort movie) { try { await _pageService.PushAsync(new PopupLoading()); await _pageService.PushAsync(new PredictionResult(movie)); } finally { SelectedItem = null; await _pageService.PopAsync(); } }
private async Task ItemSelected(MovieShort movie) { try { await _pageService.PushAsync(new PopupLoading()); await _pageService.PushAsync(new MovieInfo(movie)); } catch (Exception ex) { await _pageService.DisplayAlert(AppResources.WarningTitle, ex.Message); } finally { SelectedItem = null; await _pageService.PopAsync(); } }
public void GetHashCode_SameMovie_ReturnsSameHashCode() { var fixture = new Fixture(); var movie1 = new MovieShort(); var movie2 = new MovieShort(); var id = fixture.Create <int>(); var dateUploadedUnix = fixture.Create <int>(); movie1.Id = id; movie2.Id = id; movie1.DateUploadedUnix = dateUploadedUnix; movie2.DateUploadedUnix = dateUploadedUnix; Assert.AreEqual( _comparer.GetHashCode(movie1), _comparer.GetHashCode(movie1)); Assert.AreEqual( _comparer.GetHashCode(movie1), _comparer.GetHashCode(movie2)); }
public void Equals_SameMovie_ReturnsTrue() { var fixture = new Fixture(); var movie1 = new MovieShort(); var movie2 = new MovieShort(); var id = fixture.Create <int>(); var dateUploadedUnix = fixture.Create <int>(); movie1.Id = id; movie2.Id = id; movie1.DateUploadedUnix = dateUploadedUnix; movie2.DateUploadedUnix = dateUploadedUnix; Assert.AreEqual( _comparer.Equals(movie1, movie1), true); Assert.AreEqual( _comparer.Equals(movie1, movie2), true); }
private async Task <double> Prediction(MovieShort movie) { var credits = new CastAndCrew(movie.Id); var castList = credits.GetCredits(); var countToTake = castList.Cast.Count > _maxCounter ? _maxCounter : castList.Cast.Count; var rateAvg = 0D; return(await Task.Run(() => { foreach (var cast in castList.Cast.Take(countToTake)) { var person = new ProfileInfo(cast.Id); var resume = person.GetHistory(); rateAvg += resume.Cast.Select(i => i.VoteAverage).Average(); } rateAvg = rateAvg / countToTake; return Math.Round(rateAvg, 2); })); }
/// <summary> /// Load the requested movie /// </summary> /// <param name="movie">The movie to load</param> private async Task LoadMovieAsync(MovieShort movie) { var watch = Stopwatch.StartNew(); Messenger.Default.Send(new LoadMovieMessage()); IsMovieLoading = true; Movie = await _movieService.GetMovieFullDetailsAsync(movie, _cancellationLoadingToken.Token); IsMovieLoading = false; await _movieService.DownloadPosterImageAsync(Movie, _cancellationLoadingToken); await _movieService.DownloadCastImageAsync(Movie, _cancellationLoadingToken); await _movieService.DownloadBackgroundImageAsync(Movie, _cancellationLoadingToken); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Logger.Debug($"LoadMovieAsync ({movie.ImdbCode}) in {elapsedMs} milliseconds."); }
/// <summary> /// Get the requested movie /// </summary> /// <param name="movie">The movie to load</param> private async Task LoadMovieAsync(MovieShort movie) { Messenger.Default.Send(new LoadMovieMessage(movie)); IsMovieLoading = true; try { Movie = await MovieService.GetMovieFullDetailsAsync(movie); IsMovieLoading = false; await MovieService.DownloadPosterImageAsync(Movie); await MovieService.DownloadDirectorImageAsync(Movie); await MovieService.DownloadActorImageAsync(Movie); await MovieService.DownloadBackgroundImageAsync(Movie); } catch (Exception ex) when(ex is SocketException || ex is WebException) { Messenger.Default.Send(new ManageExceptionMessage(ex)); } }
/// <summary> /// Get movie by id /// </summary> /// <param name="id">Movie's id</param> /// <returns>Movie searched by movie id</returns> public async Task <MovieShort> GetMovieById(int id) { var watch = Stopwatch.StartNew(); var restClient = new RestClient(Constants.YtsApiEndpoint); var request = new RestRequest("/{segment}", Method.GET); request.AddUrlSegment("segment", "movie_details.json"); request.AddParameter("movie_id", id); request.AddParameter("with_cast", true); request.AddParameter("with_images", true); var response = await restClient.ExecuteGetTaskAsync(request); if (response.ErrorException != null) { Messenger.Default.Send(new ManageExceptionMessage(new WebException(response.ErrorException.Message))); } var movie = new MovieShort(); await Task.Run(() => { var wrapper = JsonConvert.DeserializeObject <WrapperMovieFullDeserialized>(response.Content); if (wrapper == null) { return; } var rating = Convert.ToDouble(movie.Rating, CultureInfo.InvariantCulture); rating /= 2.0; movie = new MovieShort { ApiVersion = wrapper.Meta.ApiVersion, DateUploaded = wrapper.Movie.DateUploaded, DateUploadedUnix = wrapper.Movie.DateUploadedUnix, ExecutionTime = wrapper.Meta.ExecutionTime, Genres = wrapper.Movie.Genres, Id = wrapper.Movie.Id, ImdbCode = wrapper.Movie.ImdbCode, IsFavorite = false, HasBeenSeen = false, Language = wrapper.Movie.Language, MediumCoverImage = wrapper.Movie.Images.MediumCoverImage, CoverImagePath = string.Empty, MpaRating = wrapper.Movie.MpaRating, RatingValue = rating, Runtime = wrapper.Movie.Runtime, ServerTime = wrapper.Meta.ServerTime, ServerTimezone = wrapper.Meta.ServerTimezone, SmallCoverImage = wrapper.Movie.Images.SmallCoverImage, State = wrapper.Status, Title = wrapper.Movie.TitleLong, TitleLong = wrapper.Movie.TitleLong, Torrents = wrapper.Movie.Torrents, Url = wrapper.Movie.Url, Year = wrapper.Movie.Year }; }); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Logger.Debug( $"GetMovieById ({id}) in {elapsedMs} milliseconds."); return(movie); }
/// <summary> /// Constructor /// </summary> /// <param name="movie">The movie</param> public ChangeFavoriteMovieMessage(MovieShort movie) { Movie = movie; }
public MovieInfoViewModel(MovieShort movieIntro, IPageService pageService) : this(movieIntro) { _pageService = pageService; }
public MovieInfo(MovieShort movieIntro) : this() { BindingContext = new MovieInfoViewModel(movieIntro, new PageService()); }
/// <summary> /// Get TMDb movie informations /// </summary> /// <param name="movieToLoad">Movie to load</param> /// <param name="ct">Used to cancel loading</param> /// <returns>Movie's full details</returns> public async Task <MovieFull> GetMovieFullDetailsAsync(MovieShort movieToLoad, CancellationToken ct) { var watch = Stopwatch.StartNew(); var movie = new MovieFull(); var restClient = new RestClient(Constants.YtsApiEndpoint); var request = new RestRequest("/{segment}", Method.GET); request.AddUrlSegment("segment", "movie_details.json"); request.AddParameter("movie_id", movieToLoad.Id); request.AddParameter("with_images", true); request.AddParameter("with_cast", true); try { var response = await restClient.ExecuteGetTaskAsync <WrapperMovieFull>(request, ct); if (response.ErrorException != null) { throw response.ErrorException; } await Task.Run(() => { var tmdbInfos = TmdbClient.GetMovie(response.Data.Movie.ImdbCode, MovieMethods.Credits); movie = new MovieFull { Id = response.Data.Movie.Id, Actors = response.Data.Movie.Actors, BackgroundImagePath = string.Empty, DateUploaded = response.Data.Movie.DateUploaded, DateUploadedUnix = response.Data.Movie.DateUploadedUnix, DescriptionFull = tmdbInfos.Overview, DescriptionIntro = response.Data.Movie.DescriptionIntro, Directors = response.Data.Movie.Directors, DownloadCount = response.Data.Movie.DownloadCount, FullHdAvailable = response.Data.Movie.Torrents.Any(torrent => torrent.Quality == "1080p"), Genres = tmdbInfos.Genres.Select(a => a.Name).ToList(), Images = response.Data.Movie.Images, ImdbCode = response.Data.Movie.ImdbCode, Language = response.Data.Movie.Language, LikeCount = response.Data.Movie.LikeCount, MpaRating = response.Data.Movie.MpaRating, PosterImagePath = string.Empty, RatingValue = response.Data.Movie.Rating, RtAudienceRating = response.Data.Movie.RtAudienceRating, RtAudienceScore = response.Data.Movie.RtAudienceScore, RtCriticsRating = response.Data.Movie.RtCriticsRating, RtCrtiticsScore = response.Data.Movie.RtCrtiticsScore, Runtime = response.Data.Movie.Runtime, Title = tmdbInfos.Title, TitleLong = response.Data.Movie.TitleLong, Torrents = response.Data.Movie.Torrents, Url = response.Data.Movie.Url, WatchInFullHdQuality = false, Year = response.Data.Movie.Year, YtTrailerCode = response.Data.Movie.YtTrailerCode }; }, ct); } catch (Exception exception) when(exception is TaskCanceledException) { Logger.Debug( "GetMovieFullDetailsAsync cancelled."); } catch (Exception exception) { Logger.Error( $"GetMovieFullDetailsAsync: {exception.Message}"); throw; } finally { watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Logger.Debug( $"GetMovieFullDetailsAsync ({movie.ImdbCode}) in {elapsedMs} milliseconds."); } return(movie); }
public void Pageinitialization(MovieShort movie) { Title = movie.Title; Task.Run(async() => { PredictionRate = await Prediction(movie); }).Wait(); }
/// <summary> /// Constructor /// </summary> /// <param name="movie">Movie</param> public LoadMovieMessage(MovieShort movie) { Movie = movie; }
/// <summary> /// Get TMDb movie informations /// </summary> /// <param name="movieToLoad">Movie to load</param> /// <returns>Movie's full details</returns> public async Task <MovieFull> GetMovieFullDetailsAsync(MovieShort movieToLoad) { var watch = Stopwatch.StartNew(); var restClient = new RestClient(Constants.YtsApiEndpoint); var request = new RestRequest("/{segment}", Method.GET); request.AddUrlSegment("segment", "movie_details.json"); request.AddParameter("movie_id", movieToLoad.Id); request.AddParameter("with_images", true); request.AddParameter("with_cast", true); var response = await restClient.ExecuteGetTaskAsync(request); if (response.ErrorException != null) { Messenger.Default.Send(new ManageExceptionMessage(new WebException(response.ErrorException.Message))); } var movie = new MovieFull(); await Task.Run(() => { var wrapper = JsonConvert.DeserializeObject <WrapperMovieFullDeserialized>(response.Content); if (wrapper == null) { return; } var tmdbInfos = TmdbClient.GetMovie(wrapper.Movie.ImdbCode, MovieMethods.Credits); var rating = Convert.ToDouble(wrapper.Movie.Rating, CultureInfo.InvariantCulture); rating /= 2.0; movie = new MovieFull { Id = wrapper.Movie.Id, Actors = wrapper.Movie.Actors, BackgroundImagePath = string.Empty, DateUploaded = wrapper.Movie.DateUploaded, DateUploadedUnix = wrapper.Movie.DateUploadedUnix, DescriptionFull = tmdbInfos.Overview, DescriptionIntro = wrapper.Movie.DescriptionIntro, Directors = wrapper.Movie.Directors, DownloadCount = wrapper.Movie.DownloadCount, FullHdAvailable = wrapper.Movie.Torrents.Any(torrent => torrent.Quality == "1080p"), Genres = tmdbInfos.Genres.Select(a => a.Name).ToList(), Images = wrapper.Movie.Images, ImdbCode = wrapper.Movie.ImdbCode, Language = wrapper.Movie.Language, LikeCount = wrapper.Movie.LikeCount, MpaRating = wrapper.Movie.MpaRating, PosterImagePath = string.Empty, RatingValue = rating, RtAudienceRating = wrapper.Movie.RtAudienceRating, RtAudienceScore = wrapper.Movie.RtAudienceScore, RtCriticsRating = wrapper.Movie.RtCriticsRating, RtCrtiticsScore = wrapper.Movie.RtCrtiticsScore, Runtime = wrapper.Movie.Runtime, Title = tmdbInfos.Title, TitleLong = wrapper.Movie.TitleLong, Torrents = wrapper.Movie.Torrents, Url = wrapper.Movie.Url, WatchInFullHdQuality = false, Year = wrapper.Movie.Year, YtTrailerCode = wrapper.Movie.YtTrailerCode }; }); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Logger.Debug( $"GetMovieFullDetails ({movie.ImdbCode}) in {elapsedMs} milliseconds."); return(movie); }
public PredictionResult(MovieShort movie) : this() { BindingContext = new PredictionResultViewModel(movie, new PageService()); }