public static DownloadImage ( string url, string localFile ) : bool | ||
url | string | Online URL of image to download |
localFile | string | Local filename to save image |
return | bool |
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); }
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); }
static void GetUserProfileImage(TraktUserSummaryEx user) { string url = user.Profile.Images.Avatar.FullSize; string localFile = user.Profile.Images.Avatar.LocalImageFilename(ArtworkType.Avatar); GUIImageHandler.DownloadImage(url, localFile); }
static void GetUserProfileImage(TraktUserProfile userProfile) { string url = userProfile.Avatar; string localFile = userProfile.Avatar.LocalImageFilename(ArtworkType.Avatar); GUIImageHandler.DownloadImage(url, localFile); }
/// <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 <GUITraktImage> 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 <GUITraktImage>(); 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 <GUITraktImage>)o; foreach (var item in items) { #region Avatar if (item.UserImages != null && item.UserImages.Avatar != null) { // stop download if we have exited window if (StopDownload) { break; } string remoteThumb = item.UserImages.Avatar.FullSize; string localThumb = item.UserImages.Avatar.LocalImageFilename(ArtworkType.Avatar); if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb)) { if (GUIImageHandler.DownloadImage(remoteThumb, localThumb)) { if (StopDownload) { break; } // notify that image has been downloaded item.NotifyPropertyChanged("Avatar"); } } } #endregion } }) { IsBackground = true, Name = "ImageDownloader" + i.ToString() }.Start(groupList); } }
private void DownloadFanart(string localFile, string remoteFile) { var getFanartthread = new Thread((o) => { GUIImageHandler.DownloadImage(remoteFile, localFile); GUIUtils.SetProperty("#Trakt.Shout.Fanart", localFile); }) { Name = "ImageDownload", IsBackground = true }; getFanartthread.Start(); }
/// <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 <TraktImage> 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 <TraktImage>(); 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 <TraktImage>)o; foreach (var item in items) { #region Poster // stop download if we have exited window if (StopDownload) { break; } string remoteThumb = item.ShowImages.Poster.ToSmallPoster(); string localThumb = item.ShowImages.Poster.LocalImageFilename(ArtworkType.ShowPoster); 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 = item.ShowImages.Fanart.ToSmallFanart(); string localFanart = item.ShowImages.Fanart.LocalImageFilename(ArtworkType.ShowFanart); 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); } }
private void GetImages(List <TraktShow.ShowImages> 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++) { List <TraktShow.ShowImages> groupList = new List <TraktShow.ShowImages>(); 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) { List <TraktShow.ShowImages> items = (List <TraktShow.ShowImages>)o; foreach (TraktShow.ShowImages item in items) { #region Poster // stop download if we have exited window if (StopDownload) { break; } string remoteThumb = item.Poster; string localThumb = item.PosterImageFilename; if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb)) { if (GUIImageHandler.DownloadImage(remoteThumb, localThumb)) { // notify that image has been downloaded item.NotifyPropertyChanged("PosterImageFilename"); } } #endregion #region Fanart // stop download if we have exited window if (StopDownload) { break; } if (!TraktSettings.DownloadFanart) { continue; } string remoteFanart = item.Fanart; string localFanart = item.FanartImageFilename; if (!string.IsNullOrEmpty(remoteFanart) && !string.IsNullOrEmpty(localFanart)) { if (GUIImageHandler.DownloadImage(remoteFanart, localFanart)) { // notify that image has been downloaded item.NotifyPropertyChanged("FanartImageFilename"); } } #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.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); } }
/// <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, bool downloadFanart = true) { 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) { if (item.PeopleImages != null) { // stop download if we have exited window if (StopDownload) { break; } var peopleImages = TmdbCache.GetPersonImages(item.PeopleImages.Id); if (peopleImages == null) { return; } item.PeopleImages = peopleImages; string remoteThumb = TmdbCache.GetPersonHeadshotUrl(peopleImages); string localThumb = TmdbCache.GetPersonHeadshotFilename(peopleImages); if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb)) { if (GUIImageHandler.DownloadImage(remoteThumb, localThumb)) { // notify that image has been downloaded item.NotifyPropertyChanged("HeadShot"); } } // not all methods have Fanart for people // only get it, if we need it //if (downloadFanart && item.PeopleImages.Fanart != null) //{ // remoteThumb = TraktSettings.DownloadFullSizeFanart ? item.PeopleImages.Fanart.FullSize : item.PeopleImages.Fanart.MediumSize; // localThumb = item.PeopleImages.Fanart.LocalImageFilename(ArtworkType.PersonFanart); // if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb)) // { // if (GUIImageHandler.DownloadImage(remoteThumb, localThumb)) // { // // notify that image has been downloaded // item.NotifyPropertyChanged("Fanart"); // } // } //} } } }) { 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.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]); } // 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 <TraktImage> 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 <TraktImage>(); 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 <TraktImage>)o; foreach (var item in items) { string remoteThumb = string.Empty; string localThumb = string.Empty; #region Shows if (item.ShowImages != null) { #region Show Poster // stop download if we have exited window if (StopDownload) { break; } remoteThumb = item.ShowImages.Poster.ToSmallPoster(); localThumb = item.ShowImages.Poster.LocalImageFilename(ArtworkType.ShowPoster); if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb)) { if (GUIImageHandler.DownloadImage(remoteThumb, localThumb)) { // notify that image has been downloaded item.NotifyPropertyChanged("ShowPoster"); } } #endregion #region Show Season Poster // stop download if we have exited window if (StopDownload) { break; } remoteThumb = item.ShowImages.Season; localThumb = item.ShowImages.Season.LocalImageFilename(ArtworkType.SeasonPoster); if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb)) { if (GUIImageHandler.DownloadImage(remoteThumb, localThumb)) { // notify that image has been downloaded item.NotifyPropertyChanged("Season"); } } #endregion #region Fanart // stop download if we have exited window if (StopDownload) { break; } if (!TraktSettings.DownloadFanart) { continue; } string remoteFanart = item.ShowImages.Fanart.ToSmallFanart(); string localFanart = item.ShowImages.Fanart.LocalImageFilename(ArtworkType.ShowFanart); if (!string.IsNullOrEmpty(remoteFanart) && !string.IsNullOrEmpty(localFanart)) { if (GUIImageHandler.DownloadImage(remoteFanart, localFanart)) { // notify that image has been downloaded item.NotifyPropertyChanged("Fanart"); } } #endregion } #endregion #region Movies if (item.MovieImages != null) { #region Movie Poster // stop download if we have exited window if (StopDownload) { break; } remoteThumb = item.MovieImages.Poster.ToSmallPoster(); localThumb = item.MovieImages.Poster.LocalImageFilename(ArtworkType.MoviePoster); if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb)) { if (GUIImageHandler.DownloadImage(remoteThumb, localThumb)) { // 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 = item.MovieImages.Fanart.ToSmallFanart(); string localFanart = item.MovieImages.Fanart.LocalImageFilename(ArtworkType.MovieFanart); if (!string.IsNullOrEmpty(remoteFanart) && !string.IsNullOrEmpty(localFanart)) { if (GUIImageHandler.DownloadImage(remoteFanart, localFanart)) { // notify that image has been downloaded item.NotifyPropertyChanged("Fanart"); } } #endregion } #endregion } }) { IsBackground = true, Name = "ImageDownloader" + i.ToString() }.Start(groupList); } }
private void GetImages(List <TraktUser> itemsWithThumbs) { StopDownload = false; new Thread((o) => { // download fanart if we need to if (!File.Exists(Fanart) && !string.IsNullOrEmpty(OnlineFanart) && TraktSettings.DownloadFanart) { if (GUIImageHandler.DownloadImage(OnlineFanart, Fanart)) { // notify that image has been downloaded GUIUtils.SetProperty("#Trakt.Shout.Fanart", Fanart); } } }) { IsBackground = true, Name = "ImageDownloader" }.Start(); // 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++) { List <TraktUser> groupList = new List <TraktUser>(); 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) { List <TraktUser> items = (List <TraktUser>)o; foreach (var item in items) { // stop download if we have exited window if (StopDownload) { break; } string remoteThumb = item.Avatar; string localThumb = item.AvatarFilename; if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb)) { if (GUIImageHandler.DownloadImage(remoteThumb, localThumb)) { // notify that image has been downloaded item.NotifyPropertyChanged("AvatarFilename"); } } } }) { 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); } }
private void GetImages(List <object> 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++) { List <object> groupList = new List <object>(); 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) { List <object> items = (List <object>)o; foreach (object item in items) { #region Poster // stop download if we have exited window if (StopDownload) { break; } string remoteThumb = string.Empty; string localThumb = string.Empty; bool seasonPoster = false; if (item is TraktMovie.MovieImages) { remoteThumb = ((TraktMovie.MovieImages)item).Poster; localThumb = ((TraktMovie.MovieImages)item).PosterImageFilename; } else { // check if season poster should be downloaded instead of series poster if (string.IsNullOrEmpty(((TraktShow.ShowImages)item).SeasonImageFilename)) { seasonPoster = false; remoteThumb = ((TraktShow.ShowImages)item).Poster; localThumb = ((TraktShow.ShowImages)item).PosterImageFilename; } else { seasonPoster = true; remoteThumb = ((TraktShow.ShowImages)item).Season; localThumb = ((TraktShow.ShowImages)item).SeasonImageFilename; } } if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb)) { if (GUIImageHandler.DownloadImage(remoteThumb, localThumb)) { // notify that image has been downloaded if (item is TraktMovie.MovieImages) { ((TraktMovie.MovieImages)item).NotifyPropertyChanged("PosterImageFilename"); } else { ((TraktShow.ShowImages)item).NotifyPropertyChanged(seasonPoster ? "SeasonImageFilename" : "PosterImageFilename"); } } } #endregion #region Fanart // stop download if we have exited window if (StopDownload) { break; } if (!TraktSettings.DownloadFanart) { continue; } string remoteFanart = string.Empty; string localFanart = string.Empty; remoteFanart = item is TraktMovie.MovieImages ? ((TraktMovie.MovieImages)item).Fanart : ((TraktShow.ShowImages)item).Fanart; localFanart = item is TraktMovie.MovieImages ? ((TraktMovie.MovieImages)item).FanartImageFilename : ((TraktShow.ShowImages)item).FanartImageFilename; if (!string.IsNullOrEmpty(remoteFanart) && !string.IsNullOrEmpty(localFanart)) { if (GUIImageHandler.DownloadImage(remoteFanart, localFanart)) { // notify that image has been downloaded if (item is TraktMovie.MovieImages) { ((TraktMovie.MovieImages)item).NotifyPropertyChanged("FanartImageFilename"); } else { ((TraktShow.ShowImages)item).NotifyPropertyChanged("FanartImageFilename"); } } } #endregion } }) { IsBackground = true, Name = "ImageDownloader" + i.ToString() }.Start(groupList); } }