public static void SaveMovieToDatabase(MovieDB_Movie_Result searchResult, bool saveImages, bool isTrakt) { using (var session = DatabaseFactory.SessionFactory.OpenSession()) { SaveMovieToDatabase(session, searchResult, saveImages, isTrakt); } }
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); }
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, false); } } catch (Exception ex) { logger.Error("Error in MovieDB Search: " + ex.Message); } return(results); }
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, false); } catch (Exception ex) { logger.Error(ex, "Error in ParseBanners: " + ex.ToString()); } }
public static void SaveMovieToDatabase(ISession session, MovieDB_Movie_Result searchResult, bool saveImages, bool isTrakt) { ISessionWrapper sessionWrapper = session.Wrap(); // save to the DB MovieDB_Movie movie = RepoFactory.MovieDb_Movie.GetByOnlineID(searchResult.MovieID); if (movie == null) { movie = new MovieDB_Movie(); } movie.Populate(searchResult); // Only save movie info if source is not trakt, this presents adding tv shows as movies // Needs better fix later on if (!isTrakt) { RepoFactory.MovieDb_Movie.Save(movie); } if (!saveImages) { return; } int numFanartDownloaded = 0; int numPostersDownloaded = 0; // save data to the DB and determine the number of images we already have foreach (MovieDB_Image_Result img in searchResult.Images) { if (img.ImageType.Equals("poster", StringComparison.InvariantCultureIgnoreCase)) { MovieDB_Poster poster = RepoFactory.MovieDB_Poster.GetByOnlineID(session, img.URL); if (poster == null) { poster = new MovieDB_Poster(); } poster.Populate(img, movie.MovieId); RepoFactory.MovieDB_Poster.Save(poster); if (!string.IsNullOrEmpty(poster.GetFullImagePath()) && File.Exists(poster.GetFullImagePath())) { numPostersDownloaded++; } } else { // fanart (backdrop) MovieDB_Fanart fanart = RepoFactory.MovieDB_Fanart.GetByOnlineID(session, img.URL); if (fanart == null) { fanart = new MovieDB_Fanart(); } fanart.Populate(img, movie.MovieId); RepoFactory.MovieDB_Fanart.Save(fanart); if (!string.IsNullOrEmpty(fanart.GetFullImagePath()) && File.Exists(fanart.GetFullImagePath())) { numFanartDownloaded++; } } } // download the posters if (ServerSettings.MovieDB_AutoPosters || isTrakt) { foreach (MovieDB_Poster poster in RepoFactory.MovieDB_Poster.GetByMovieID(sessionWrapper, movie.MovieId) ) { if (numPostersDownloaded < ServerSettings.MovieDB_AutoPostersAmount) { // download the image if (!string.IsNullOrEmpty(poster.GetFullImagePath()) && !File.Exists(poster.GetFullImagePath())) { CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(poster.MovieDB_PosterID, JMMImageType.MovieDB_Poster, false); cmd.Save(session); numPostersDownloaded++; } } else { //The MovieDB_AutoPostersAmount should prevent from saving image info without image // we should clean those image that we didn't download because those dont exists in local repo // first we check if file was downloaded if (!File.Exists(poster.GetFullImagePath())) { RepoFactory.MovieDB_Poster.Delete(poster.MovieDB_PosterID); } } } } // download the fanart if (ServerSettings.MovieDB_AutoFanart || isTrakt) { foreach (MovieDB_Fanart fanart in RepoFactory.MovieDB_Fanart.GetByMovieID(sessionWrapper, movie.MovieId) ) { if (numFanartDownloaded < ServerSettings.MovieDB_AutoFanartAmount) { // download the image if (!string.IsNullOrEmpty(fanart.GetFullImagePath()) && !File.Exists(fanart.GetFullImagePath())) { CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(fanart.MovieDB_FanartID, JMMImageType.MovieDB_FanArt, false); cmd.Save(session); numFanartDownloaded++; } } else { //The MovieDB_AutoFanartAmount should prevent from saving image info without image // we should clean those image that we didn't download because those dont exists in local repo // first we check if file was downloaded if (!File.Exists(fanart.GetFullImagePath())) { RepoFactory.MovieDB_Fanart.Delete(fanart.MovieDB_FanartID); } } } } }
public static void SaveMovieToDatabase(MovieDB_Movie_Result searchResult, bool saveImages, bool isTrakt) { // save to the DB MovieDB_Movie movie; using (var upd = Repo.Instance.MovieDb_Movie.BeginAddOrUpdate(() => Repo.Instance.MovieDb_Movie.GetByMovieID(searchResult.MovieID).FirstOrDefault())) { upd.Entity.Populate_RA(searchResult); // Only save movie info if source is not trakt, this presents adding tv shows as movies // Needs better fix later on if (!isTrakt) { movie = upd.Commit(); } else { movie = upd.Entity; } } if (!saveImages) { return; } int numFanartDownloaded = 0; int numPostersDownloaded = 0; // save data to the DB and determine the number of images we already have foreach (MovieDB_Image_Result img in searchResult.Images) { if (img.ImageType.Equals("poster", StringComparison.InvariantCultureIgnoreCase)) { MovieDB_Poster poster; using (var upd = Repo.Instance.MovieDB_Poster.BeginAddOrUpdate(() => Repo.Instance.MovieDB_Poster.GetByOnlineID(img.URL))) { upd.Entity.Populate_RA(img, movie.MovieId); poster = upd.Commit(); } if (!string.IsNullOrEmpty(poster.GetFullImagePath()) && File.Exists(poster.GetFullImagePath())) { numPostersDownloaded++; } } else { // fanart (backdrop) MovieDB_Fanart fanart; using (var upd = Repo.Instance.MovieDB_Fanart.BeginAddOrUpdate(() => Repo.Instance.MovieDB_Fanart.GetByOnlineID(img.URL))) { upd.Entity.Populate_RA(img, movie.MovieId); fanart = upd.Commit(); } if (!string.IsNullOrEmpty(fanart.GetFullImagePath()) && File.Exists(fanart.GetFullImagePath())) { numFanartDownloaded++; } } } // download the posters if (ServerSettings.Instance.MovieDb.AutoPosters || isTrakt) { foreach (MovieDB_Poster poster in Repo.Instance.MovieDB_Poster.GetByMovieID(movie.MovieId)) { if (numPostersDownloaded < ServerSettings.Instance.MovieDb.AutoPostersAmount) { // download the image if (!string.IsNullOrEmpty(poster.GetFullImagePath()) && !File.Exists(poster.GetFullImagePath())) { CommandQueue.Queue.Instance.Add(new CmdImageDownload(poster.MovieDB_PosterID, ImageEntityType.MovieDB_Poster, false)); numPostersDownloaded++; } } else { //The MovieDB_AutoPostersAmount should prevent from saving image info without image // we should clean those image that we didn't download because those dont exists in local repo // first we check if file was downloaded if (!File.Exists(poster.GetFullImagePath())) { Repo.Instance.MovieDB_Poster.Delete(poster); } } } } // download the fanart if (ServerSettings.Instance.MovieDb.AutoFanart || isTrakt) { foreach (MovieDB_Fanart fanart in Repo.Instance.MovieDB_Fanart.GetByMovieID(movie.MovieId)) { if (numFanartDownloaded < ServerSettings.Instance.MovieDb.AutoFanartAmount) { // download the image if (!string.IsNullOrEmpty(fanart.GetFullImagePath()) && !File.Exists(fanart.GetFullImagePath())) { CommandQueue.Queue.Instance.Add(new CmdImageDownload(fanart.MovieDB_FanartID, ImageEntityType.MovieDB_FanArt, false)); numFanartDownloaded++; } } else { //The MovieDB_AutoFanartAmount should prevent from saving image info without image // we should clean those image that we didn't download because those dont exists in local repo // first we check if file was downloaded if (!File.Exists(fanart.GetFullImagePath())) { Repo.Instance.MovieDB_Fanart.Delete(fanart); } } } } }