private void DownloadFanart() { if (Movie == null || Movie.Ids == null || Movie.Ids.Tmdb == null) { return; } var getFanartthread = new Thread((o) => { var movieImages = TmdbCache.GetMovieImages(Movie.Ids.Tmdb); if (movieImages == null) { return; } var movie = o as TraktMovieSummary; string localFile = TmdbCache.GetMoviePosterFilename(movieImages); string remoteFile = TmdbCache.GetMoviePosterUrl(movieImages); if (localFile == null || remoteFile == null) { return; } GUIImageHandler.DownloadImage(remoteFile, localFile); GUIUtils.SetProperty("#Trakt.Movie.FanartImageFilename", localFile); }) { Name = "ImageDownload", IsBackground = true }; getFanartthread.Start(Movie); }
/// <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((m1, m2) => //{ // int x = Convert.ToInt32(File.Exists(m1.MovieImages.Poster.LocalImageFilename(ArtworkType.MoviePoster))) + Convert.ToInt32(File.Exists(m1.MovieImages.Fanart.LocalImageFilename(ArtworkType.MovieFanart))); // int y = Convert.ToInt32(File.Exists(m2.MovieImages.Poster.LocalImageFilename(ArtworkType.MoviePoster))) + Convert.ToInt32(File.Exists(m2.MovieImages.Fanart.LocalImageFilename(ArtworkType.MovieFanart))); // 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 movieImages = TmdbCache.GetMovieImages(item.MovieImages.Id); if (movieImages == null) { continue; } item.MovieImages = movieImages; #region Poster // stop download if we have exited window if (StopDownload) { break; } string remoteThumb = TmdbCache.GetMoviePosterUrl(movieImages); string localThumb = TmdbCache.GetMoviePosterFilename(movieImages); if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb)) { if (GUIImageHandler.DownloadImage(remoteThumb, localThumb)) { // 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.GetMovieBackdropUrl(movieImages);; string localFanart = TmdbCache.GetMovieBackdropFilename(movieImages); 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); } }
/// <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); } }