示例#1
0
        public List<Contract_TvDB_ImagePoster> GetAllTvDBPosters(int? tvDBID)
        {
            List<Contract_TvDB_ImagePoster> allImages = new List<Contract_TvDB_ImagePoster>();
            try
            {
                TvDB_ImagePosterRepository repImages = new TvDB_ImagePosterRepository();
                List<TvDB_ImagePoster> allPosters = null;
                if (tvDBID.HasValue)
                    allPosters = repImages.GetBySeriesID(tvDBID.Value);
                else
                    allPosters = repImages.GetAll();

                foreach (TvDB_ImagePoster img in allPosters)
                    allImages.Add(img.ToContract());

                return allImages;

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return allImages;
            }
        }
示例#2
0
文件: Importer.cs 项目: dizzydezz/jmm
		public static void RunImport_GetImages()
		{
			// AniDB posters
			AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
			foreach (AniDB_Anime anime in repAnime.GetAll())
			{
				if (anime.AnimeID == 8580)
					Console.Write("");

				if (string.IsNullOrEmpty(anime.PosterPath)) continue;

				bool fileExists = File.Exists(anime.PosterPath);
				if (!fileExists)
				{
					CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(anime.AniDB_AnimeID, JMMImageType.AniDB_Cover, false);
					cmd.Save();
				}
			}

			// TvDB Posters
			if (ServerSettings.TvDB_AutoPosters)
			{
				TvDB_ImagePosterRepository repTvPosters = new TvDB_ImagePosterRepository();
				Dictionary<int, int> postersCount = new Dictionary<int, int>();

				// build a dictionary of series and how many images exist
				List<TvDB_ImagePoster> allPosters = repTvPosters.GetAll();
				foreach (TvDB_ImagePoster tvPoster in allPosters)
				{
					if (string.IsNullOrEmpty(tvPoster.FullImagePath)) continue;
					bool fileExists = File.Exists(tvPoster.FullImagePath);

					if (fileExists)
					{
						if (postersCount.ContainsKey(tvPoster.SeriesID))
							postersCount[tvPoster.SeriesID] = postersCount[tvPoster.SeriesID] + 1;
						else
							postersCount[tvPoster.SeriesID] = 1;
					}
				}

				foreach (TvDB_ImagePoster tvPoster in allPosters)
				{
					if (string.IsNullOrEmpty(tvPoster.FullImagePath)) continue;
					bool fileExists = File.Exists(tvPoster.FullImagePath);

					int postersAvailable = 0;
					if (postersCount.ContainsKey(tvPoster.SeriesID))
						postersAvailable = postersCount[tvPoster.SeriesID];

					if (!fileExists && postersAvailable < ServerSettings.TvDB_AutoPostersAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvPoster.TvDB_ImagePosterID, JMMImageType.TvDB_Cover, false);
						cmd.Save();
					}
				}
			}

			// TvDB Fanart
			if (ServerSettings.TvDB_AutoFanart)
			{
				Dictionary<int, int> fanartCount = new Dictionary<int, int>();
				TvDB_ImageFanartRepository repTvFanart = new TvDB_ImageFanartRepository();

				List<TvDB_ImageFanart> allFanart = repTvFanart.GetAll();
				foreach (TvDB_ImageFanart tvFanart in allFanart)
				{
					// build a dictionary of series and how many images exist
					if (string.IsNullOrEmpty(tvFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(tvFanart.FullImagePath);

					if (fileExists)
					{
						if (fanartCount.ContainsKey(tvFanart.SeriesID))
							fanartCount[tvFanart.SeriesID] = fanartCount[tvFanart.SeriesID] + 1;
						else
							fanartCount[tvFanart.SeriesID] = 1;
					}
				}

				foreach (TvDB_ImageFanart tvFanart in allFanart)
				{
					if (string.IsNullOrEmpty(tvFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(tvFanart.FullImagePath);

					int fanartAvailable = 0;
					if (fanartCount.ContainsKey(tvFanart.SeriesID))
						fanartAvailable = fanartCount[tvFanart.SeriesID];

					if (!fileExists && fanartAvailable < ServerSettings.TvDB_AutoFanartAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvFanart.TvDB_ImageFanartID, JMMImageType.TvDB_FanArt, false);
						cmd.Save();
						fanartCount[tvFanart.SeriesID] = fanartAvailable + 1;
					}
				}
			}

			// TvDB Wide Banners
			if (ServerSettings.TvDB_AutoWideBanners)
			{
				TvDB_ImageWideBannerRepository repTvBanners = new TvDB_ImageWideBannerRepository();
				Dictionary<int, int> fanartCount = new Dictionary<int, int>();

				// build a dictionary of series and how many images exist
				List<TvDB_ImageWideBanner> allBanners = repTvBanners.GetAll();
				foreach (TvDB_ImageWideBanner tvBanner in allBanners)
				{
					if (string.IsNullOrEmpty(tvBanner.FullImagePath)) continue;
					bool fileExists = File.Exists(tvBanner.FullImagePath);

					if (fileExists)
					{
						if (fanartCount.ContainsKey(tvBanner.SeriesID))
							fanartCount[tvBanner.SeriesID] = fanartCount[tvBanner.SeriesID] + 1;
						else
							fanartCount[tvBanner.SeriesID] = 1;
					}
				}

				foreach (TvDB_ImageWideBanner tvBanner in allBanners)
				{
					if (string.IsNullOrEmpty(tvBanner.FullImagePath)) continue;
					bool fileExists = File.Exists(tvBanner.FullImagePath);

					int bannersAvailable = 0;
					if (fanartCount.ContainsKey(tvBanner.SeriesID))
						bannersAvailable = fanartCount[tvBanner.SeriesID];

					if (!fileExists && bannersAvailable < ServerSettings.TvDB_AutoWideBannersAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvBanner.TvDB_ImageWideBannerID, JMMImageType.TvDB_Banner, false);
						cmd.Save();
					}
				}
			}

			// TvDB Episodes
			TvDB_EpisodeRepository repTvEpisodes = new TvDB_EpisodeRepository();
			foreach (TvDB_Episode tvEpisode in repTvEpisodes.GetAll())
			{
				if (string.IsNullOrEmpty(tvEpisode.FullImagePath)) continue;
				bool fileExists = File.Exists(tvEpisode.FullImagePath);
				if (!fileExists)
				{
					CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvEpisode.TvDB_EpisodeID, JMMImageType.TvDB_Episode, false);
					cmd.Save();
				}
			}

			// MovieDB Posters
			if (ServerSettings.MovieDB_AutoPosters)
			{
				MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
				Dictionary<int, int> postersCount = new Dictionary<int, int>();

				// build a dictionary of series and how many images exist
				List<MovieDB_Poster> allPosters = repMoviePosters.GetAll();
				foreach (MovieDB_Poster moviePoster in allPosters)
				{
					if (string.IsNullOrEmpty(moviePoster.FullImagePath)) continue;
					bool fileExists = File.Exists(moviePoster.FullImagePath);

					if (fileExists)
					{
						if (postersCount.ContainsKey(moviePoster.MovieId))
							postersCount[moviePoster.MovieId] = postersCount[moviePoster.MovieId] + 1;
						else
							postersCount[moviePoster.MovieId] = 1;
					}
				}

				foreach (MovieDB_Poster moviePoster in allPosters)
				{
					if (string.IsNullOrEmpty(moviePoster.FullImagePath)) continue;
					bool fileExists = File.Exists(moviePoster.FullImagePath);

					int postersAvailable = 0;
					if (postersCount.ContainsKey(moviePoster.MovieId))
						postersAvailable = postersCount[moviePoster.MovieId];

					if (!fileExists && postersAvailable < ServerSettings.MovieDB_AutoPostersAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(moviePoster.MovieDB_PosterID, JMMImageType.MovieDB_Poster, false);
						cmd.Save();
					}
				}
			}

			// MovieDB Fanart
			if (ServerSettings.MovieDB_AutoFanart)
			{
				MovieDB_FanartRepository repMovieFanarts = new MovieDB_FanartRepository();
				Dictionary<int, int> fanartCount = new Dictionary<int, int>();

				// build a dictionary of series and how many images exist
				List<MovieDB_Fanart> allFanarts = repMovieFanarts.GetAll();
				foreach (MovieDB_Fanart movieFanart in allFanarts)
				{
					if (string.IsNullOrEmpty(movieFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(movieFanart.FullImagePath);

					if (fileExists)
					{
						if (fanartCount.ContainsKey(movieFanart.MovieId))
							fanartCount[movieFanart.MovieId] = fanartCount[movieFanart.MovieId] + 1;
						else
							fanartCount[movieFanart.MovieId] = 1;
					}
				}

				foreach (MovieDB_Fanart movieFanart in repMovieFanarts.GetAll())
				{
					if (string.IsNullOrEmpty(movieFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(movieFanart.FullImagePath);

					int fanartAvailable = 0;
					if (fanartCount.ContainsKey(movieFanart.MovieId))
						fanartAvailable = fanartCount[movieFanart.MovieId];

					if (!fileExists && fanartAvailable < ServerSettings.MovieDB_AutoFanartAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(movieFanart.MovieDB_FanartID, JMMImageType.MovieDB_FanArt, false);
						cmd.Save();
					}
				}
			}

			// Trakt Posters
			if (ServerSettings.Trakt_DownloadPosters)
			{
				Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
				foreach (Trakt_ImagePoster traktPoster in repTraktPosters.GetAll())
				{
					if (string.IsNullOrEmpty(traktPoster.FullImagePath)) continue;
					bool fileExists = File.Exists(traktPoster.FullImagePath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktPoster.Trakt_ImagePosterID, JMMImageType.Trakt_Poster, false);
						cmd.Save();
					}
				}
			}

			// Trakt Fanart
			if (ServerSettings.Trakt_DownloadFanart)
			{
				Trakt_ImageFanartRepository repTraktFanarts = new Trakt_ImageFanartRepository();
				foreach (Trakt_ImageFanart traktFanart in repTraktFanarts.GetAll())
				{
					if (string.IsNullOrEmpty(traktFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(traktFanart.FullImagePath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktFanart.Trakt_ImageFanartID, JMMImageType.Trakt_Fanart, false);
						cmd.Save();
					}
				}
			}

			// Trakt Episode
			if (ServerSettings.Trakt_DownloadEpisodes)
			{
				Trakt_EpisodeRepository repTraktEpisodes = new Trakt_EpisodeRepository();
				foreach (Trakt_Episode traktEp in repTraktEpisodes.GetAll())
				{
					if (string.IsNullOrEmpty(traktEp.FullImagePath)) continue;
					bool fileExists = File.Exists(traktEp.FullImagePath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktEp.Trakt_EpisodeID, JMMImageType.Trakt_Episode, false);
						cmd.Save();
					}
				}
			}

			// AniDB Characters
			if (ServerSettings.AniDB_DownloadCharacters)
			{
				AniDB_CharacterRepository repChars = new AniDB_CharacterRepository();
				foreach (AniDB_Character chr in repChars.GetAll())
				{
					if (string.IsNullOrEmpty(chr.PosterPath)) continue;
					bool fileExists = File.Exists(chr.PosterPath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(chr.AniDB_CharacterID, JMMImageType.AniDB_Character, false);
						cmd.Save();
					}
				}
			}

			// AniDB Creators
			if (ServerSettings.AniDB_DownloadCreators)
			{
				AniDB_SeiyuuRepository repSeiyuu = new AniDB_SeiyuuRepository();
				foreach (AniDB_Seiyuu seiyuu in repSeiyuu.GetAll())
				{
					if (string.IsNullOrEmpty(seiyuu.PosterPath)) continue;
					bool fileExists = File.Exists(seiyuu.PosterPath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(seiyuu.AniDB_SeiyuuID, JMMImageType.AniDB_Creator, false);
						cmd.Save();
					}
				}
			}
		}