Ejemplo n.º 1
0
		public void Save(MovieDB_Poster obj)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				Save(session, obj);
			}
		}
Ejemplo n.º 2
0
		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++;
						}
					}
				}
			}
		}
Ejemplo n.º 3
0
		public void Save(ISession session, MovieDB_Poster obj)
		{
			// populate the database
			using (var transaction = session.BeginTransaction())
			{
				session.SaveOrUpdate(obj);
				transaction.Commit();
			}
		}
Ejemplo n.º 4
0
        public Contract_AniDB_Anime_DefaultImage ToContract(ISession session)
        {
            Contract_AniDB_Anime_DefaultImage contract = new Contract_AniDB_Anime_DefaultImage();

            contract.AniDB_Anime_DefaultImageID = this.AniDB_Anime_DefaultImageID;
            contract.AnimeID         = this.AnimeID;
            contract.ImageParentID   = this.ImageParentID;
            contract.ImageParentType = this.ImageParentType;
            contract.ImageType       = this.ImageType;

            contract.MovieFanart  = null;
            contract.MoviePoster  = null;
            contract.TVPoster     = null;
            contract.TVFanart     = null;
            contract.TVWideBanner = null;
            contract.TraktFanart  = null;
            contract.TraktPoster  = null;

            JMMImageType imgType = (JMMImageType)ImageParentType;

            switch (imgType)
            {
            case JMMImageType.TvDB_Banner:

                TvDB_ImageWideBannerRepository repBanners = new TvDB_ImageWideBannerRepository();
                TvDB_ImageWideBanner           banner     = repBanners.GetByID(session, ImageParentID);
                if (banner != null)
                {
                    contract.TVWideBanner = banner.ToContract();
                }

                break;

            case JMMImageType.TvDB_Cover:

                TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository();
                TvDB_ImagePoster           poster     = repPosters.GetByID(session, ImageParentID);
                if (poster != null)
                {
                    contract.TVPoster = poster.ToContract();
                }

                break;

            case JMMImageType.TvDB_FanArt:

                TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
                TvDB_ImageFanart           fanart    = repFanart.GetByID(session, ImageParentID);
                if (fanart != null)
                {
                    contract.TVFanart = fanart.ToContract();
                }

                break;

            case JMMImageType.MovieDB_Poster:

                MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
                MovieDB_Poster           moviePoster     = repMoviePosters.GetByID(session, ImageParentID);
                if (moviePoster != null)
                {
                    contract.MoviePoster = moviePoster.ToContract();
                }

                break;

            case JMMImageType.MovieDB_FanArt:

                MovieDB_FanartRepository repMovieFanart = new MovieDB_FanartRepository();
                MovieDB_Fanart           movieFanart    = repMovieFanart.GetByID(session, ImageParentID);
                if (movieFanart != null)
                {
                    contract.MovieFanart = movieFanart.ToContract();
                }

                break;

            case JMMImageType.Trakt_Fanart:

                Trakt_ImageFanartRepository repTraktFanart = new Trakt_ImageFanartRepository();
                Trakt_ImageFanart           traktFanart    = repTraktFanart.GetByID(session, ImageParentID);
                if (traktFanart != null)
                {
                    contract.TraktFanart = traktFanart.ToContract();
                }

                break;

            case JMMImageType.Trakt_Poster:

                Trakt_ImagePosterRepository repTraktPoster = new Trakt_ImagePosterRepository();
                Trakt_ImagePoster           traktPoster    = repTraktPoster.GetByID(session, ImageParentID);
                if (traktPoster != null)
                {
                    contract.TraktPoster = traktPoster.ToContract();
                }

                break;
            }

            return(contract);
        }
Ejemplo n.º 5
0
        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);
                        }
                    }
                }
            }
        }