Ejemplo n.º 1
0
 private TvShowRepo()
 {
     _tmdbClient = new TMDbClient(Settings.TMDB_API_KEY);
     _tmdbClient.GetConfig();
     _strikeClient = new Strike();
     _jsonStorage = new JsonStorage();
 }
Ejemplo n.º 2
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.º 3
0
 public TMDb()
 {
     try {
         client = new TMDbClient(API_KEY);
         client.GetConfig();
         //client.MaxRetryCount = 15;
     } catch(Exception) { }
 }
Ejemplo n.º 4
0
        public TMDbManager()
        {
            TMDbClient = new TMDbClient(ConfigurationManager.AppSettings["TheMovieDB"]);
            MongoManager = new MongoDBManager();

            TMDbClient.GetConfig();
            TMDbConfig config = TMDbClient.Config;
            ImageBase = config.Images.BaseUrl + config.Images.PosterSizes.Where(o => o == "w342").First();
            Client = new TMDbClient(ConfigurationManager.AppSettings["TheMovieDB"]);
        }
Ejemplo n.º 5
0
        public void ClientConstructorUrlTest()
        {
            TMDbClient clientA = new TMDbClient(TestConfig.APIKey, false, "http://api.themoviedb.org");
            clientA.GetConfig();

            TMDbClient clientB = new TMDbClient(TestConfig.APIKey, true, "http://api.themoviedb.org");
            clientB.GetConfig();

            TMDbClient clientC = new TMDbClient(TestConfig.APIKey, false, "https://api.themoviedb.org");
            clientC.GetConfig();

            TMDbClient clientD = new TMDbClient(TestConfig.APIKey, true, "https://api.themoviedb.org");
            clientD.GetConfig();
        }
Ejemplo n.º 6
0
 public EPG_Control_V3(string SourceDirectory)
 {
   this.sourceDirectory = SourceDirectory;
   currentTime = DateTime.Now;
   lastTime = DateTime.Now.AddHours(4);
   incrementalTime = new System.TimeSpan(0, 30, 0);
   epg_Data = new EPG_Program_Channel();
   epg_Times = new EPG_Time();
   epg_SelectedItem = new EPG_SelectedItem();
   tvdbHandler = new TvdbHandler(new XmlCacheProvider("C:\\test"), "572328F18DC4374A");
   tvdbHandler.InitCache();
   client = new TMDbClient("ecaa9ae8c8346269b53c80e2a61aa0ea");
   client.GetConfig();
   epg_ChannelIndex = 0;
   epg_ProgramIndex = 0;
 }
Ejemplo n.º 7
0
 public EPG_Control_V4(string SourceDirectory)
 {
   this.sourceDirectory = SourceDirectory;;
   if (DateTime.Now.Minute < 30)
     currentTime = DateTime.Now.AddMinutes(-DateTime.Now.Minute);
   else
     currentTime = DateTime.Now.AddMinutes(30 - DateTime.Now.Minute);
   currentSelectedTime = currentTime;
   lastTime = currentTime.AddHours(2);
   currentChannel = 0;
   lastChannel = 2;
   incrementalTime = new System.TimeSpan(0, 30, 0);
   epg_Data = new EPG_Program_Channel();
   epg_Times = new EPG_Time();
   epg_SelectedItem = new EPG_SelectedItem();
   tvdbHandler = new TvdbHandler(new XmlCacheProvider("C:\\test"), "572328F18DC4374A");
   tvdbHandler.InitCache();
   client = new TMDbClient("ecaa9ae8c8346269b53c80e2a61aa0ea");
   client.GetConfig();
 }
Ejemplo n.º 8
0
    public EPG_Control_V2(string SourceDirectory)
    {
      this.sourceDirectory = SourceDirectory;
      epg_Data = new EPG_Program_Channel();
      epg_Times = new EPG_Time();
      epg_SelectedItem = new EPG_SelectedItem();
      tvdbHandler = new TvdbHandler(new XmlCacheProvider("C:\\test"), "572328F18DC4374A");
      tvdbHandler.InitCache();
      client = new TMDbClient("ecaa9ae8c8346269b53c80e2a61aa0ea");
      client.GetConfig();
      epg_ChannelIndex = 0;
      epg_ProgramIndex = 0;
      incTimeSpan = new TimeSpan(0, 30, 0);
      int ts = 0;

      if (DateTime.Now.Minute < 30)      
        ts = -(DateTime.Now.Minute);      
      else      
        ts = 30 - DateTime.Now.Minute;        
      
      currentTime = DateTime.Now.AddMinutes(ts);
      lastTime = currentTime.AddHours(2);
    }
Ejemplo n.º 9
0
 public Netflix_ContentVM()
 {
   NFGenreSelectedIndex = 0;
   NFMovieSelectedIndex = 0;
   client = new TMDbClient("ecaa9ae8c8346269b53c80e2a61aa0ea");
   client.GetConfig();
   Messenger.Default.Register<string>(this, "LoadStatus", successfulLoad);
   NetflixUpdater NFU = new NetflixUpdater(); //NetflixUpdater checks for xml file and loads or updates if older than 7 days      
 }
Ejemplo n.º 10
0
        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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
0
 public TmdbMoviesService()
 {
     var config = new Configuration();
     _client = new TMDbClient(config.Get<string>("TmdbApiKey"));
     _client.GetConfig();
 }
Ejemplo n.º 16
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.º 17
0
        /// <summary>
        /// Match the series information by Episode name
        /// </summary>
        private static bool MatchByEpisodeName(TMDbClient client, VideoTags videoTags, TvShow tvShow)
        {
            if (String.IsNullOrWhiteSpace(videoTags.SubTitle))
                return false; //Nothing to match here


            // Cycle through all Seasons and Episodes looking for a match
            for (int sNo = 0; sNo <= tvShow.NumberOfSeasons; sNo++)
            {
                TvSeason season = client.GetTvSeason(tvShow.Id, sNo);
                if (season == null || season.Episodes == null)
                    continue;

                for (int eNo = 0; eNo <= season.Episodes.Count; eNo++)
                {
                    TvEpisode episode = client.GetTvEpisode(tvShow.Id, sNo, eNo);
                    if (episode == null)
                        continue;

                    string episodeName = episode.Name;

                    if (!String.IsNullOrWhiteSpace(episodeName))
                    {
                        if (String.Compare(videoTags.SubTitle.Trim(), episodeName.Trim(), CultureInfo.InvariantCulture, (CompareOptions.IgnoreSymbols | CompareOptions.IgnoreCase)) == 0) // Compare the episode names (case / special characters / whitespace can change very often)
                        {
                            int episodeNo = episode.EpisodeNumber;
                            int seasonNo = season.SeasonNumber;
                            string episodeOverview = episode.Overview;
                            string overview = season.Overview;
                            string tvdbID = (episode.ExternalIds != null ? (episode.ExternalIds.TvdbId != null ? episode.ExternalIds.TvdbId.ToString() : "") : "");
                            string imdbID = (episode.ExternalIds != null ? episode.ExternalIds.ImdbId : "");
                            string tmdbID = (tvShow.Id != 0 ? tvShow.Id.ToString() : "");
                            string network = (tvShow.Networks != null ? String.Join(";", tvShow.Networks.Select(s => s.Name)) : "");
                            DateTime premiereDate = GlobalDefs.NO_BROADCAST_TIME;
                            if (tvShow.FirstAirDate != null)
                                premiereDate = (DateTime)tvShow.FirstAirDate;
                            List<string> genres = (tvShow.Genres != null ? tvShow.Genres.Select(s => s.Name).ToList() : new List<string>());
                            DateTime firstAired = (episode.AirDate != null ? episode.AirDate : GlobalDefs.NO_BROADCAST_TIME);
                            string mediaCredits = (tvShow.Credits != null ? ((tvShow.Credits.Cast != null) ? String.Join(";", tvShow.Credits.Cast.Select(s => s.Name)) : "") : "");

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

                            if ((episodeNo != 0) && (videoTags.Episode == 0)) videoTags.Episode = episodeNo;
                            if ((seasonNo != 0) && (videoTags.Season == 0)) videoTags.Season = seasonNo;
                            if (!String.IsNullOrWhiteSpace(episodeOverview) && String.IsNullOrWhiteSpace(videoTags.Description)) videoTags.Description = episodeOverview;
                            else if (!String.IsNullOrWhiteSpace(overview) && (String.IsNullOrWhiteSpace(videoTags.Description))) videoTags.Description = overview;
                            if (!String.IsNullOrWhiteSpace(tvdbID) && String.IsNullOrWhiteSpace(videoTags.tvdbId)) videoTags.tvdbId = tvdbID;
                            if (!String.IsNullOrWhiteSpace(imdbID) && String.IsNullOrWhiteSpace(videoTags.imdbId)) videoTags.imdbId = imdbID;
                            if (!String.IsNullOrWhiteSpace(tmdbID) && String.IsNullOrWhiteSpace(videoTags.tmdbId)) videoTags.tmdbId = tmdbID;
                            if (!String.IsNullOrWhiteSpace(network) && String.IsNullOrWhiteSpace(videoTags.Network)) videoTags.Network = network;
                            if (!String.IsNullOrWhiteSpace(mediaCredits) && String.IsNullOrWhiteSpace(videoTags.MediaCredits)) videoTags.MediaCredits = mediaCredits;
                            if (premiereDate > GlobalDefs.NO_BROADCAST_TIME)
                                if ((videoTags.SeriesPremiereDate <= GlobalDefs.NO_BROADCAST_TIME) || (videoTags.SeriesPremiereDate.Date > premiereDate.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 TVDB dates, TVDB Dates are more reliable than video metadata usually
                                    videoTags.SeriesPremiereDate = premiereDate; // TVDB stores time in network (local) timezone
                            if (genres.Count > 0)
                            {
                                if (videoTags.Genres != null)
                                {
                                    if (videoTags.Genres.Length == 0)
                                        videoTags.Genres = genres.ToArray();
                                }
                                else
                                    videoTags.Genres = genres.ToArray();
                            }

                            if (firstAired > GlobalDefs.NO_BROADCAST_TIME)
                                if ((videoTags.OriginalBroadcastDateTime <= GlobalDefs.NO_BROADCAST_TIME) || (videoTags.OriginalBroadcastDateTime.Date > firstAired.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 TVDB dates, TVDB Dates are more reliable than video metadata usually
                                    videoTags.OriginalBroadcastDateTime = firstAired; // TVDB stores time in network (local) timezone

                            return true; // Found a match got all the data, we're done here
                        }
                    }
                }
            }

            return false; // nothing matches
        }