Пример #1
0
        public static string GetShowBackdropUrl(TmdbShowImages images, bool logo = false)
        {
            if (images == null || images.Backdrops == null)
            {
                return(null);
            }

            TmdbImage showBackdrop = null;

            if (logo)
            {
                // get the highest rated backdrop with a language
                showBackdrop = images.Backdrops.LocalisedImage();
            }
            else
            {
                showBackdrop = images.Backdrops.FirstOrDefault();
            }

            if (showBackdrop == null)
            {
                return(null);
            }

            // return the desired resolution
            return(TraktSettings.TmdbConfiguration.Images.BaseUrl + (TraktSettings.DownloadFullSizeFanart ? "original" : TraktSettings.TmdbPreferredBackdropSize) + showBackdrop.FilePath);
        }
Пример #2
0
        public static string GetShowBackdropFilename(TmdbShowImages images, bool logo = false)
        {
            if (images == null || images.Backdrops == null)
            {
                return(null);
            }

            string    languagePath = string.Empty;
            TmdbImage showBackdrop = null;

            if (logo)
            {
                // get the highest rated backdrop with a language
                showBackdrop = images.Backdrops.LocalisedImage();
            }
            else
            {
                showBackdrop = images.Backdrops.FirstOrDefault();
            }

            if (showBackdrop == null)
            {
                return(null);
            }

            // create filename based on desired resolution
            return(Path.Combine(Config.GetFolder(Config.Dir.Thumbs), @"Trakt\Shows\Backdrops\") +
                   images.Id + "_" + (TraktSettings.DownloadFullSizeFanart ? "original" : TraktSettings.TmdbPreferredBackdropSize) + "_" + showBackdrop.FilePath.TrimStart('/'));
        }
Пример #3
0
 static void RemoveShowImagesFromCache(TmdbShowImages images)
 {
     if (images != null)
     {
         Shows.RemoveAll(s => s.Id == images.Id);
     }
 }
Пример #4
0
 static void RemoveShowImagesFromCache(TmdbShowImages images)
 {
     if (images != null)
     {
         TmdbShowImages ignored;
         Shows.TryRemove(images.Id, out ignored);
     }
 }
Пример #5
0
 static void AddShowImagesToCache(TmdbShowImages images)
 {
     if (images != null)
     {
         images.RequestAge = DateTime.Now.ToString();
         Shows.TryAdd(images.Id, images);
     }
 }
Пример #6
0
        public static string GetShowPosterUrl(TmdbShowImages images)
        {
            if (images == null || images.Posters == null)
            {
                return(null);
            }

            var showPoster = images.Posters.LocalisedImage();

            if (showPoster == null)
            {
                return(null);
            }

            // return the desired resolution
            return(TraktSettings.TmdbConfiguration.Images.BaseUrl + TraktSettings.TmdbPreferredPosterSize + showPoster.FilePath);
        }
Пример #7
0
        public static string GetShowPosterFilename(TmdbShowImages images)
        {
            if (images == null || images.Posters == null)
            {
                return(null);
            }

            var showPoster = images.Posters.LocalisedImage();

            if (showPoster == null)
            {
                return(null);
            }

            // create filename based on desired resolution
            return(Path.Combine(Config.GetFolder(Config.Dir.Thumbs), @"Trakt\Shows\Posters\") +
                   images.Id + "_" + TraktSettings.TmdbPreferredPosterSize + "_" + showPoster.FilePath.TrimStart('/'));
        }
Пример #8
0
        /// <summary>
        /// Download all images attached to the GUI List Control
        /// TODO: Make part of a GUI Base Window
        /// </summary>
        /// <param name="itemsWithThumbs">List of images to get</param>
        internal static void GetImages(List <GUITmdbImage> itemsWithThumbs)
        {
            StopDownload = false;

            // split the downloads in 5+ groups and do multithreaded downloading
            int groupSize = (int)Math.Max(1, Math.Floor((double)itemsWithThumbs.Count / 5));
            int groups    = (int)Math.Ceiling((double)itemsWithThumbs.Count() / groupSize);

            for (int i = 0; i < groups; i++)
            {
                var groupList = new List <GUITmdbImage>();
                for (int j = groupSize * i; j < groupSize * i + (groupSize * (i + 1) > itemsWithThumbs.Count ? itemsWithThumbs.Count - groupSize * i : groupSize); j++)
                {
                    groupList.Add(itemsWithThumbs[j]);
                }

                // sort images so that images that already exist are displayed first
                //groupList.Sort((s1, s2) =>
                //{
                //    int x = Convert.ToInt32(File.Exists(s1.EpisodeImages.ScreenShot.LocalImageFilename(ArtworkType.EpisodeImage))) + (s1.ShowImages == null ? 0 : Convert.ToInt32(File.Exists(s1.ShowImages.Fanart.LocalImageFilename(ArtworkType.ShowFanart))));
                //    int y = Convert.ToInt32(File.Exists(s2.EpisodeImages.ScreenShot.LocalImageFilename(ArtworkType.EpisodeImage))) + (s2.ShowImages == null ? 0 : Convert.ToInt32(File.Exists(s2.ShowImages.Fanart.LocalImageFilename(ArtworkType.ShowFanart))));
                //    return y.CompareTo(x);
                //});

                new Thread(delegate(object o)
                {
                    var items = (List <GUITmdbImage>)o;
                    foreach (var item in items)
                    {
                        #region Episode Image
                        // stop download if we have exited window
                        if (StopDownload)
                        {
                            break;
                        }

                        bool downloadShowBackdrop = false;

                        string remoteThumb = string.Empty;
                        string localThumb  = string.Empty;

                        TmdbEpisodeImages episodeImages = null;
                        TmdbShowImages showImages       = null;

                        // Don't try to get episode images that air after today, they most likely do not exist and contain spoilers
                        if (item.EpisodeImages.AirDate != null && Convert.ToDateTime(item.EpisodeImages.AirDate) <= Convert.ToDateTime(DateTime.Now.ToShortDateString()))
                        {
                            episodeImages = TmdbCache.GetEpisodeImages(item.EpisodeImages.Id, item.EpisodeImages.Season, item.EpisodeImages.Episode);
                            if (episodeImages != null)
                            {
                                item.EpisodeImages = episodeImages;
                            }
                        }

                        showImages = TmdbCache.GetShowImages(item.EpisodeImages.Id);
                        if (showImages != null)
                        {
                            item.ShowImages = showImages;
                        }

                        // if the episode image exists get it, otherwise get the show fanart
                        if (episodeImages != null && episodeImages.Stills != null && episodeImages.Stills.Count > 0)
                        {
                            remoteThumb = TmdbCache.GetEpisodeThumbUrl(episodeImages);
                            localThumb  = TmdbCache.GetEpisodeThumbFilename(episodeImages);
                        }
                        else
                        {
                            downloadShowBackdrop = true;

                            // use fanart for episode image, get one with a logo
                            remoteThumb = TmdbCache.GetShowBackdropUrl(item.ShowImages, true);
                            localThumb  = TmdbCache.GetShowBackdropFilename(item.ShowImages, true);
                        }

                        if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb))
                        {
                            if (GUIImageHandler.DownloadImage(remoteThumb, localThumb))
                            {
                                if (StopDownload)
                                {
                                    break;
                                }

                                // notify that image has been downloaded
                                item.NotifyPropertyChanged(downloadShowBackdrop ? "ShowScreenStillAsBackdrop" : "ShowScreenStill");
                            }
                        }
                        #endregion

                        #region Fanart
                        // stop download if we have exited window
                        if (StopDownload)
                        {
                            break;
                        }
                        if (!TraktSettings.DownloadFanart)
                        {
                            continue;
                        }

                        remoteThumb = TmdbCache.GetShowBackdropUrl(item.ShowImages);
                        localThumb  = TmdbCache.GetShowBackdropFilename(item.ShowImages);

                        if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb))
                        {
                            if (GUIImageHandler.DownloadImage(remoteThumb, localThumb))
                            {
                                if (StopDownload)
                                {
                                    break;
                                }

                                // notify that image has been downloaded
                                item.NotifyPropertyChanged("Fanart");
                            }
                        }
                        #endregion
                    }
                })
                {
                    IsBackground = true,
                    Name         = "ImageDownloader" + i.ToString()
                }.Start(groupList);
            }
        }