private void InitProperties()
        {
            // only set property if file exists
            // if we set now and download later, image will not set to skin
            var showImages       = TmdbCache.GetShowImages(Show.Ids.Tmdb, true);
            var backdropFilename = TmdbCache.GetShowBackdropFilename(showImages);

            if (backdropFilename != null)
            {
                if (File.Exists(backdropFilename))
                {
                    GUIUtils.SetProperty("#Trakt.Show.Fanart", backdropFilename);
                }
            }
            else if (Fanart != null)
            {
                if (File.Exists(Fanart))
                {
                    GUIUtils.SetProperty("#Trakt.Show.Fanart", Fanart);
                }
            }

            // Load Show Properties
            PublishShowSkinProperties(Show);

            // load last layout
            CurrentLayout = (GUIFacadeControl.Layout)TraktSettings.ShowSeasonsDefaultLayout;

            // update layout button label
            GUIControl.SetControlLabel(GetID, layoutButton.GetID, GUICommon.GetLayoutTranslation(CurrentLayout));
        }
예제 #2
0
        private void DownloadFanart()
        {
            var getFanartthread = new Thread((o) =>
            {
                var show = o as TraktShowSummary;

                var images = TmdbCache.GetShowImages(show.Ids.Tmdb);
                if (images == null)
                {
                    return;
                }

                string localFile  = TmdbCache.GetShowBackdropFilename(images);
                string remoteFile = TmdbCache.GetShowBackdropUrl(images);

                if (localFile == null || remoteFile == null)
                {
                    return;
                }

                GUIImageHandler.DownloadImage(remoteFile, localFile);
                GUIUtils.SetProperty("#Trakt.Show.FanartImageFilename", localFile);
            })
            {
                Name = "ImageDownload", IsBackground = true
            };

            getFanartthread.Start(Show);
        }
        private void GetShowDetail()
        {
            // check if we need to fetch the show detail as well
            // currently the season API does not give back any show
            // summary info except for images
            if (Show.UpdatedAt == null)
            {
                string slug = Show.Ids.Trakt.ToString();
                if (string.IsNullOrEmpty(slug))
                {
                    if (Show.Ids.Imdb != null)
                    {
                        slug = Show.Ids.Imdb;
                    }
                    else
                    {
                        slug = Show.Title.StripYear(Show.Year).ToSlug();
                    }
                }

                var showSummary = TraktAPI.TraktAPI.GetShowSummary(slug);
                if (showSummary != null)
                {
                    Show = showSummary;

                    // Load Show Properties
                    PublishShowSkinProperties(Show);

                    // Publish Fanart
                    var showImages           = TmdbCache.GetShowImages(showSummary.Ids.Tmdb);
                    var showBackdropFilename = TmdbCache.GetShowBackdropFilename(showImages);
                    if (showBackdropFilename == null)
                    {
                        return;
                    }

                    if (File.Exists(showBackdropFilename))
                    {
                        GUIUtils.SetProperty("#Trakt.Show.Fanart", showBackdropFilename);
                    }
                }
            }
        }
        private void InitProperties()
        {
            // only set property if file exists
            // if we set now and download later, image will not set to skin
            var showImages       = TmdbCache.GetShowImages(Show.Ids.Tmdb, true);
            var backdropFilename = TmdbCache.GetShowBackdropFilename(showImages);

            if (backdropFilename != null && File.Exists(backdropFilename))
            {
                GUIUtils.SetProperty("#Trakt.Show.Fanart", backdropFilename);
            }

            // load last layout
            CurrentLayout = (Layout)TraktSettings.SeasonEpisodesDefaultLayout;

            // update button label
            if (layoutButton != null)
            {
                GUIControl.SetControlLabel(GetID, layoutButton.GetID, GUICommon.GetLayoutTranslation(CurrentLayout));
            }
        }
        /// <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.SeasonImages.Poster.LocalImageFilename(ArtworkType.SeasonPoster)));
                //    int y = Convert.ToInt32(File.Exists(s2.SeasonImages.Poster.LocalImageFilename(ArtworkType.SeasonPoster)));
                //    return y.CompareTo(x);
                //});

                new Thread(obj =>
                {
                    var items = (List <GUITmdbImage>)obj;
                    if (items == null || items.Count == 0)
                    {
                        return;
                    }

                    // all seasons should have the same show reference
                    var showImages = TmdbCache.GetShowImages(items.First().SeasonImages.Id);
                    if (showImages != null)
                    {
                        items.ForEach(s => s.ShowImages = showImages);
                    }

                    foreach (var item in items)
                    {
                        #region Season Poster
                        // stop download if we have exited window
                        if (StopDownload)
                        {
                            break;
                        }

                        bool downloadShowPoster = false;

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

                        var seasonImages = TmdbCache.GetSeasonImages(item.SeasonImages.Id, item.SeasonImages.Season);
                        if (seasonImages != null)
                        {
                            item.SeasonImages = seasonImages;
                        }

                        if (seasonImages != null && seasonImages.Posters != null && seasonImages.Posters.Count > 0)
                        {
                            remoteThumb = TmdbCache.GetSeasonPosterUrl(seasonImages);
                            localThumb  = TmdbCache.GetSeasonPosterFilename(seasonImages);
                        }
                        else
                        {
                            downloadShowPoster = true;

                            // use show image if season poster not available
                            remoteThumb = TmdbCache.GetShowPosterUrl(showImages);
                            localThumb  = TmdbCache.GetShowPosterFilename(showImages);
                        }

                        if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb))
                        {
                            if (GUIImageHandler.DownloadImage(remoteThumb, localThumb))
                            {
                                // notify that image has been downloaded
                                item.NotifyPropertyChanged(downloadShowPoster ? "ShowPoster" : "SeasonPoster");
                            }
                        }
                        #endregion

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

                        string remoteFanart = TmdbCache.GetShowBackdropUrl(showImages);
                        string localFanart  = TmdbCache.GetShowBackdropFilename(showImages);

                        if (!string.IsNullOrEmpty(remoteFanart) && !string.IsNullOrEmpty(localFanart))
                        {
                            if (GUIImageHandler.DownloadImage(remoteFanart, localFanart))
                            {
                                // notify that image has been downloaded
                                item.NotifyPropertyChanged("Fanart");
                            }
                        }
                        #endregion
                    }
                })
                {
                    IsBackground = true,
                    Name         = "ImageDownloader" + i.ToString()
                }.Start(groupList);
            }
        }
예제 #6
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);
            }
        }
        /// <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]);
                }

                new Thread(delegate(object o)
                {
                    var items = (List <GUITmdbImage>)o;
                    foreach (var item in items)
                    {
                        string remoteThumb = string.Empty;
                        string localThumb  = string.Empty;

                        #region Seasons / Episodes
                        if (item.SeasonImages != null)
                        {
                            // check if we have the image in our cache
                            var seasonImages = TmdbCache.GetSeasonImages(item.SeasonImages.Id, item.SeasonImages.Season);
                            if (seasonImages == null)
                            {
                                continue;
                            }

                            item.SeasonImages = seasonImages;

                            #region Show Season Poster
                            // stop download if we have exited window
                            if (StopDownload)
                            {
                                break;
                            }

                            remoteThumb = TmdbCache.GetSeasonPosterUrl(seasonImages);
                            localThumb  = TmdbCache.GetSeasonPosterFilename(seasonImages);

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

                                    // notify that image has been downloaded
                                    item.NotifyPropertyChanged("SeasonPoster");
                                }
                            }
                            #endregion
                        }
                        #endregion

                        #region Shows / Seasons / Episodes
                        if (item.ShowImages != null)
                        {
                            #region Show Poster

                            var showImages = TmdbCache.GetShowImages(item.ShowImages.Id);
                            if (showImages == null)
                            {
                                continue;
                            }

                            item.ShowImages = showImages;

                            // don't download the show poster if we have a season poster
                            if (item.SeasonImages == null || item.SeasonImages.Posters == null || item.SeasonImages.Posters.Count == 0)
                            {
                                // stop download if we have exited window
                                if (StopDownload)
                                {
                                    break;
                                }

                                remoteThumb = TmdbCache.GetShowPosterUrl(showImages);
                                localThumb  = TmdbCache.GetShowPosterFilename(showImages);

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

                                        // notify that image has been downloaded
                                        item.NotifyPropertyChanged("ShowPoster");
                                    }
                                }
                            }
                            #endregion

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

                            string remoteFanart = TmdbCache.GetShowBackdropUrl(showImages);;
                            string localFanart  = TmdbCache.GetShowBackdropFilename(showImages);

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

                                    // notify that image has been downloaded
                                    item.NotifyPropertyChanged("Fanart");
                                }
                            }
                            #endregion
                        }
                        #endregion

                        #region Movies
                        if (item.MovieImages != null)
                        {
                            // check if we have the image in our cache
                            var movieImages = TmdbCache.GetMovieImages(item.MovieImages.Id);
                            if (movieImages == null)
                            {
                                continue;
                            }

                            item.MovieImages = movieImages;

                            #region Movie Poster
                            // stop download if we have exited window
                            if (StopDownload)
                            {
                                break;
                            }

                            remoteThumb = TmdbCache.GetMoviePosterUrl(movieImages);
                            localThumb  = TmdbCache.GetMoviePosterFilename(movieImages);

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

                                    // notify that image has been downloaded
                                    item.NotifyPropertyChanged("MoviePoster");
                                }
                            }
                            #endregion

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

                            string remoteFanart = TmdbCache.GetMovieBackdropUrl(movieImages);;
                            string localFanart  = TmdbCache.GetMovieBackdropFilename(movieImages);

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

                                    // notify that image has been downloaded
                                    item.NotifyPropertyChanged("Fanart");
                                }
                            }
                            #endregion
                        }
                        #endregion

                        #region People

                        if (item.PeopleImages != null)
                        {
                            // check if we have the image in our cache
                            var peopleImages = TmdbCache.GetPersonImages(item.PeopleImages.Id);
                            if (peopleImages == null)
                            {
                                continue;
                            }

                            item.PeopleImages = peopleImages;

                            #region Headshot
                            // stop download if we have exited window
                            if (StopDownload)
                            {
                                break;
                            }

                            remoteThumb = TmdbCache.GetPersonHeadshotUrl(peopleImages);
                            localThumb  = TmdbCache.GetPersonHeadshotFilename(peopleImages);

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

                                    // notify that image has been downloaded
                                    item.NotifyPropertyChanged("HeadShot");
                                }
                            }
                            #endregion
                        }

                        #endregion
                    }
                })
                {
                    IsBackground = true,
                    Name         = "ImageDownloader" + i.ToString()
                }.Start(groupList);
            }
        }
        /// <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.ShowImages.Poster.LocalImageFilename(ArtworkType.ShowPoster))) + Convert.ToInt32(File.Exists(s1.ShowImages.Fanart.LocalImageFilename(ArtworkType.ShowFanart)));
                //    int y = Convert.ToInt32(File.Exists(s2.ShowImages.Poster.LocalImageFilename(ArtworkType.ShowPoster))) + 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)
                    {
                        // check if we have the image in our cache
                        var showImages = TmdbCache.GetShowImages(item.ShowImages.Id);
                        if (showImages == null)
                        {
                            continue;
                        }

                        item.ShowImages = showImages;

                        #region Poster
                        // stop download if we have exited window
                        if (StopDownload)
                        {
                            break;
                        }

                        string remoteThumb = TmdbCache.GetShowPosterUrl(showImages);
                        string localThumb  = TmdbCache.GetShowPosterFilename(showImages);

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

                                // notify that image has been downloaded
                                item.NotifyPropertyChanged("Poster");
                            }
                        }
                        #endregion

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

                        string remoteFanart = TmdbCache.GetShowBackdropUrl(showImages);;
                        string localFanart  = TmdbCache.GetShowBackdropFilename(showImages);

                        if (!string.IsNullOrEmpty(remoteFanart) && !string.IsNullOrEmpty(localFanart))
                        {
                            if (GUIImageHandler.DownloadImage(remoteFanart, localFanart))
                            {
                                //if (StopDownload) break;

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