public static void LinkAniDBMovieDB(int animeID, int movieDBID, bool fromWebCache) { // check if we have this information locally // if not download it now MovieDB_MovieRepository repMovies = new MovieDB_MovieRepository(); MovieDB_Movie movie = repMovies.GetByOnlineID(movieDBID); if (movie == null) { // we download the series info here just so that we have the basic info in the // database before the queued task runs later UpdateMovieInfo(movieDBID, false); movie = repMovies.GetByOnlineID(movieDBID); if (movie == null) { return; } } // download and update series info and images UpdateMovieInfo(movieDBID, true); CrossRef_AniDB_OtherRepository repCrossRef = new CrossRef_AniDB_OtherRepository(); CrossRef_AniDB_Other xref = repCrossRef.GetByAnimeIDAndType(animeID, CrossRefType.MovieDB); if (xref == null) { xref = new CrossRef_AniDB_Other(); } xref.AnimeID = animeID; if (fromWebCache) { xref.CrossRefSource = (int)CrossRefSource.WebCache; } else { xref.CrossRefSource = (int)CrossRefSource.User; } xref.CrossRefType = (int)CrossRefType.MovieDB; xref.CrossRefID = movieDBID.ToString(); repCrossRef.Save(xref); AniDB_Anime.UpdateStatsByAnimeID(animeID); logger.Trace("Changed moviedb association: {0}", animeID); CommandRequest_WebCacheSendXRefAniDBOther req = new CommandRequest_WebCacheSendXRefAniDBOther(xref.CrossRef_AniDB_OtherID); req.Save(); }
public MovieDB_Movie GetMovieDB_Movie(ISession session) { if (CrossRefType != (int)JMMServer.CrossRefType.MovieDB) { return(null); } MovieDB_MovieRepository repMovieDBMovie = new MovieDB_MovieRepository(); return(repMovieDBMovie.GetByOnlineID(session, int.Parse(CrossRefID))); }
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) { // 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)) { repPosters.Delete(poster.MovieDB_PosterID); } } } } // download the fanart if (ServerSettings.MovieDB_AutoFanart) { foreach (MovieDB_Fanart fanart in repFanart.GetByMovieID(session, 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)) { repFanart.Delete(fanart.MovieDB_FanartID); } } } } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_MovieDBSearchAnime: {0}", AnimeID); try { using (var session = JMMService.SessionFactory.OpenSession()) { // first check if the user wants to use the web cache if (ServerSettings.WebCache_TvDB_Get) { try { MovieDB_MovieRepository repMovies = new MovieDB_MovieRepository(); JMMServer.Providers.Azure.CrossRef_AniDB_Other crossRef = JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBOther(AnimeID, CrossRefType.MovieDB); if (crossRef != null) { int movieID = int.Parse(crossRef.CrossRefID); MovieDB_Movie movie = repMovies.GetByOnlineID(session, movieID); if (movie == null) { // update the info from online MovieDBHelper.UpdateMovieInfo(session, movieID, true); movie = repMovies.GetByOnlineID(movieID); } if (movie != null) { // since we are using the web cache result, let's save it MovieDBHelper.LinkAniDBMovieDB(AnimeID, movieID, true); return; } } } catch (Exception) { } } string searchCriteria = ""; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(session, AnimeID); if (anime == null) { return; } searchCriteria = anime.MainTitle; // if not wanting to use web cache, or no match found on the web cache go to TvDB directly List <MovieDB_Movie_Result> results = MovieDBHelper.Search(searchCriteria); logger.Trace("Found {0} moviedb results for {1} on TheTvDB", results.Count, searchCriteria); if (ProcessSearchResults(session, results, searchCriteria)) { return; } if (results.Count == 0) { foreach (AniDB_Anime_Title title in anime.GetTitles(session)) { if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper()) { continue; } if (searchCriteria.ToUpper() == title.Title.ToUpper()) { continue; } results = MovieDBHelper.Search(title.Title); logger.Trace("Found {0} moviedb results for search on {1}", results.Count, title.Title); if (ProcessSearchResults(session, results, title.Title)) { return; } } } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex.ToString()); return; } }
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++; } } } } }