static void RemoveEpisodeImagesFromCache(TmdbEpisodeImages images, int season, int episode)
 {
     if (images != null)
     {
         Episodes.RemoveAll(e => e.Id == images.Id && e.Season == season && e.Episode == episode);
     }
 }
Beispiel #2
0
 static void RemoveEpisodeImagesFromCache(TmdbEpisodeImages images)
 {
     if (images != null)
     {
         TmdbEpisodeImages ignored;
         Episodes.TryRemove(Tuple.Create(images.Id, images.Season, images.Episode), out ignored);
     }
 }
Beispiel #3
0
 static void AddEpisodeImagesToCache(TmdbEpisodeImages images)
 {
     if (images != null)
     {
         images.RequestAge = DateTime.Now.ToString();
         Episodes.TryAdd(Tuple.Create(images.Id, images.Season, images.Episode), images);
     }
 }
 static void AddEpisodeImagesToCache(TmdbEpisodeImages images, int?id, int season, int episode)
 {
     if (images != null)
     {
         images.RequestAge = DateTime.Now.ToString();
         images.Season     = season;
         images.Episode    = episode;
         images.Id         = id;
         Episodes.Add(images);
     }
 }
Beispiel #5
0
        public static string GetEpisodeThumbUrl(TmdbEpisodeImages images)
        {
            if (images == null || images.Stills == null)
            {
                return(null);
            }

            var episodeThumb = images.Stills.FirstOrDefault();

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

            // return the desired resolution
            return(TraktSettings.TmdbConfiguration.Images.BaseUrl + TraktSettings.TmdbPreferredPosterSize + episodeThumb.FilePath);
        }
Beispiel #6
0
        public static string GetEpisodeThumbFilename(TmdbEpisodeImages images)
        {
            if (images == null || images.Stills == null)
            {
                return(null);
            }

            var episodeThumb = images.Stills.FirstOrDefault();

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

            // create filename based on desired resolution
            return(Path.Combine(Config.GetFolder(Config.Dir.Thumbs), @"Trakt\Episodes\Thumbs\") +
                   images.Id + "_" + TraktSettings.TmdbPreferredPosterSize + "_" + episodeThumb.FilePath.TrimStart('/'));
        }
Beispiel #7
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);
            }
        }