public static void SaveMovieToDatabase(MovieDB_Movie_Result searchResult, bool saveImages) { using (var session = JMMService.SessionFactory.OpenSession()) { SaveMovieToDatabase(session, searchResult, saveImages); } }
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 void SaveMovieToDatabase(MovieDB_Movie_Result searchResult, bool saveImages) { using (var session = JMMService.SessionFactory.OpenSession()) { SaveMovieToDatabase(session, searchResult, saveImages); } }
public void Populate(MovieDB_Movie_Result searchResult) { this.MovieId = searchResult.MovieID; this.MovieName = searchResult.MovieName; this.OriginalName = searchResult.OriginalName; this.Overview = searchResult.Overview; }
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 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 void UpdateMovieInfo(ISession session, int movieID, bool saveImages) { try { string url = string.Format(InfoURL, apiKey, movieID); // Search for a movie string xmlSearch = Utils.DownloadWebPage(url); XmlDocument docSearchResult = new XmlDocument(); docSearchResult.LoadXml(xmlSearch); bool hasData = docSearchResult["OpenSearchDescription"]["movies"].HasChildNodes; if (hasData) { XmlNodeList movies = docSearchResult["OpenSearchDescription"]["movies"].GetElementsByTagName("movie"); XmlNode movie = movies[0]; MovieDB_Movie_Result searchResult = new MovieDB_Movie_Result(); if (searchResult.Populate(movie)) { // save to the DB SaveMovieToDatabase(session, searchResult, saveImages); } } } catch (Exception ex) { logger.ErrorException("Error in ParseBanners: " + ex.ToString(), ex); } }
private static void SaveMovieToDatabase(ISession session, MovieDB_Movie_Result searchResult, bool saveImages) { MovieDB_MovieRepository repMovies = new MovieDB_MovieRepository(); MovieDB_FanartRepository repFanart = new MovieDB_FanartRepository(); MovieDB_PosterRepository repPosters = new MovieDB_PosterRepository(); // save to the DB MovieDB_Movie movie = repMovies.GetByOnlineID(searchResult.MovieID); if (movie == null) movie = new MovieDB_Movie(); movie.Populate(searchResult); repMovies.Save(session, movie); if (!saveImages) return; int numFanartDownloaded = 0; int numPostersDownloaded = 0; foreach (MovieDB_Image_Result img in searchResult.Images) { if (img.ImageType.Equals("poster", StringComparison.InvariantCultureIgnoreCase)) { MovieDB_Poster poster = repPosters.GetByOnlineID(session, img.ImageID, img.ImageSize); if (poster == null) poster = new MovieDB_Poster(); poster.Populate(img, movie.MovieId); repPosters.Save(session, poster); if (ServerSettings.MovieDB_AutoPosters && numPostersDownloaded < ServerSettings.MovieDB_AutoPostersAmount) { // download the image if (!string.IsNullOrEmpty(poster.FullImagePath) && !File.Exists(poster.FullImagePath)) { CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(poster.MovieDB_PosterID, JMMImageType.MovieDB_Poster, false); cmd.Save(session); numPostersDownloaded++; } } } else { // fanart (backdrop) MovieDB_Fanart fanart = repFanart.GetByOnlineID(session, img.ImageID, img.ImageSize); if (fanart == null) fanart = new MovieDB_Fanart(); fanart.Populate(img, movie.MovieId); repFanart.Save(session, fanart); if (ServerSettings.MovieDB_AutoFanart && numFanartDownloaded < ServerSettings.MovieDB_AutoPostersAmount) { // download the image if (!string.IsNullOrEmpty(fanart.FullImagePath) && !File.Exists(fanart.FullImagePath)) { CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(fanart.MovieDB_FanartID, JMMImageType.MovieDB_FanArt, false); cmd.Save(session); numFanartDownloaded++; } } } } }
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 List <MovieDB_Movie_Result> Search(string criteria) { List <MovieDB_Movie_Result> results = new List <MovieDB_Movie_Result>(); try { string url = string.Format(SearchURL, apiKey, criteria.Trim()); // Search for a movie string xmlSearch = Utils.DownloadWebPage(url); XmlDocument docSearchResult = new XmlDocument(); docSearchResult.LoadXml(xmlSearch); bool hasData = docSearchResult["OpenSearchDescription"]["movies"].HasChildNodes; if (hasData) { XmlNodeList movies = docSearchResult["OpenSearchDescription"]["movies"].GetElementsByTagName("movie"); foreach (XmlNode movieNode in movies) { MovieDB_Movie_Result searchResult = new MovieDB_Movie_Result(); if (searchResult.Populate(movieNode)) { results.Add(searchResult); SaveMovieToDatabase(searchResult, false); } } } } catch (Exception ex) { logger.Error("Error in MovieDB Search: " + ex.Message); } return(results); }
public static void SaveMovieToDatabase(ISession session, MovieDB_Movie_Result searchResult, bool saveImages) { MovieDB_MovieRepository repMovies = new MovieDB_MovieRepository(); MovieDB_FanartRepository repFanart = new MovieDB_FanartRepository(); MovieDB_PosterRepository repPosters = new MovieDB_PosterRepository(); // save to the DB MovieDB_Movie movie = repMovies.GetByOnlineID(searchResult.MovieID); if (movie == null) { movie = new MovieDB_Movie(); } movie.Populate(searchResult); repMovies.Save(session, 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 = repPosters.GetByOnlineID(session, img.URL); if (poster == null) { poster = new MovieDB_Poster(); } poster.Populate(img, movie.MovieId); repPosters.Save(session, poster); if (!string.IsNullOrEmpty(poster.FullImagePath) && File.Exists(poster.FullImagePath)) { numPostersDownloaded++; } } else { // fanart (backdrop) MovieDB_Fanart fanart = repFanart.GetByOnlineID(session, img.URL); if (fanart == null) { fanart = new MovieDB_Fanart(); } fanart.Populate(img, movie.MovieId); repFanart.Save(session, fanart); if (!string.IsNullOrEmpty(fanart.FullImagePath) && File.Exists(fanart.FullImagePath)) { numFanartDownloaded++; } } } // download the posters if (ServerSettings.MovieDB_AutoPosters) { foreach (MovieDB_Poster poster in repPosters.GetByMovieID(session, movie.MovieId)) { if (numPostersDownloaded >= ServerSettings.MovieDB_AutoPostersAmount) { break; } // download the image if (!string.IsNullOrEmpty(poster.FullImagePath) && !File.Exists(poster.FullImagePath)) { CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(poster.MovieDB_PosterID, JMMImageType.MovieDB_Poster, false); cmd.Save(session); numPostersDownloaded++; } } } // download the fanart if (ServerSettings.MovieDB_AutoFanart) { foreach (MovieDB_Fanart fanart in repFanart.GetByMovieID(session, movie.MovieId)) { if (numFanartDownloaded >= ServerSettings.MovieDB_AutoFanartAmount) { break; } // download the image if (!string.IsNullOrEmpty(fanart.FullImagePath) && !File.Exists(fanart.FullImagePath)) { CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(fanart.MovieDB_FanartID, JMMImageType.MovieDB_FanArt, false); cmd.Save(session); numFanartDownloaded++; } } } }
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.FullImagePath) && File.Exists(poster.FullImagePath)) 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.FullImagePath) && File.Exists(fanart.FullImagePath)) 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.FullImagePath) && !File.Exists(poster.FullImagePath)) { 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.FullImagePath)) { 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.FullImagePath) && !File.Exists(fanart.FullImagePath)) { 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.FullImagePath)) { RepoFactory.MovieDB_Fanart.Delete(fanart.MovieDB_FanartID); } } } } }
public static void UpdateMovieInfo(ISession session, int movieID, bool saveImages) { try { string url = string.Format(InfoURL, apiKey, movieID); // Search for a movie string xmlSearch = Utils.DownloadWebPage(url); XmlDocument docSearchResult = new XmlDocument(); docSearchResult.LoadXml(xmlSearch); bool hasData = docSearchResult["OpenSearchDescription"]["movies"].HasChildNodes; if (hasData) { XmlNodeList movies = docSearchResult["OpenSearchDescription"]["movies"].GetElementsByTagName("movie"); XmlNode movie = movies[0]; MovieDB_Movie_Result searchResult = new MovieDB_Movie_Result(); if (searchResult.Populate(movie)) { // save to the DB SaveMovieToDatabase(session, searchResult, saveImages); } } } catch (Exception ex) { logger.ErrorException("Error in ParseBanners: " + ex.ToString(), ex); } }
public static List<MovieDB_Movie_Result> Search(string criteria) { List<MovieDB_Movie_Result> results = new List<MovieDB_Movie_Result>(); try { string url = string.Format(SearchURL, apiKey, criteria.Trim()); // Search for a movie string xmlSearch = Utils.DownloadWebPage(url); XmlDocument docSearchResult = new XmlDocument(); docSearchResult.LoadXml(xmlSearch); bool hasData = docSearchResult["OpenSearchDescription"]["movies"].HasChildNodes; if (hasData) { XmlNodeList movies = docSearchResult["OpenSearchDescription"]["movies"].GetElementsByTagName("movie"); foreach (XmlNode movieNode in movies) { MovieDB_Movie_Result searchResult = new MovieDB_Movie_Result(); if (searchResult.Populate(movieNode)) { results.Add(searchResult); SaveMovieToDatabase(searchResult, false); } } } } catch (Exception ex) { logger.Error("Error in MovieDB Search: " + ex.Message); } return results; }
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 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 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; }
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.FullImagePath) && File.Exists(poster.FullImagePath)) { 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.FullImagePath) && File.Exists(fanart.FullImagePath)) { 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.FullImagePath) && !File.Exists(poster.FullImagePath)) { 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.FullImagePath)) { 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.FullImagePath) && !File.Exists(fanart.FullImagePath)) { 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.FullImagePath)) { RepoFactory.MovieDB_Fanart.Delete(fanart.MovieDB_FanartID); } } } } }
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; }