Beispiel #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);
        }
Beispiel #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++;
                        }
                    }
                    else
                    {
                        //The TvDB_AutoFanartAmount point to download less images than its available
                        // 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(img.FullImagePath))
                        {
                            repFanart.Delete(img.TvDB_ImageFanartID);
                        }
                    }
                }

                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++;
                        }
                    }
                    else
                    {
                        //The TvDB_AutoPostersAmount point to download less images than its available
                        // 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(img.FullImagePath))
                        {
                            repPosters.Delete(img.TvDB_ImagePosterID);
                        }
                    }
                }

                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++;
                        }
                    }
                    else
                    {
                        //The TvDB_AutoWideBannersAmount point to download less images than its available
                        // 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(img.FullImagePath))
                        {
                            repBanners.Delete(img.TvDB_ImageWideBannerID);
                        }
                    }
                }
            }
        }