Ejemplo n.º 1
0
        private static void FetchConfig(TMDbClient client)
        {
            FileInfo configXml = new FileInfo("config.xml");

            Console.WriteLine("Config file: " + configXml.FullName + ", Exists: " + configXml.Exists);

            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);
            }

            Spacer();
        }
Ejemplo n.º 2
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.º 3
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();
        }