Ejemplo n.º 1
0
		private List<object> ParseBanners(int seriesID, XmlDocument xmlDoc)
		{
			List<object> banners = new List<object>();
			try
			{
				XmlNodeList bannerItems = xmlDoc["Banners"].GetElementsByTagName("Banner");

				//BaseConfig.MyAnimeLog.Write("Found {0} banner nodes", bannerItems.Count);

				if (bannerItems.Count <= 0)
					return banners;

				// banner types
				// series = wide banner
				// fanart = fanart
				// poster = filmstrip poster/dvd cover

				TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
				TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository();
				TvDB_ImageWideBannerRepository repWideBanners = new TvDB_ImageWideBannerRepository();

				List<int> validFanartIDs = new List<int>();
				List<int> validPosterIDs = new List<int>();
				List<int> validBannerIDs = new List<int>();

				foreach (XmlNode node in bannerItems)
				{
					JMMImageType imageType = JMMImageType.TvDB_Cover;

					string bannerType = node["BannerType"].InnerText.Trim().ToUpper();
					string bannerType2 = node["BannerType2"].InnerText.Trim().ToUpper();


					if (bannerType == "FANART")
						imageType = JMMImageType.TvDB_FanArt;
					else if (bannerType == "POSTER")
						imageType = JMMImageType.TvDB_Cover;
					else if (bannerType == "SEASON")
					{
						if (bannerType2 == "SEASON")
							imageType = JMMImageType.TvDB_Cover;
						else
							imageType = JMMImageType.TvDB_Banner;
					}
					else if (bannerType == "SERIES")
					{
						if (bannerType2 == "SEASONWIDE" || bannerType2 == "GRAPHICAL" || bannerType2 == "TEXT" || bannerType2 == "BLANK")
							imageType = JMMImageType.TvDB_Banner;
						else
							imageType = JMMImageType.TvDB_Cover;
					}

					if (imageType == JMMImageType.TvDB_FanArt)
					{
						int id = int.Parse(node["id"].InnerText);
						TvDB_ImageFanart img = repFanart.GetByTvDBID(id);
						if (img == null)
						{
							img = new TvDB_ImageFanart();
							img.Enabled = 1;
						}

						img.Populate(seriesID, node);
						repFanart.Save(img);

						banners.Add(img);
						validFanartIDs.Add(id);
					}

					if (imageType == JMMImageType.TvDB_Banner)
					{
						int id = int.Parse(node["id"].InnerText);

						TvDB_ImageWideBanner img = repWideBanners.GetByTvDBID(id);
						if (img == null)
						{
							img = new TvDB_ImageWideBanner();
							img.Enabled = 1;
						}

						img.Populate(seriesID, node, TvDBImageNodeType.Series);
						repWideBanners.Save(img);

						banners.Add(img);
						validBannerIDs.Add(id);
					}

					if (imageType == JMMImageType.TvDB_Cover)
					{
						int id = int.Parse(node["id"].InnerText);

						TvDB_ImagePoster img = repPosters.GetByTvDBID(id);
						if (img == null)
						{
							img = new TvDB_ImagePoster();
							img.Enabled = 1;
						}

						TvDBImageNodeType nodeType = TvDBImageNodeType.Series;
						if (bannerType == "SEASON") nodeType = TvDBImageNodeType.Season;


						img.Populate(seriesID, node, nodeType);
						repPosters.Save(img);

						banners.Add(img);
						validPosterIDs.Add(id);
					}
				}

				// delete any banners from the database which are no longer valid
				foreach (TvDB_ImageFanart img in repFanart.GetBySeriesID(seriesID))
				{
					if (!validFanartIDs.Contains(img.Id))
						repFanart.Delete(img.TvDB_ImageFanartID);
				}

				foreach (TvDB_ImagePoster img in repPosters.GetBySeriesID(seriesID))
				{
					if (!validPosterIDs.Contains(img.Id))
						repPosters.Delete(img.TvDB_ImagePosterID);
				}

				foreach (TvDB_ImageWideBanner img in repWideBanners.GetBySeriesID(seriesID))
				{
					if (!validBannerIDs.Contains(img.Id))
						repWideBanners.Delete(img.TvDB_ImageWideBannerID);
				}

			}
			catch (Exception ex)
			{
				logger.ErrorException("Error in ParseBanners: " + ex.ToString(), ex);
			}

			return banners;
		}
Ejemplo n.º 2
0
		public void DownloadAutomaticImages(XmlDocument doc, int seriesID, bool forceDownload)
		{
			List<object> banners = ParseBanners(seriesID, doc);

			int numFanartDownloaded = 0;
			int numPostersDownloaded = 0;
			int numBannersDownloaded = 0;

            // find out how many images we already have locally
            TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
            TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository();
            TvDB_ImageWideBannerRepository repBanners = new TvDB_ImageWideBannerRepository();

            using (var session = JMMService.SessionFactory.OpenSession())
            {
                foreach (TvDB_ImageFanart fanart in repFanart.GetBySeriesID(session, seriesID))
                {
                    if (!string.IsNullOrEmpty(fanart.FullImagePath) && File.Exists(fanart.FullImagePath))
                        numFanartDownloaded++;
                }

                foreach (TvDB_ImagePoster poster in repPosters.GetBySeriesID(session, seriesID))
                {
                    if (!string.IsNullOrEmpty(poster.FullImagePath) && File.Exists(poster.FullImagePath))
                        numPostersDownloaded++;
                }

                foreach (TvDB_ImageWideBanner banner in repBanners.GetBySeriesID(session, seriesID))
                {
                    if (!string.IsNullOrEmpty(banner.FullImagePath) && File.Exists(banner.FullImagePath))
                        numBannersDownloaded++;
                }
            }
            


			foreach (object obj in banners)
			{
				if (obj.GetType() == typeof(TvDB_ImageFanart))
				{
					TvDB_ImageFanart img = obj as TvDB_ImageFanart;
					if (ServerSettings.TvDB_AutoFanart && numFanartDownloaded < ServerSettings.TvDB_AutoFanartAmount)
					{
						bool fileExists = File.Exists(img.FullImagePath);
						if (!fileExists || (fileExists && forceDownload))
						{
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImageFanartID, JMMImageType.TvDB_FanArt, forceDownload);
							cmd.Save();
							numFanartDownloaded++;
						}
					}
				}

				if (obj.GetType() == typeof(TvDB_ImagePoster))
				{
					TvDB_ImagePoster img = obj as TvDB_ImagePoster;
					if (ServerSettings.TvDB_AutoPosters && numPostersDownloaded < ServerSettings.TvDB_AutoPostersAmount)
					{
						bool fileExists = File.Exists(img.FullImagePath);
						if (!fileExists || (fileExists && forceDownload))
						{
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImagePosterID, JMMImageType.TvDB_Cover, forceDownload);
							cmd.Save();
							numPostersDownloaded++;
						}
					}
				}

				if (obj.GetType() == typeof(TvDB_ImageWideBanner))
				{
					TvDB_ImageWideBanner img = obj as TvDB_ImageWideBanner;
					if (ServerSettings.TvDB_AutoWideBanners && numBannersDownloaded < ServerSettings.TvDB_AutoWideBannersAmount)
					{
						bool fileExists = File.Exists(img.FullImagePath);
						if (!fileExists || (fileExists && forceDownload))
						{
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImageWideBannerID, JMMImageType.TvDB_Banner, forceDownload);
							cmd.Save();
							numBannersDownloaded++;
						}
					}
				}
			}
		}
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
0
        public Contract_AniDB_AnimeCrossRefs GetCrossRefDetails(int animeID)
        {
            Contract_AniDB_AnimeCrossRefs result = new Contract_AniDB_AnimeCrossRefs();
            result.AnimeID = animeID;

            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository();
                    AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                    AniDB_Anime anime = repAnime.GetByAnimeID(animeID);
                    if (anime == null) return result;

                    TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
                    TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository();
                    TvDB_ImageWideBannerRepository repBanners = new TvDB_ImageWideBannerRepository();

                    // TvDB
                    foreach (CrossRef_AniDB_TvDBV2 xref in anime.GetCrossRefTvDBV2())
                    {
                        result.CrossRef_AniDB_TvDB.Add(xref.ToContract());

                        TvDB_Series ser = repSeries.GetByTvDBID(session, xref.TvDBID);
                        if (ser != null)
                            result.TvDBSeries.Add(ser.ToContract());

                        foreach (TvDB_Episode ep in anime.GetTvDBEpisodes())
                            result.TvDBEpisodes.Add(ep.ToContract());

                        foreach (TvDB_ImageFanart fanart in repFanart.GetBySeriesID(session, xref.TvDBID))
                            result.TvDBImageFanarts.Add(fanart.ToContract());

                        foreach (TvDB_ImagePoster poster in repPosters.GetBySeriesID(session, xref.TvDBID))
                            result.TvDBImagePosters.Add(poster.ToContract());

                        foreach (TvDB_ImageWideBanner banner in repBanners.GetBySeriesID(xref.TvDBID))
                            result.TvDBImageWideBanners.Add(banner.ToContract());

                    }

                    // Trakt

                    Trakt_ImageFanartRepository repTraktFanart = new Trakt_ImageFanartRepository();
                    Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
                    Trakt_ShowRepository repTrakt = new Trakt_ShowRepository();

                    foreach (CrossRef_AniDB_TraktV2 xref in anime.GetCrossRefTraktV2())
                    {
                        result.CrossRef_AniDB_Trakt.Add(xref.ToContract());

                        Trakt_Show show = repTrakt.GetByTraktSlug(session, xref.TraktID);
                        if (show != null)
                        {
                            result.TraktShows.Add(show.ToContract());

                            foreach (Trakt_ImageFanart fanart in repTraktFanart.GetByShowID(session, show.Trakt_ShowID))
                                result.TraktImageFanarts.Add(fanart.ToContract());

                            foreach (Trakt_ImagePoster poster in repTraktPosters.GetByShowID(session, show.Trakt_ShowID))
                                result.TraktImagePosters.Add(poster.ToContract());
                        }
                    }

                    // MovieDB
                    CrossRef_AniDB_Other xrefMovie = anime.GetCrossRefMovieDB();
                    if (xrefMovie == null)
                        result.CrossRef_AniDB_MovieDB = null;
                    else
                        result.CrossRef_AniDB_MovieDB = xrefMovie.ToContract();

                    MovieDB_Movie movie = anime.GetMovieDBMovie();
                    if (movie == null)
                        result.MovieDBMovie = null;
                    else
                        result.MovieDBMovie = movie.ToContract();

                    foreach (MovieDB_Fanart fanart in anime.GetMovieDBFanarts())
                    {
                        if (fanart.ImageSize.Equals(Constants.MovieDBImageSize.Original, StringComparison.InvariantCultureIgnoreCase))
                            result.MovieDBFanarts.Add(fanart.ToContract());
                    }

                    foreach (MovieDB_Poster poster in anime.GetMovieDBPosters())
                    {
                        if (poster.ImageSize.Equals(Constants.MovieDBImageSize.Original, StringComparison.InvariantCultureIgnoreCase))
                            result.MovieDBPosters.Add(poster.ToContract());
                    }

                    // MAL
                    List<CrossRef_AniDB_MAL> xrefMAL = anime.GetCrossRefMAL();
                    if (xrefMAL == null)
                        result.CrossRef_AniDB_MAL = null;
                    else
                    {
                        result.CrossRef_AniDB_MAL = new List<Contract_CrossRef_AniDB_MAL>();
                        foreach (CrossRef_AniDB_MAL xrefTemp in xrefMAL)
                            result.CrossRef_AniDB_MAL.Add(xrefTemp.ToContract());
                    }

                }
                return result;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return result;
            }
        }
Ejemplo n.º 5
0
        public List<TvDB_ImagePoster> GetTvDBImagePosters(ISession session)
        {
            List<TvDB_ImagePoster> ret = new List<TvDB_ImagePoster>();

            List<CrossRef_AniDB_TvDBV2> xrefs = GetCrossRefTvDBV2(session);
            if (xrefs.Count == 0) return ret;

            TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository();

            foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
            {
                ret.AddRange(repPosters.GetBySeriesID(session, xref.TvDBID));
            }

            return ret;
        }