Ejemplo n.º 1
0
        private static void FetchImagesExample(TMDbClient client)
        {
            const int movieId = 76338; // Thor: The Dark World (2013)

            // In the call below, we're fetching the wanted movie from TMDb, but we're also doing something else.
            // We're requesting additional data, in this case: Images. This means that the Movie property "Images" will be populated (else it will be null).
            // We could combine these properties, requesting even more information in one go:
            //      client.GetMovie(movieId, MovieMethods.Images);
            //      client.GetMovie(movieId, MovieMethods.Images | MovieMethods.Releases);
            //      client.GetMovie(movieId, MovieMethods.Images | MovieMethods.Trailers | MovieMethods.Translations);
            //
            // .. and so on..
            //
            // Note: Each method normally corresponds to a property on the resulting object. If you haven't requested the information, the property will most likely be null.

            // Also note, that while we could have used 'client.GetMovieImages()' - it was better to do it like this because we also wanted the Title of the movie.
            Movie movie = client.GetMovie(movieId, MovieMethods.Images);

            Console.WriteLine("Fetching images for '" + movie.Title + "'");

            // Images come in two forms, each dispayed below
            Console.WriteLine("Displaying Backdrops");
            ProcessImages(client, movie.Images.Backdrops.Take(3), client.Config.Images.BackdropSizes);
            Console.WriteLine();

            Console.WriteLine("Displaying Posters");
            ProcessImages(client, movie.Images.Posters.Take(3), client.Config.Images.PosterSizes);
            Console.WriteLine();

            Spacer();
        }
Ejemplo n.º 2
0
        public void ClientRateLimitTest()
        {
            const int tomorrowLand = 158852;
            TMDbClient client = new TMDbClient(TestConfig.APIKey);
            client.ThrowErrorOnExeedingMaxCalls = true;

            for (int i = 0; i < 100; i++)
            {
                client.GetMovie(tomorrowLand);
            }

            Assert.Fail();
        }
Ejemplo n.º 3
0
        // This code is to get Movies from THE Movie Database (http://www.themoviedb.org)
        public static MovieModel getSingleFromTMDB(string title)
        {
            // Year
            int year = DateTime.Now.Year;

            MovieModel expectedMovie = new MovieModel();
            TMDbClient client = new TMDbClient("34c356b1eb1a362f5a3b958a9e94a113");
            SearchContainer<SearchMovie> results = client.SearchMovie(title);

            if(results.Results.Count> 0)
            {
                try
                {
                    int id = results.Results[0].Id;
                    Movie movie = client.GetMovie(id);
                    if (movie.OriginalLanguage.Equals("hi")) return null;
                    List<Genre> genres = movie.Genres;
                    var credits = client.GetMovieCredits(id);
                    List<string> credit = getStringFromCrewList(credits);

                    expectedMovie.Title = title;
                    expectedMovie.Year = movie.ReleaseDate.Value.Year.ToString();
                    expectedMovie.Released = movie.ReleaseDate.Value.Date.ToString();
                    expectedMovie.Runtime = movie.Runtime.ToString() + " Minutes";
                    expectedMovie.Genre = getStringFromGenereList(movie.Genres);

                    expectedMovie.Actors = credit[0].ToString();

                    expectedMovie.Director = credit[1].ToString();

                    expectedMovie.Writer = credit[2].ToString();

                    expectedMovie.Plot = movie.Overview;
                    expectedMovie.Language = movie.OriginalLanguage;
                    if(movie.ProductionCountries.Count>0) expectedMovie.Country = movie.ProductionCountries[0].Name;
                    expectedMovie.Poster = Constants.POSTER_LINK_HOST_PATH + movie.PosterPath;
                    expectedMovie.imdbRating = movie.VoteAverage.ToString();
                    expectedMovie.imdbVotes = movie.VoteCount.ToString();
                    expectedMovie.imdbID = movie.ImdbId.ToString();
                    expectedMovie.Showtype = "2D";
                    return expectedMovie;
                }
                catch (Exception e)
                {
                    return null;
                }
            }
            else return null;
        }
Ejemplo n.º 4
0
        //Retrieve TMDB info with a TMDBNum
        public Models.Movie ReturnMovieInfoFromTMDB(int tmdbNum)
        {
            TMDbClient client = new TMDbClient("1fee8f2397ff73412985de2bb825f020");

            Movie movie = client.GetMovie(tmdbNum);

            Models.Movie movieInfo = new Models.Movie();
            movieInfo.MovieTitle = movie.Title;
            movieInfo.MovieTMDBNum = movie.Id;
            movieInfo.MpaaRating = movie.Releases.Countries.FirstOrDefault(m => m.Iso_3166_1 == "US").Certification;
            movieInfo.ReleaseDate = movie.ReleaseDate.Value;
            movieInfo.Synopsis = movie.Overview;
            movieInfo.Duration = movie.Runtime.Value;
            movieInfo.PosterUrl = "https://image.tmdb.org/t/p/original/" + movie.Images.Posters[0].FilePath;

            foreach (var g in movie.Genres)
            {
                movieInfo.Genres.Add(g.Name);
            }

            movieInfo.Director.DirectorName = movie.Credits.Crew.FirstOrDefault(d => d.Job == "Director").Name;
            movieInfo.Director.DirectorTMDBNum = movie.Credits.Crew.FirstOrDefault(d => d.Job == "Director").Id;
            movieInfo.Studio.StudioName = movie.ProductionCompanies[0].Name;
            movieInfo.Studio.StudioTMDBNum = movie.ProductionCompanies[0].Id;

            foreach (var t in movie.AlternativeTitles.Titles)
            {
                if (t.Iso_3166_1 == "US")
                {
                    movieInfo.MovieAliases.Add(t.Title);
                }
            }

            for (int i = 0; i < 15; i++)
            {
                Actor newActor = new Actor();
                newActor.ActorName = movie.Credits.Cast[i].Name;
                newActor.ActorTMDBNum = movie.Credits.Cast[i].Id;
                movieInfo.MovieActors.Add(newActor);
            }

            return movieInfo;
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string v = Request.QueryString["id"];

            string connstring = "Server=ec2-54-217-202-110.eu-west-1.compute.amazonaws.com;Port=5432;" +
                "User Id=iwzexazhfjxbbt;Password=4JVMJFooosyfdM5Y79Si-c691D;Database=d8u6uelvine6d6;ssl=true";

            NpgsqlConnection conn = new NpgsqlConnection(connstring);
            conn.Open();

            string sql = "SELECT original_title, vote_average FROM movie where id = " + v;

            NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);

            da.Fill(ds, "movie_genre");

            dt = ds.Tables[0];

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                Label1.Text = row["original_title"].ToString();
                Label2.Text = row["vote_average"].ToString();
            }
            string sql1 = "SELECT a.name as Genre FROM genre a, movie_genre b where a.id=b.genre_id and b.movie_id = " + v;

            NpgsqlDataAdapter da1 = new NpgsqlDataAdapter(sql1, conn);

            da1.Fill(ds1);

            dt1 = ds1.Tables[0];

            GridView1.DataSource = dt1;
            GridView1.DataBind();
            conn.Close();

            TMDbClient client = new TMDbClient("c6d0e337dede3d1affc1e12252ced4d4");
               Movie movie = client.GetMovie(Int32.Parse(v));

            Label5.Text = v;
            Label4.Text = movie.Overview;
        }
Ejemplo n.º 6
0
 private void TmdbComplete(TMDbClient tmdb)
 {
     try
     {
         String[] split = Title.Split(new char[] { ' ', '.', '_', '-' });
         TMDbLib.Objects.General.SearchContainer<SearchMovie> results = tmdb.SearchMovie(this.Title);
         for (int i = split.Length; results.TotalResults == 0 && i > 0 ; --i)
         {
             String name = null;
             for (int j = 0; j < i; ++j)
                 name += " " + split[j];
             results = tmdb.SearchMovie(name);
         }
         Movie mov = tmdb.GetMovie(results.Results[0].Id);
         this.Adult = mov.Adult;
         this.Url = mov.Homepage;
         this.Title = mov.Title;
         if (mov != null && this.Picture == @"/WindowsMediaPlayer;component/assets/video_cover.png")
             SetImage(@"https://image.tmdb.org/t/p/w185" + mov.PosterPath, Lastfm.Utilities.md5(Path));
     }
     catch (Exception e)
     {
         Debug.Add(e.ToString() + "\n");
     }
 }
Ejemplo n.º 7
0
        public static List<MovieDB_Movie_Result> SearchWithTVShowID(int id, bool isTrakt)
        {
            List<MovieDB_Movie_Result> results = new List<MovieDB_Movie_Result>();

            try
            {
                TMDbClient client = new TMDbClient(apiKey);
                TvShow result = client.GetTvShow(id, TvShowMethods.Images, null);

                if (result != null)
                {

                    logger.Info("Got TMDB results for id: {0} | show name: {1}", id, result.Name);
                    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, true, isTrakt);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error in MovieDB Search: " + ex.Message);
            }

            return results;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            using (new SecurityDisabler())
            {
                Sitecore.Configuration.Settings.Indexing.Enabled = false;
                IndexCustodian.PauseIndexing();
                TMDbClient client = new TMDbClient("a7e29a282bb192663ce78f3574cf7a24");
                client.GetConfig();

                var master = Factory.GetDatabase("master");
                var movieContainer = master.GetItem(new ID("{46294884-8157-4828-9FD1-83B6E8EAFEA0}"));
                //movieContainer.DeleteChildren();
                var folderItem = master.GetItem(new ID("{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}"));
                var movieTemplateItem = master.GetItem(new ID("{7D2F4318-029A-461B-854E-FD7CFB4C4F6A}"));
                var genresContainer = master.GetItem(new ID("{1A3786F4-68C0-47A5-A9D5-462765FE7C3E}"));
                var listItem = master.GetItem(new ID("{EB8C2C7A-FE2B-4E9A-8859-D4EBD9CD94D1}"));
                var productionCompaniesContainer = master.GetItem(new ID("{7A968F6F-7A21-4977-815C-581A9DC3EF5A}"));
                var productionCountriesContainer = master.GetItem(new ID("{2E421735-1C21-4648-8CC9-118B68B150C8}"));
                var pageID = 0;
                var totalPages = client.GetMovieList(MovieListType.TopRated, pageID).TotalPages;
                while (pageID <= totalPages)
                {
                    var movies = client.GetMovieList(MovieListType.TopRated, pageID);
                    pageID++;
                    foreach (var movie in movies.Results)
                    {
                        litMessage.Text += String.Format("{0} -> {1}<br/>", movie.OriginalTitle,
                            !movie.Title.Equals(movie.OriginalTitle) ? movie.Title : "");
                        var movieExt = client.GetMovie(movie.Id, MovieMethods.Credits);
                        
                        var sitecoreTitle = ItemUtil.ProposeValidItemName(movieExt.Title.Trim().ToLower());
                        var firstLetter = ItemUtil.ProposeValidItemName(sitecoreTitle.Substring(0, 1));

                        Item subFolder = movieContainer.Children.FirstOrDefault(x => x.Name == firstLetter);
                        if (subFolder == null)
                            subFolder = movieContainer.Add(firstLetter, new TemplateID(folderItem.ID));
                        if (subFolder.Children.FirstOrDefault(x => x.Name == sitecoreTitle) != null)
                            continue;
                        var movieItem = subFolder.Add(sitecoreTitle, new TemplateID(movieTemplateItem.ID));
                        movieItem.Editing.BeginEdit();
                        movieItem["Original title"] = movieExt.OriginalTitle;
                        movieItem["Title"] = movieExt.Title;
                        movieItem["Tagline"] = movieExt.Tagline;
                        movieItem["Body"] = movieExt.Overview;
                        movieItem["Vote average"] = movieExt.VoteAverage.ToString("00.00");
                        movieItem["Vote count"] = movieExt.VoteCount.ToString();
                        var genresField = (MultilistField) movieItem.Fields["Genres"];

                        foreach (var genre in movieExt.Genres)
                        {
                            var genreSitecoreName = ItemUtil.ProposeValidItemName(genre.Name.Trim().ToLower());
                            var genreItem = genresContainer.Children.FirstOrDefault(x => x.Name == genreSitecoreName);
                            if (genreItem == null)
                            {
                                genreItem = genresContainer.Add(genreSitecoreName, new TemplateID(listItem.ID));
                                genreItem.Editing.BeginEdit();
                                genreItem["Id"] = genre.Id.ToString();
                                genreItem["Name"] = genre.Name;
                                genreItem.Editing.EndEdit();
                            }
                            genresField.Add(genreItem.ID.ToString());
                        }
                        movieItem["Tmdb Id"] = movieExt.Id.ToString();
                        movieItem["Imdb Id"] = movieExt.ImdbId;
                        movieItem["Runtime"] = movieExt.Runtime.GetValueOrDefault().ToString();
                        movieItem["Status"] = movieExt.Status;
                        movieItem["Release date"] = DateUtil.ToIsoDate(movieExt.ReleaseDate.GetValueOrDefault());

                        var productionCompaniesField = (MultilistField) movieItem.Fields["Production companies"];

                        foreach (var productionCompany in movieExt.ProductionCompanies)
                        {
                            var productionCompanySitecoreName =
                                ItemUtil.ProposeValidItemName(productionCompany.Name.Trim().ToLower());
                            var productionCompanyItem =
                                productionCompaniesContainer.Children.FirstOrDefault(
                                    x => x.Name == productionCompanySitecoreName);
                            if (productionCompanyItem == null)
                            {
                                productionCompanyItem = productionCompaniesContainer.Add(productionCompanySitecoreName,
                                    new TemplateID(listItem.ID));
                                productionCompanyItem.Editing.BeginEdit();
                                productionCompanyItem["Id"] = productionCompany.Id.ToString();
                                productionCompanyItem["Name"] = productionCompany.Name;
                                productionCompanyItem.Editing.EndEdit();
                            }
                            productionCompaniesField.Add(productionCompanyItem.ID.ToString());
                        }
                        var productionCountriesField = (MultilistField) movieItem.Fields["Production countries"];

                        foreach (var productionCountry in movieExt.ProductionCountries)
                        {
                            var productionCountrySitecoreName =
                                ItemUtil.ProposeValidItemName(productionCountry.Name.Trim().ToLower());
                            var productionCountryItem =
                                productionCountriesContainer.Children.FirstOrDefault(
                                    x => x.Name == productionCountrySitecoreName);
                            if (productionCountryItem == null)
                            {
                                productionCountryItem = productionCountriesContainer.Add(productionCountrySitecoreName,
                                    new TemplateID(listItem.ID));
                                productionCountryItem.Editing.BeginEdit();
                                productionCountryItem["Id"] = productionCountry.Iso_3166_1;
                                productionCountryItem["Name"] = productionCountry.Name;
                                productionCountryItem.Editing.EndEdit();
                            }
                            productionCountriesField.Add(productionCountryItem.ID.ToString());
                        }
                        var posterUri = client.GetImageUrl("original", movie.PosterPath);
                        if (!String.IsNullOrEmpty(movie.PosterPath))
                        {
                            var mediaItem = AddFile(posterUri, sitecoreTitle, movie.PosterPath.Replace("/", ""));
                            if (mediaItem != null)
                            {
                                Sitecore.Data.Fields.ImageField imageField = movieItem.Fields["Image"];
                                imageField.MediaID = mediaItem.ID;
                            }
                        }
                        movieItem["Menu title"] = movie.Title;
                        movieItem["SEO title"] = movie.Title;
                        movieItem.Editing.EndEdit();
                    }
                }
                IndexCustodian.ResumeIndexing();
                Sitecore.Configuration.Settings.Indexing.Enabled = true;
                IndexCustodian.RebuildAll();
            }}
Ejemplo n.º 9
0
        /// <summary>
        /// Download the movie background image
        /// </summary>
        /// <param name="imdbCode">The unique identifier of a movie</param>
        /// <param name="cancellationToken">cancellationToken</param>
        public async Task<Tuple<string, IEnumerable<Exception>>> DownloadMovieBackgroundImageAsync(string imdbCode,
            CancellationTokenSource cancellationToken)
        {
            List<Exception> ex = new List<Exception>();
            string backgroundImage = String.Empty;

            TMDbClient tmDbclient = new TMDbClient(Constants.TmDbClientId);
            tmDbclient.GetConfig();

            try
            {
                TMDbLib.Objects.Movies.Movie movie = tmDbclient.GetMovie(imdbCode, MovieMethods.Images);
                if (movie.ImdbId != null)
                {
                    Uri imageUri = tmDbclient.GetImageUrl(Constants.BackgroundImageSizeTmDb,
                        movie.Images.Backdrops.Aggregate((i1, i2) => i1.VoteAverage > i2.VoteAverage ? i1 : i2).FilePath);

                    try
                    {
                        Tuple<string, Exception> res =
                            await
                                DownloadFileAsync(imdbCode, imageUri, Constants.FileType.BackgroundImage,
                                    cancellationToken.Token);

                        if (res != null)
                        {
                            if (res.Item2 == null)
                            {
                                backgroundImage = Constants.BackgroundMovieDirectory + imdbCode +
                                                  Constants.ImageFileExtension;
                            }
                            else
                            {
                                ex.Add(res.Item2);
                            }
                        }
                        else
                        {
                            ex.Add(new Exception());
                        }
                    }
                    catch (WebException webException)
                    {
                        ex.Add(webException);
                    }
                    catch (TaskCanceledException e)
                    {
                        ex.Add(e);
                    }
                }
                else
                {
                    ex.Add(new Exception());
                }
            }
            catch (Exception e)
            {
                ex.Add(e);
            }

            return new Tuple<string, IEnumerable<Exception>>(backgroundImage, ex);
        }
Ejemplo n.º 10
0
        public void ClientRateLimitTest()
        {
            const int tomorrowLand = 158852;

            TMDbClient client = new TMDbClient(TestConfig.APIKey);
            client.ThrowErrorOnExeedingMaxCalls = true;

            for (int i = 0; i < 100; i++)
            {
                try
                {
                    client.GetMovie(tomorrowLand).Wait();
                }
                catch (AggregateException ex)
                {
                    // Unpack the InnerException
                    throw ex.InnerException;
                }
            }

            Assert.Fail();
        }
Ejemplo n.º 11
0
        public static void Execute()
        {
            Console.Write("Please enter the movie ID (TMDB) that you want to look up (11 is Star Wars): ");
            string input = Console.ReadLine();

            TMDbClient client = new TMDbClient("1fee8f2397ff73412985de2bb825f020");

            Movie movie = client.GetMovie(input, MovieMethods.AlternativeTitles | MovieMethods.Credits | MovieMethods.Images | MovieMethods.Releases | MovieMethods.Videos);

            Console.Clear();

            Console.WriteLine("Movie Name: {0}", movie.Title);

            Console.WriteLine("Movie TMDBNum: {0}", movie.Id);

            Console.WriteLine("MPAA Rating: {0}", movie.Releases.Countries.FirstOrDefault(m => m.Iso_3166_1 == "US").Certification);

            Console.WriteLine("Release Date: {0}", movie.ReleaseDate.Value.ToString("yyyy-MM-dd"));

            Console.WriteLine("Synopsis: {0}", movie.Overview);

            Console.WriteLine("Duration: {0} mins", movie.Runtime);

            Console.WriteLine("PosterUrl: {0}", "https://image.tmdb.org/t/p/original" + movie.PosterPath);

            Console.WriteLine("Movie Studio: {0} (ID {1})", movie.ProductionCompanies[0].Name, movie.ProductionCompanies[0].Id);

            Console.WriteLine("Director: {0} (ID {1})", movie.Credits.Crew.FirstOrDefault(d => d.Job == "Director").Name, movie.Credits.Crew.FirstOrDefault(d => d.Job == "Director").Id);

            Console.WriteLine("List of Genres:");
            foreach (var g in movie.Genres)
            {
                Console.WriteLine("{0} - {1}", g.Name, g.Id);
            }

            Console.WriteLine("Youtube trailer");
            Console.WriteLine(movie.Video);
            foreach (var t in movie.Videos.Results)
            {
                Console.WriteLine("Site: {0}", t.Site);
                Console.WriteLine("ID: {0}", t.Id);
                Console.WriteLine("Iso_639_1: {0}", t.Iso_639_1);
                Console.WriteLine("Key: {0}", t.Key);
                Console.WriteLine("Name: {0}", t.Name);
                Console.WriteLine("Size: {0}", t.Size);
                Console.WriteLine("Type: {0}", t.Type);
                Console.WriteLine();
            }

            Console.WriteLine();

            Console.WriteLine("List of First 15 Actors!!");

            for (int i = 0; i < 15; i++)
            {
                Console.WriteLine("{0} - plays {1} - (ID {2})", movie.Credits.Cast[i].Name, movie.Credits.Cast[i].Character, movie.Credits.Cast[i].Id);
            }

            Console.WriteLine();

            Console.WriteLine("List of Alternate US Titles");
            foreach (var t in movie.AlternativeTitles.Titles)
            {
                if (t.Iso_3166_1 == "US")
                {
                    Console.WriteLine("{0} - {1}", t.Title, t.Iso_3166_1);
                }
            }
        }
Ejemplo n.º 12
0
        //Retrieve TMDB info with a TMDBNum
        public Models.Movie ReturnMovieInfoFromTMDB(int tmdbNum)
        {
            TMDbClient client = new TMDbClient("1fee8f2397ff73412985de2bb825f020");

            Movie movie = client.GetMovie(tmdbNum,
                MovieMethods.AlternativeTitles | MovieMethods.Credits | MovieMethods.Images | MovieMethods.Releases |
                MovieMethods.Videos);

            Models.Movie movieInfo = new Models.Movie();
            movieInfo.MovieTitle = movie.Title;
            movieInfo.MovieTMDBNum = movie.Id;
            if (movie.Releases.Countries.FirstOrDefault(m => m.Iso_3166_1 == "US") != null)
            {
                movieInfo.MpaaRating = movie.Releases.Countries.FirstOrDefault(m => m.Iso_3166_1 == "US").Certification;
            }
            else
            {
                movieInfo.MpaaRating = "NR";
            }
            if (movie.ReleaseDate != null)
            {
                movieInfo.ReleaseDate = movie.ReleaseDate.Value.Date;
            }
            if (movie.Overview != null)
            {
                movieInfo.Synopsis = movie.Overview;
            }
            if (movie.Runtime != null)
            {
                movieInfo.Duration = movie.Runtime.Value;
            }
            if (movie.PosterPath != null)
            {
                movieInfo.PosterUrl = "http://image.tmdb.org/t/p/w396" + movie.PosterPath;
            }
            else
            {
                movieInfo.PosterUrl =
                    "http://assets.tmdb.org/assets/7f29bd8b3370c71dd379b0e8b570887c/images/no-poster-w185-v2.png";
            }
            if (movie.Videos.Results.Where(v => v.Type == "Trailer").FirstOrDefault() != null)
            {
                movieInfo.YouTubeTrailer = "http://www.youtube.com/embed/" +
                                           movie.Videos.Results.Where(v => v.Type == "Trailer").FirstOrDefault().Key;
            }
            if (movie.Genres.Count != 0)
            {
                foreach (var g in movie.Genres)
                {
                    var newGenre = new Models.Genre();
                    newGenre.GenreName = g.Name;
                    movieInfo.Genres.Add(newGenre);
                }
            }
            if (movie.Credits.Crew.FirstOrDefault(d => d.Job == "Director") != null)
            {
                movieInfo.Director.DirectorName = movie.Credits.Crew.FirstOrDefault(d => d.Job == "Director").Name;
                movieInfo.Director.DirectorTMDBNum = movie.Credits.Crew.FirstOrDefault(d => d.Job == "Director").Id;
            }
            if (movie.ProductionCompanies.Count != 0)
            {
                movieInfo.Studio.StudioName = movie.ProductionCompanies[0].Name;
                movieInfo.Studio.StudioTMDBNum = movie.ProductionCompanies[0].Id;
            }

            if (movie.AlternativeTitles.Titles.Count != 0)
            {
                foreach (var t in movie.AlternativeTitles.Titles)
                {
                    if (t.Iso_3166_1 == "US")
                    {
                        var newMovieAlias = new MovieAlias();
                        newMovieAlias.MovieAliasTitle = t.Title;
                        movieInfo.MovieAliases.Add(newMovieAlias);
                    }
                }
            }

            if (movie.Credits.Cast.Count < 10 && movie.Credits.Cast.Count > 0)
            {
                foreach (var a in movie.Credits.Cast)
                {
                    Actor newActor = new Actor();
                    newActor.ActorName = a.Name;
                    newActor.ActorTMDBNum = a.Id;
                    newActor.CharacterName = a.Character;
                    movieInfo.MovieActors.Add(newActor);
                }
            }
            else if (movie.Credits.Cast.Count == 0)
            {
                return movieInfo;
            }
            else
            {
                for (int i = 0; i < 10; i++)
                {
                    Actor newActor = new Actor();
                    newActor.ActorName = movie.Credits.Cast[i].Name;
                    newActor.ActorTMDBNum = movie.Credits.Cast[i].Id;
                    newActor.CharacterName = movie.Credits.Cast[i].Character;
                    movieInfo.MovieActors.Add(newActor);
                }
            }

            return movieInfo;
        }
Ejemplo n.º 13
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);
                }	

			}
			catch (Exception ex)
			{
				logger.Error("Error in MovieDB Search: " + ex.Message);
			}

			return results;
		}
        internal static string IdentifyFilmByTMDbFilmTitleMatchingEngine
            (IMLItem item)
        {


            string filmTitle = item.Name;


            string filmImdbId = Helpers.GetTagValueFromItem(item, "ImdbID");

            //MessageBox.Show("Film title: " + filmTitle);

            if (String.IsNullOrEmpty(filmTitle))
                return filmImdbId;


            if (!String.IsNullOrEmpty(filmImdbId))
                return filmImdbId;




            int filmReleaseYear = -1;

            string filmReleaseYearString = Helpers.GetTagValueFromItem(item, "Year").Trim();

            if (!String.IsNullOrEmpty(filmReleaseYearString))
            {

                bool yarStringIsValidNumber = true;

                foreach (var digit in filmReleaseYearString)
                {
                    if (!Char.IsNumber(digit))
                        yarStringIsValidNumber = false;
                }

                if (yarStringIsValidNumber)
                {

                    filmReleaseYear = Convert.ToInt16(filmReleaseYearString);

                }

            }


            Helpers.UpdateProgress
                ("Updating Movies Section...", 
                "Attempting to identify film by title using TMDb...", item);


            TMDbClient tmDbClient = new TMDbClient(MeediFier.Settings.TMDbApiKey);


            SearchContainer<SearchMovie> filmSearchResults 
                = tmDbClient.SearchMovie
                (filmTitle, "", -1, false, filmReleaseYear);
            
            //SearchContainer<SearchMovie> filmSearchResults = tmDbClient.SearchMovie(filmTitle);



            if (filmSearchResults.Results.Count <= 0)
                return filmImdbId;
            

            SearchMovie firstMovieInSearchResults = filmSearchResults.Results[0];


            TMDbLib.Objects.Movies.Movie movie = tmDbClient.GetMovie(firstMovieInSearchResults.Id);

            filmImdbId = movie.ImdbId;



            //MessageBox.Show(filmImdbId);


            if (String.IsNullOrEmpty(filmImdbId))
                return filmImdbId;


            item.Tags["ImdbID"] = filmImdbId;
            item.SaveTags();

            return filmImdbId;

        }
Ejemplo n.º 15
0
        static public bool DownloadMovieDetails(VideoTags videoTags)
        {
            // The new v3 database is accessed via the TMDbLib API's
            try
            {
                TMDbClient client = new TMDbClient(MCEBUDDY_TMDB_APIKey);
                List<SearchMovie> movieSearch = new List<SearchMovie>();
                Movie movieMatch = null;

                // TODO: Add support for multiple language searches
                if (String.IsNullOrWhiteSpace(videoTags.imdbId)) // If dont' have a specific movieId specified, look up the movie details
                {
                    if (videoTags.OriginalBroadcastDateTime > GlobalDefs.NO_BROADCAST_TIME) // Release date narrow down
                    {
                        // The information is stored on the server using the network timezone
                        // So we assume that the show being converted was recorded locally and is converted locally so the timezones match
                        DateTime dt = videoTags.OriginalBroadcastDateTime.ToLocalTime();
                        movieSearch = client.SearchMovie(videoTags.Title.Trim().ToLower(), 0, true, dt.Year).Results;
                    }
                    else // Title Check
                        movieSearch = client.SearchMovie(videoTags.Title.Trim().ToLower(), 0, true, 0).Results;
                }
                else // Specific ID
                {
                    movieMatch = client.GetMovie(videoTags.imdbId); // We have a specific movie to work with
                }

                if (movieMatch == null) // If we haven't forced a movie match
                {
                    foreach (SearchMovie movieResult in movieSearch) // Cycle through all possible combinations
                    {
                        Movie movie = client.GetMovie(movieResult.Id);
                        List<AlternativeTitle> akaValues = null;
                        if (movie.AlternativeTitles != null)
                            akaValues = movie.AlternativeTitles.Titles;
                        bool akaMatch = false;
                        string title = videoTags.Title;
                        if (akaValues != null) // Check if there are any AKA names to match
                            akaMatch = akaValues.Any(s => (String.Compare(s.Title.Trim(), title.Trim(), CultureInfo.InvariantCulture, (CompareOptions.IgnoreSymbols | CompareOptions.IgnoreCase)) == 0 ? true : false));

                        // Get and match Movie name (check both titles and aka values)
                        if (String.Compare(movie.Title.Trim(), videoTags.Title.Trim(), CultureInfo.InvariantCulture, (CompareOptions.IgnoreSymbols | CompareOptions.IgnoreCase)) != 0) // ignore white space and special characters
                            if (String.Compare(movie.OriginalTitle.Trim(), videoTags.Title.Trim(), CultureInfo.InvariantCulture, (CompareOptions.IgnoreSymbols | CompareOptions.IgnoreCase)) != 0) // ignore white space and special characters
                                if (!akaMatch) // check for aka value matches
                                    continue; // No match in name

                        // If we got here, then we found a match
                        movieMatch = movie;
                        break; // We are done here
                    }
                }

                if (movieMatch != null) // We have a match
                {
                    if (!String.IsNullOrWhiteSpace(videoTags.imdbId)) // Match names only if the movie imdb id is not forced, else take what is returned by moviedb
                        videoTags.Title = movieMatch.Title; // Take what is forced for the imdb movie id

                    // Get Movie Id
                    videoTags.tmdbId = movieMatch.Id.ToString();

                    videoTags.IsMovie = true; // this is a movie

                    // Get Overview
                    string overview = movieMatch.Overview;
                    if (!String.IsNullOrWhiteSpace(overview) && String.IsNullOrWhiteSpace(videoTags.Description))
                        videoTags.Description = overview;

                    // Get original release date
                    if (movieMatch.ReleaseDate != null)
                    {
                        DateTime releaseDate = (DateTime)movieMatch.ReleaseDate;
                        if (releaseDate > GlobalDefs.NO_BROADCAST_TIME)
                            if ((videoTags.OriginalBroadcastDateTime <= GlobalDefs.NO_BROADCAST_TIME) || (videoTags.OriginalBroadcastDateTime.Date > releaseDate.Date)) // Sometimes the metadata from the video recordings are incorrect and report the recorded date (which is more recent than the release date) then use MovieDB dates, MovieDB Dates are more reliable than video metadata usually
                                videoTags.OriginalBroadcastDateTime = releaseDate; // MovieDB stores time in network (local) timezone
                    }

                    // Get Genres
                    List<string> genres = new List<string>();
                    foreach (Genre genre in movieMatch.Genres)
                    {
                        genres.Add(genre.Name);
                    }
                    if (genres.Count > 0)
                    {
                        if (videoTags.Genres != null)
                        {
                            if (videoTags.Genres.Length == 0)
                                videoTags.Genres = genres.ToArray();
                        }
                        else
                            videoTags.Genres = genres.ToArray();
                    }

                    // Download the banner file
                    client.GetConfig(); // First we need to get the config
                    VideoMetaData.DownloadBannerFile(videoTags, client.GetImageUrl("original", movieMatch.PosterPath).OriginalString); // Get bannerfile

                    return true; // home free, we're good
                }

                return false;
            }
            catch
            {
                return false;
            }
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            TMDbClient client = new TMDbClient("APIKEY");

            FileInfo configXml = new FileInfo("config.xml");

            if (configXml.Exists && configXml.LastWriteTimeUtc >= DateTime.UtcNow.AddHours(-1))
            {
                Console.WriteLine("Using stored config");
                string xml = File.ReadAllText(configXml.FullName, Encoding.Unicode);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xml);

                client.SetConfig(Serializer.Deserialize<TMDbConfig>(xmlDoc));
            }
            else
            {
                Console.WriteLine("Getting new config");
                client.GetConfig();

                Console.WriteLine("Storing config");
                XmlDocument xmlDoc = Serializer.Serialize(client.Config);
                File.WriteAllText(configXml.FullName, xmlDoc.OuterXml, Encoding.Unicode);
            }

            //
            //client.GetCompany(177, CompanyMethods.Movies);
            //client.GetCompanyMovies(177);
            Movie movie = client.GetMovie(47964, extraMethods: Enum.GetValues(typeof(MovieMethods)).OfType<MovieMethods>().Aggregate((methods, movieMethods) => movieMethods | methods));

            //client.GetCollection(1570, extraMethods: CollectionMethods.Images);
            //client.GetCollectionImages(1570);

            //client.GetList(movie.Lists.Results.First().Id);
            //client.GetPerson(62, extraMethods: PersonMethods.Images | PersonMethods.Credits | PersonMethods.Changes);
            //client.GetPersonChanges(62);
            //client.GetPersonCredits(62);
            //client.GetPersonImages(62);

            //client.GetMovieList(MovieListType.NowPlaying);
            //client.GetMovieList(MovieListType.Popular);
            //client.GetMovieList(MovieListType.TopRated);
            //client.GetMovieAlternativeTitles(47964);
            //client.GetMovieCasts(47964);
            //client.GetMovieImages(47964);
            //client.GetMovieKeywords(47964);
            //client.GetMovieReleases(47964);
            //client.GetMovieTrailers(47964);
            //client.GetMovieTranslations(47964);
            //client.GetMovieSimilarMovies(47964);
            //client.GetMovieLists(47964);
            //client.GetMovieChanges(47964);

            //client.GetMovieLatest();

            //client.GetMovie(47964, extraMethods: Enum.GetValues(typeof(MovieMethods)).OfType<MovieMethods>().Aggregate((methods, movieMethods) => movieMethods | methods));

            //client.SearchMovie("A good day to die");
            //client.SearchCollection("Die h");
            //client.SearchKeyword("Action");
            //client.SearchList("to watch");
            //client.SearchCompany("Disney");
            //client.SearchPerson("Bruce");

            //client.GetChangesMovies();
            //client.GetChangesPeople();

            //int kId = movie.Keywords.Keywords.First().Id;

            //client.GetKeyword(kId);
            //client.GetKeywordMovies(kId);

            //client.GetGenres();
            //client.GetGenreMovies(28);

            Console.WriteLine("Done.");
            Console.ReadLine();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Get the link to the youtube trailer of a movie
        /// </summary>
        /// <param name="imdbCode">The unique identifier of a movie</param>
        public Tuple<Trailers, Exception> GetMovieTrailer(string imdbCode)
        {
            Exception ex = null;
            Trailers trailers = new Trailers();

            TMDbClient tmDbclient = new TMDbClient(Constants.TmDbClientId);
            tmDbclient.GetConfig();

            try
            {
                TMDbLib.Objects.Movies.Movie movie = tmDbclient.GetMovie(imdbCode);
                if (movie.ImdbId != null)
                {
                    trailers = tmDbclient.GetMovieTrailers(movie.Id);
                }
                else
                {
                    ex = new Exception();
                }
            }
            catch (Exception e)
            {
                ex = e;
            }

            return new Tuple<Trailers, Exception>(trailers, ex);
        }
Ejemplo n.º 18
0
		public static void UpdateMovieInfo(ISession session, int movieID, bool saveImages)
		{

			try
			{
                TMDbClient client = new TMDbClient(apiKey);
                Movie movie = client.GetMovie(movieID);
                ImagesWithId imgs = client.GetMovieImages(movieID);

                MovieDB_Movie_Result searchResult = new MovieDB_Movie_Result();
                searchResult.Populate(movie, imgs);

                // save to the DB
                SaveMovieToDatabase(session, searchResult, saveImages);
			}
			catch (Exception ex)
			{
				logger.ErrorException("Error in ParseBanners: " + ex.ToString(), ex);
			}
		}
        public static void DownloadFilmDetailsFromTMDb(IMLItem item)
        {


            
            if (!MeediFier.Settings.TMDbFilmDetailsEnabled)
                return;



            string tmdbID = Helpers.GetTagValueFromItem(item, "TMDbID");



            //MessageBox.Show("TMDbID: " + tmdbID);


            if (String.IsNullOrEmpty(tmdbID))
            {

                Debugger.LogMessageToFile
                    ("The TMDb id for this film is unknown. " +
                     "Unable to download adittional film information from themoviedb.org.");
                
                return;
            
            }


            Helpers.UpdateProgress
                (MainImportingEngine.GeneralStatus, 
                "Downloading film details from TMDb...", item);




            TMDbClient client = new TMDbClient(MeediFier.Settings.TMDbApiKey);

            TMDbLib.Objects.Movies.Movie tmdbMovie = client.GetMovie(tmdbID);





            if (!String.IsNullOrEmpty(tmdbMovie.Title))
            {
                if (String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "Title")))
                {
                    item.Tags["Title"] = tmdbMovie.Title;
                    item.SaveTags();
                }
            }



            if (!String.IsNullOrEmpty(tmdbMovie.Tagline))
            {
                if (String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "Tagline")))
                {
                    item.Tags["Tagline"] = tmdbMovie.Tagline;
                    item.SaveTags();
                }
            }





            if (!String.IsNullOrEmpty(tmdbMovie.Status))
            {
                if (String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "ReleaseStatus")))
                {
                    item.Tags["ReleaseStatus"] = tmdbMovie.Status;
                    item.SaveTags();
                }
            }



            if (!String.IsNullOrEmpty(tmdbMovie.Overview))
            {
                if (String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "Overview")))
                {
                    item.Tags["Overview"] = tmdbMovie.Overview;
                    item.SaveTags();
                }
            }





            if (String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "Genre")))
            {

                List<Genre> filmGenres = tmdbMovie.Genres;

                if (filmGenres.Count > 0)
                {

                    string filmGenresString = String.Empty;

                    foreach (var filmGenre in filmGenres)
                    {

                        filmGenresString = "|" + filmGenre.Name;

                    }

                    filmGenresString = filmGenresString + "|";

                    item.Tags["Genre"] = filmGenresString;

                }



            }








            if (!String.IsNullOrEmpty(Convert.ToString(tmdbMovie.Runtime)))
            {
                if (String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "Runtime")))
                {
                    item.Tags["Runtime"] = Convert.ToString(tmdbMovie.Runtime);
                    item.SaveTags();
                }
            }





            if (!String.IsNullOrEmpty(Convert.ToString(tmdbMovie.ReleaseDate)))
            {
                if (String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "ReleaseDate")))
                {
                    item.Tags["ReleaseDate"] = Convert.ToString(tmdbMovie.ReleaseDate);
                    item.SaveTags();
                }
            }



            if (!String.IsNullOrEmpty(Convert.ToString(tmdbMovie.VoteAverage)))
            {
                if (String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "TMDbReview")))
                {
                    item.Tags["TMDbReview"] = Convert.ToString(tmdbMovie.VoteAverage);
                    item.SaveTags();
                }
            }





            if (!String.IsNullOrEmpty(Convert.ToString(tmdbMovie.Budget)))
            {
                if (String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "Budget")))
                {
                    item.Tags["Budget"] = Convert.ToString(tmdbMovie.Budget);
                    item.SaveTags();
                }
            }






            if (!String.IsNullOrEmpty(Convert.ToString(tmdbMovie.Revenue)))
            {
                if (String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "Revenue")))
                {
                    item.Tags["Revenue"] = Convert.ToString(tmdbMovie.Revenue);
                    item.SaveTags();
                }
            }





            if (!String.IsNullOrEmpty(tmdbMovie.Homepage))
            {
                if (String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "Homepage")))
                {
                    item.Tags["Homepage"] = tmdbMovie.Homepage;
                    item.SaveTags();
                }
            }


            if (String.IsNullOrEmpty(Helpers.GetTagValueFromItem(item, "SpokenLanguages")))
            {

                List<TMDbLib.Objects.Movies.SpokenLanguage> filmSpokenLanguages = tmdbMovie.SpokenLanguages;

                if (filmSpokenLanguages.Count > 0)
                {

                    string spokenLanguagesString = String.Empty;

                    foreach (var filmSpokenLanguage in filmSpokenLanguages)
                    {

                        spokenLanguagesString = "|" + filmSpokenLanguage.Name;

                    }

                    spokenLanguagesString = spokenLanguagesString + "|";

                    item.Tags["SpokenLanguages"] = spokenLanguagesString;

                }



            }
            //item.Tags["Trailer"] = tmdbMovie.Trailers;

            item.SaveTags();

            

        }
Ejemplo n.º 20
0
        private void MediaInfoLoadButton_Click(object sender, RoutedEventArgs e)
        {
            string searchMedia = MediaTitleInfo.Text;
            if (string.IsNullOrEmpty(searchMedia)) return;

            string selectedLang = (string) SearchLanguage.SelectedValue;
            if (string.IsNullOrEmpty(selectedLang))
                selectedLang = "en";

            string selectedCertCountry = (string) RatingCountry.SelectedValue;
            if (string.IsNullOrEmpty(selectedCertCountry))
                selectedCertCountry = "us";

            AppSettings.MovieDBLastLanguage = selectedLang;
            AppSettings.MovieDBLastRatingCountry = selectedCertCountry;

            TMDbClient client = new TMDbClient(MovieDBApiKey);

            FileInfo configXml = new FileInfo("TMDbconfig.xml");
            if (configXml.Exists && configXml.LastWriteTimeUtc >= DateTime.UtcNow.AddHours(-1))
            {
                Log.Info("TMDbClient: Using stored config");
                string xml = File.ReadAllText(configXml.FullName, Encoding.Unicode);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xml);

                client.SetConfig(TMDbSerializer.Deserialize<TMDbConfig>(xmlDoc));
            }
            else
            {
                Log.Info("TMDbClient: Getting new config");
                client.GetConfig();

                Log.Info("TMDbClient: Storing config");
                XmlDocument xmlDoc = TMDbSerializer.Serialize(client.Config);
                File.WriteAllText(configXml.FullName, xmlDoc.OuterXml, Encoding.Unicode);
            }

            SearchContainer<SearchMovie> movieList = client.SearchMovie(searchMedia, selectedLang);
            if (movieList == null || movieList.TotalResults <= 0) return;

            SearchMovie resultMovie = new SearchMovie();
            if (movieList.TotalResults > 1)
            {
                MovieDBMultipleSelection selectWindow = new MovieDBMultipleSelection
                    {
                        Owner = this,
                        SearchResults = movieList
                    };
                if (selectWindow.ShowDialog() == true)
                    resultMovie = selectWindow.SelectionResult;
            }
            else
                resultMovie = movieList.Results.First();

            if (resultMovie.Id == 0) return;

            Movie searchResult = client.GetMovie(resultMovie.Id, selectedLang);
            ImagesWithId imageList = client.GetMovieImages(resultMovie.Id);
            Casts movieCasts = client.GetMovieCasts(resultMovie.Id);
            KeywordsContainer movieKeywords = client.GetMovieKeywords(resultMovie.Id);
            Trailers movieTrailers = client.GetMovieTrailers(resultMovie.Id);
            Releases movieReleases = client.GetMovieReleases(resultMovie.Id);

            if (searchResult == null) return;

            MovieTitle.Text = searchResult.Title;
            MovieOriginalTitle.Text = searchResult.OriginalTitle;

            Genre.Text = searchResult.Genres != null
                             ? string.Join(" / ", searchResult.Genres.ConvertAll(input => input.Name))
                             : string.Empty;

            Rating.Text = searchResult.VoteAverage.ToString("g");
            Runtime.Text = searchResult.Runtime.ToString("g");
            Votes.Text = searchResult.VoteCount.ToString("g");
            Year.Text = searchResult.ReleaseDate.Year.ToString("g");
            Tagline.Text = searchResult.Tagline;
            Plot.Text = searchResult.Overview;

            if (movieKeywords != null && movieKeywords.Keywords != null)
                Keywords.Text = string.Join(", ", movieKeywords.Keywords.ConvertAll(input => input.Name));
            else
                Keywords.Text = string.Empty;

            ImdbId.Text = searchResult.ImdbId;

            Country.Text = searchResult.ProductionCountries != null
                               ? string.Join(" / ", searchResult.ProductionCountries.ConvertAll(input => input.Name))
                               : string.Empty;

            if (movieCasts != null && movieCasts.Crew != null)
            {
                Director.Text = string.Join(" / ",
                                            movieCasts.Crew.Where(crew => crew.Job == "Director")
                                                      .ToList()
                                                      .ConvertAll(input => input.Name));
                Writers.Text = string.Join(" / ",
                                           movieCasts.Crew.Where(crew => crew.Job == "Writer" || crew.Job == "Screenplay")
                                                     .ToList()
                                                     .ConvertAll(input => input.Name));
            }
            else
            {
                Director.Text = string.Empty;
                Writers.Text = string.Empty;
            }

            Studio.Text = searchResult.ProductionCompanies != null
                              ? string.Join(" / ", searchResult.ProductionCompanies.ConvertAll(input => input.Name))
                              : string.Empty;

            SetName.Text = searchResult.BelongsToCollection != null
                               ? string.Join(" / ", searchResult.BelongsToCollection.ConvertAll(input => input.Name))
                               : string.Empty;

            if (movieTrailers != null && movieTrailers.Youtube != null && movieTrailers.Youtube.Count > 0)
                Trailer.Text = "plugin://plugin.video.youtube/?action=play_video&amp;videoid=" +
                               movieTrailers.Youtube.First().Source;
            else
                Trailer.Text = string.Empty;

            Country selCountry =
                movieReleases.Countries.Single(country => country.Iso_3166_1.ToLowerInvariant() == selectedCertCountry) ??
                movieReleases.Countries.Single(country => country.Iso_3166_1.ToLowerInvariant() == "us");

            MovieDBCertCountry certCountry =
                MovieDBCertCountries.CountryList.Single(country => country.CountryName == selectedCertCountry);

            MPAARating.Text = certCountry.Prefix + selCountry.Certification;

            // loading image sizes
            string posterOriginal = client.Config.Images.PosterSizes.Last();

            string posterPreview = client.Config.Images.PosterSizes.Count >= 2
                                       ? client.Config.Images.PosterSizes[client.Config.Images.PosterSizes.Count - 2]
                                       : client.Config.Images.PosterSizes.Last();

            string backdropOriginal = client.Config.Images.BackdropSizes.Last();

            string backdropPreview = client.Config.Images.BackdropSizes.Count >= 3
                                         ? client.Config.Images.BackdropSizes[
                                             client.Config.Images.BackdropSizes.Count - 3]
                                         : client.Config.Images.BackdropSizes.Last();

            // remove duplicate entries
            imageList.Backdrops.RemoveAt(imageList.Backdrops.FindIndex(data => data.FilePath == searchResult.BackdropPath));
            imageList.Posters.RemoveAt(imageList.Posters.FindIndex(data => data.FilePath == searchResult.PosterPath));

            // create image lists
            _postersList.Add(new MovieDBPosterImage
                {
                    Title = "Default",
                    UrlOriginal = client.GetImageUrl(posterOriginal, searchResult.PosterPath).AbsoluteUri,
                    UrlPreview = client.GetImageUrl(posterPreview, searchResult.PosterPath).AbsoluteUri
                });
            _backdropsList.Add(new MovieDBImageInfo
                {
                    Title = "Default",
                    UrlOriginal = client.GetImageUrl(backdropOriginal, searchResult.BackdropPath).AbsoluteUri,
                    UrlPreview = client.GetImageUrl(backdropPreview, searchResult.BackdropPath).AbsoluteUri
                });

            int cnt = 1;
            foreach (ImageData poster in imageList.Posters)
            {
                _postersList.Add(new MovieDBPosterImage
                    {
                        Title = "Online image " + cnt,
                        UrlOriginal = client.GetImageUrl(posterOriginal, poster.FilePath).AbsoluteUri,
                        UrlPreview = client.GetImageUrl(posterPreview, poster.FilePath).AbsoluteUri
                    });
                cnt++;
            }
            PosterList.ItemsSource = _postersList;
            PosterList.SelectedIndex = 0;

            cnt = 1;
            foreach (ImageData backdrop in imageList.Backdrops)
            {
                _backdropsList.Add(new MovieDBImageInfo
                {
                    Title = "Online image " + cnt,
                    UrlOriginal = client.GetImageUrl(backdropOriginal, backdrop.FilePath).AbsoluteUri,
                    UrlPreview = client.GetImageUrl(backdropPreview, backdrop.FilePath).AbsoluteUri
                });
                cnt++;
            }
            BackdropList.ItemsSource = _backdropsList;
            BackdropList.SelectedIndex = 0;

            foreach (Cast cast in movieCasts.Cast)
            {
                _castList.Casts.Add(new MovieDBCast
                    {
                        Name = cast.Name,
                        Role = cast.Character,
                        Thumbnail = client.GetImageUrl("original", cast.ProfilePath).AbsoluteUri
                    });
            }
            CastListView.ItemsSource = _castList.Casts;
        }
Ejemplo n.º 21
0
        public void ClientRateLimitTest()
        {
            const int id = IdHelper.AGoodDayToDieHard;

            TMDbClient client = new TMDbClient(TestConfig.APIKey);
            client.MaxRetryCount = 0;

            try
            {
                Parallel.For(0, 100, i =>
                {
                    try
                    {
                        client.GetMovie(id).Wait();
                    }
                    catch (AggregateException ex)
                    {
                        // Unpack the InnerException
                        throw ex.InnerException;
                    }
                });
            }
            catch (AggregateException ex)
            {
                // Unpack the InnerException
                throw ex.InnerException;
            }

            Assert.Fail();
        }