Ejemplo n.º 1
0
        /// <summary>
        /// Méthode permettant d'aller chercher sur l'API de TmDb les informations sur les films.
        /// </summary>
        /// <param name="moviesInfomration"></param>
        /// <returns></returns>
        private async Task <List <MovieModel> > GetMovieDbInformation(IEnumerable <MovieInformation> moviesInfomration)
        {
            List <MovieModel> returnMovieModels = new List <MovieModel>();

            foreach (MovieInformation movieInformation in moviesInfomration)
            {
                SearchMovie movieSelected;

                // Pour palier le limit rate du site j'attend 1 sec avant de refaire une recherche.
                await Task.Delay(1000);

                if (movieInformation.Annee != "Inconnu")
                {
                    SearchContainer <SearchMovie> temp = await ClientTmDb.SearchMovieAsync(movieInformation.Titre,
                                                                                           includeAdult : true,
                                                                                           year : Convert.ToInt32(movieInformation.Annee));

                    movieSelected = GetTheGoodMovie(temp, movieInformation);
                }
                else
                {
                    SearchContainer <SearchMovie> temp = await ClientTmDb.SearchMovieAsync(movieInformation.Titre,
                                                                                           includeAdult : true);

                    movieSelected = GetTheGoodMovie(temp, movieInformation);
                }

                Movie movieDb;

                if (movieSelected == null)
                {
                    //Log.Information("Aucune information TmDb trouvé pour " + movieInformation.Titre);

                    movieDb = new Movie
                    {
                        Title    = movieInformation.Titre,
                        Overview = "Aucune information de trouvé sur TmDb"
                    };
                }
                else
                {
                    //movieDb = await ClientTmDb.GetMovieAsync(movieSelected.Id);

                    // Récupération des infos avec les vidéos.
                    movieDb = await ClientTmDb.GetMovieAsync(movieSelected.Id, MovieMethods.Videos);
                }

                returnMovieModels.Add(new MovieModel(Guid.NewGuid())
                {
                    MovieInformation = movieInformation,
                    MovieTmDb        = movieDb,
                    DateAdded        = GetDateFileCreated(movieInformation.PathFile)
                });

                Log.Logger.Information("Ajout de " + movieDb.OriginalTitle);
            }

            return(returnMovieModels);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Récupère du site TmDb les informations par rapport à un titre.
        /// </summary>
        /// <param name="titre"></param>
        /// <returns></returns>
        public async Task <IEnumerable <SearchVideoModel> > GetListVideoOnTmDb(string titre)
        {
            List <SearchVideoModel> retourInfo = new List <SearchVideoModel>();

            var temp = await ClientTmDb.SearchMovieAsync(titre);

            foreach (SearchMovie result in temp.Results)
            {
                if (!string.IsNullOrEmpty(result.PosterPath))
                {
                    retourInfo.Add(new SearchVideoModel()
                    {
                        UrlAffiche  = "https://image.tmdb.org/t/p/w370_and_h556_bestv2" + result.PosterPath,
                        IdVideoTmDb = result.Id,
                        Titre       = result.Title,
                        ReleaseDate = result.ReleaseDate
                    });
                }
            }

            return(retourInfo);
        }