TraktPlugin.GUI.GUIMovieListItem.GetImages C# (CSharp) Méthode

GetImages() static private méthode

Download all images attached to the GUI List Control TODO: Make part of a GUI Base Window
static private GetImages ( List itemsWithThumbs ) : void
itemsWithThumbs List List of images to get
Résultat void
        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);
            }
        }

Usage Example

        private void SendCastToFacade(List <TraktPersonMovieCast> cast)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (cast == null)
            {
                GUIUtils.ShowNotifyDialog(Translation.Error, Translation.ErrorGeneral);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            // filter movies
            var filteredCast = FilterCastMovies(cast).Where(m => !string.IsNullOrEmpty(m.Movie.Title)).ToList();

            // sort movies
            filteredCast.Sort(new GUIListItemMovieSorter(TraktSettings.SortByCreditMovies.Field, TraktSettings.SortByCreditMovies.Direction));

            int itemId            = 0;
            GUIMovieListItem item = null;
            var movieImages       = new List <GUITmdbImage>();

            foreach (var credit in filteredCast)
            {
                // add image for download
                var images = new GUITmdbImage {
                    MovieImages = new TmdbMovieImages {
                        Id = credit.Movie.Ids.Tmdb
                    }
                };
                movieImages.Add(images);

                item                 = new GUIMovieListItem(credit.Movie.Title, (int)TraktGUIWindows.PersonCreditMovies);
                item.Label2          = credit.Movie.Year == null ? "----" : credit.Movie.Year.ToString();
                item.Movie           = credit.Movie;
                item.TVTag           = credit;
                item.Images          = images;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig    = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage  = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnCastSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.CurrentLayout = CurrentLayout;
            GUIControl.FocusControl(GetID, Facade.GetID);

            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", Facade.Count.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", filteredCast.Count, filteredCast.Count > 1 ? Translation.Movies : Translation.Movie));

            // Download movie images Async and set to facade
            GUIMovieListItem.GetImages(movieImages);
        }
All Usage Examples Of TraktPlugin.GUI.GUIMovieListItem::GetImages