Пример #1
0
        private TvdbBanner findBanner(TvdbAPI instance, TvdbAPI.ImageType imageType, bool thumbnail, string languageCode = null)
        {
            LoadBanners(instance, languageCode);

            if (Banners == null || Banners.Count == 0)
            {
                return(null);
            }

            TvdbBanner selectedBanner = null;

            foreach (TvdbBanner banner in Banners)
            {
                if (banner.IsType(imageType))
                {
                    if ((!thumbnail && banner.FileName != null) || (thumbnail && banner.ThumbNail != null))
                    {
                        if (selectedBanner == null)
                        {
                            selectedBanner = banner;
                        }
                        else
                        {
                            if (selectedBanner.RatingsInfo != null)
                            {
                                if (selectedBanner.RatingsInfo == null)
                                {
                                    selectedBanner = banner;
                                }
                                else
                                {
                                    if (banner.RatingsInfo.Average > selectedBanner.RatingsInfo.Average)
                                    {
                                        selectedBanner = banner;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(selectedBanner);
        }
Пример #2
0
        /// <summary>
        /// Get the small fan art image.
        /// </summary>
        /// <param name="instance">An API instance.</param>
        /// <param name="fileName">The output filename.</param>
        /// <returns>True if the image was downloaded; false otherwise.</returns>
        public bool GetSmallFanArtImage(TvdbAPI instance, string fileName)
        {
            TvdbBanner selectedBanner = findBanner(instance, TvdbAPI.ImageType.FanArt, true);

            if (selectedBanner == null)
            {
                return(false);
            }

            try
            {
                return(instance.GetImage(TvdbAPI.ImageType.FanArt, selectedBanner.ThumbNail, 0, fileName));
            }
            catch (WebException e)
            {
                HttpWebResponse response = e.Response as HttpWebResponse;
                if (response != null && response.StatusCode == HttpStatusCode.NotFound)
                {
                    return(false);
                }
                throw e;
            }
        }