Exemple #1
0
        public List<MediaModel> MapObject(List<BaseItemDto> items, ApiClient client)
        {
            MMList = new List<MediaModel>();
              var imageoptions = new ImageOptions
              {
            ImageType = ImageType.Primary,
            Quality = 100
              };

              foreach (BaseItemDto item in items)
              {
            if (item.HasPrimaryImage)
            {
              initializeCatalog();
              MM.LargeCoverArt = client.GetImageUrl(item, imageoptions);
              MM.Title = item.Name;
              MM.Id = item.Path;
              MM.ReleaseYear = item.ProductionYear.ToString();
              MM.Synopsis = item.Overview;
              MM.AverageRating = item.OfficialRating;
              foreach (string g in item.Genres)
              {
            MM.Category.Add(g);
              }
              foreach (BaseItemPerson p in item.People)
              {
            MM.Cast.Add(p.Name);
              }
              MMList.Add(MM);
            }
              }
              return MMList;
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                var type = value.GetType();
                var apiClient = SimpleIoc.Default.GetInstance<IExtendedApiClient>();
                if (type == typeof(BaseItemDto))
                {

                    var imageType = parameter == null ? string.Empty : (string) parameter;
                    // http://192.168.0.2:8096/mediabrowser/api/image?item.Id=d0aac36ee980d7dc0bcf8323b1884f70&maxheight=173&quality=90
                    var item = (BaseItemDto)value;
                    return GetDtoImage(item, imageType, apiClient);
                }
                
                if (type == typeof(BaseItemPerson))
                {
                    var person = (BaseItemPerson)value;
                    if (person.HasPrimaryImage)
                    {
                        var smallImageSize = parameter == null;
                        return apiClient.GetPersonImageUrl(person, new ImageOptions
                        {
                            MaxWidth = smallImageSize ? 99 : 200, 
                            Quality = 90
                        });
                    }
                }
                
                if (type == typeof(UserDto))
                {
                    var user = (UserDto)value;
                    if (user.HasPrimaryImage)
                    {
                        var url = apiClient.GetUserImageUrl(user, new ImageOptions { MaxHeight = 173, MaxWidth = 173, Quality = 95 });
                        return new Uri(url);
                    }
                }

                if (type == typeof (SearchHint))
                {
                    var searchHint = (SearchHint) value;
                    var imageOptions = new ImageOptions
                    {
#if WP8
                        MaxHeight = 159,
                        MaxWidth = 159
#else
                        MaxHeight = 100,
                        MaxWidth = 100
#endif
                    };

                    switch (searchHint.Type)
                    {
                        case "Person":
                            return apiClient.GetPersonImageUrl(searchHint.Name, imageOptions);
                        case "Artist":
                            return apiClient.GetArtistImageUrl(searchHint.Name, imageOptions);
                        case "MusicGenre":
                        case "GameGenre":
                            return apiClient.GetGenreImageUrl(searchHint.Name, imageOptions);
                        case "Studio":
                            return apiClient.GetStudioImageUrl(searchHint.Name, imageOptions);
                        default:
                            return apiClient.GetImageUrl(searchHint.ItemId, imageOptions);
                    }
                }
                if (type == typeof (BaseItemInfo))
                {
                    var item = (BaseItemInfo) value;
                    var imageType = parameter == null ? string.Empty : (string)parameter;
                    var imageOptions = new ImageOptions
                    {
                        ImageType = ImageType.Primary
                    };

                    if (imageType.Equals("backdrop"))
                    {
                        imageOptions.ImageType = ImageType.Backdrop;
                        imageOptions.MaxWidth = 480;
                    }
                    else
                    {
#if !WP8
                        imageOptions.MaxHeight = 220;
#else
                        imageOptions.MaxHeight = 440;
#endif
                    }

                    return apiClient.GetImageUrl(item.Id, imageOptions);
                }
            }
            return "";
        }
        private static object GetDtoImage(BaseItemDto item, string imageType, IExtendedApiClient apiClient)
        {
            if (item.ImageTags.IsNullOrEmpty())
            {
                return "";
            }

            var imageOptions = new ImageOptions
            {
                Quality = 90,
#if WP8
                MaxHeight = 336,
#else
                                               MaxHeight = 173,
#endif
                ImageType = ImageType.Primary
            };
            if (imageType.Equals("logo", StringComparison.OrdinalIgnoreCase))
            {
                imageOptions.ImageType = ImageType.Logo;
            }
            else if (imageType.Equals("backdrop"))
            {
                imageOptions.MaxHeight = 800;
                imageOptions.ImageType = ImageType.Backdrop;

                var images = apiClient.GetBackdropImageUrls(item, imageOptions);
                if (!images.IsNullOrEmpty())
                {
                    return images.FirstOrDefault();
                }
            }
            else if (imageType.Equals("primaryorbackdrop"))
            {
                if (!item.HasPrimaryImage)
                {
                    imageOptions.MaxHeight = 800;
                    imageOptions.ImageType = ImageType.Backdrop;

                    var images = apiClient.GetBackdropImageUrls(item, imageOptions);
                    if (!images.IsNullOrEmpty())
                    {
                        return images.FirstOrDefault();
                    }
                }
            }
            else if (imageType.Equals("backdropsmall", StringComparison.OrdinalIgnoreCase))
            {
#if WP8
                imageOptions.MaxHeight = 336;
#else
                        imageOptions.MaxHeight = 173;
#endif
                imageOptions.ImageType = ImageType.Backdrop;

                var images = apiClient.GetBackdropImageUrls(item, imageOptions);
                if (!images.IsNullOrEmpty())
                {
                    return images.FirstOrDefault();
                }
            }
            else if (imageType.Equals("banner", StringComparison.OrdinalIgnoreCase))
            {
                imageOptions.MaxHeight = 140;
                imageOptions.ImageType = ImageType.Banner;
            }
            else if (imageType.Equals("art", StringComparison.OrdinalIgnoreCase))
            {
                imageOptions.ImageType = ImageType.Art;
            }
            else if (imageType.Equals("thumbnail", StringComparison.OrdinalIgnoreCase))
            {
                imageOptions.ImageType = ImageType.Thumb;
            }
            else if (imageType.Equals("icon", StringComparison.OrdinalIgnoreCase))
            {
#if WP8
                imageOptions.MaxHeight = 159;
#else
                        imageOptions.MaxHeight = 90;
#endif
            }
            else if (imageType.Equals("poster", StringComparison.OrdinalIgnoreCase))
            {
#if WP8
                imageOptions.MaxHeight = 675;
#else
                        imageOptions.MaxHeight = 450;
#endif
            }
            else if (imageType.Equals("episode", StringComparison.OrdinalIgnoreCase))
            {
#if WP8
                imageOptions.MaxHeight = 382;
#else
                        imageOptions.MaxHeight = 255;
#endif
            }
            else
            {
#if WP8
                imageOptions.MaxHeight = 300;
#else
                        imageOptions.MaxHeight = 200;
#endif
            }
            try
            {
                string url = item.Type == "Series" ? apiClient.GetImageUrl(item.Id, imageOptions) : apiClient.GetImageUrl(item, imageOptions);
                return url;
            }
            catch
            {
                return "";
            }
        }
        /// <summary>
        /// Gets the bitmap image async.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task{BitmapImage}.</returns>
        public Task<BitmapImage> GetBitmapImageAsync(ImageOptions options, CancellationToken cancellationToken)
        {
            string url;

            if (options.ImageType == ImageType.Logo)
            {
                url = _apiClient.GetLogoImageUrl(Item, options);
            }
            else if (options.ImageType == ImageType.Thumb)
            {
                url = _apiClient.GetThumbImageUrl(Item, options);
            }
            else if (options.ImageType == ImageType.Art)
            {
                url = _apiClient.GetArtImageUrl(Item, options);
            }
            else
            {
                url = _apiClient.GetImageUrl(Item, options);
            }

            return _imageManager.GetRemoteBitmapAsync(url, cancellationToken);
        }
        /// <summary>
        /// Gets an image url that can be used to download an image from the api
        /// </summary>
        /// <param name="imageType">The type of image requested</param>
        /// <param name="imageIndex">The image index, if there are multiple. Currently only applies to backdrops. Supply null or 0 for first backdrop.</param>
        /// <returns>System.String.</returns>
        private string GetImageUrl(ImageType imageType, int? imageIndex = null)
        {
            var scaleFactor = 1;

            var imageOptions = new ImageOptions
            {
                ImageType = imageType,
                ImageIndex = imageIndex,
                Width = Convert.ToInt32(ImageWidth * scaleFactor),
                EnableImageEnhancers = EnableServerImageEnhancers
            };

            if ((imageType == ImageType.Primary && DownloadPrimaryImageAtExactSize)
                || (imageType != ImageType.Primary && DownloadImagesAtExactSize))
            {
                imageOptions.Height = Convert.ToInt32(ImageHeight * scaleFactor);
            }

            if (imageType == ImageType.Thumb)
            {
                return _apiClient.GetThumbImageUrl(Item, imageOptions);
            }

            return _apiClient.GetImageUrl(Item, imageOptions);
        }
        /// <summary>
        /// Gets an image url that can be used to download an image from the api
        /// </summary>
        /// <param name="imageType">The type of image requested</param>
        /// <param name="imageIndex">The image index, if there are multiple. Currently only applies to backdrops. Supply null or 0 for first backdrop.</param>
        /// <returns>System.String.</returns>
        public string GetImageUrl(ImageType imageType, int? imageIndex = null)
        {
            var height = ImageHeight;

            var averageAspectRatio = BaseFolderPage.GetAspectRatio(imageType, AveragePrimaryImageAspectRatio);

            var width = height * averageAspectRatio;

            var imageOptions = new ImageOptions
            {
                ImageType = imageType,
                ImageIndex = imageIndex,
                Height = Convert.ToInt32(height)
            };

            var currentAspectRatio = imageType == ImageType.Primary ? Item.PrimaryImageAspectRatio ?? width / height : width / height;

            // Preserve the exact AR if it deviates from the average significantly
            var preserveExactAspectRatio = Math.Abs(currentAspectRatio - averageAspectRatio) > .15;

            if (!preserveExactAspectRatio)
            {
                imageOptions.Width = Convert.ToInt32(width);
            }

            if (Item.IsType("Person"))
            {
                return App.Instance.ApiClient.GetPersonImageUrl(Item, imageOptions);
            }

            return App.Instance.ApiClient.GetImageUrl(Item, imageOptions);
        }
        public async void DownloadImage()
        {
            _imageCancellationTokenSource = new CancellationTokenSource();

            if (Person.PrimaryImageTag.HasValue)
            {
                try
                {
                    var options = new ImageOptions
                    {
                        Height = ImageHeight,
                        Width = ImageWidth,
                        ImageType = ImageType.Primary,
                        Tag = Person.PrimaryImageTag
                    };

                    Image = await _imageManager.GetRemoteBitmapAsync(_apiClient.GetPersonImageUrl(Person, options), _imageCancellationTokenSource.Token);

                    DisposeCancellationTokenSource();

                    HasImage = true;
                }
                catch
                {
                    // Logged at lower levels
                    HasImage = false;
                }
            }
            else
            {
                HasImage = false;
            }

        }
        private static object GetDtoImage(BaseItemDto item, string imageType, IApiClient apiClient)
        {
            if (item.ImageTags.IsNullOrEmpty() && item.BackdropImageTags.IsNullOrEmpty())
            {
                return "";
            }

            var imageOptions = new ImageOptions
            {
                EnableImageEnhancers = App.SpecificSettings.EnableImageEnhancers,
                Quality = Constants.ImageQuality,
                MaxHeight = 336,
                ImageType = ImageType.Primary
            };

            if (item.Type == "Recording")
            {
                imageOptions.MaxHeight = 250;
            }
            else if (item.Type == "Program")
            {
                imageOptions.MaxHeight = 250;
            }
            else if (imageType.Equals("logo", StringComparison.OrdinalIgnoreCase))
            {
                imageOptions.ImageType = ImageType.Logo;
            }
            else if (imageType.Equals("backdrop"))
            {
                imageOptions.MaxHeight = 800;
                imageOptions.ImageType = ImageType.Backdrop;

                var images = apiClient.GetBackdropImageUrls(item, imageOptions);
                if (!images.IsNullOrEmpty())
                {
                    return images.FirstOrDefault();
                }
            }
            else if (imageType.Equals("primaryorbackdrop"))
            {
                if (!item.HasPrimaryImage)
                {
                    imageOptions.MaxHeight = 800;
                    imageOptions.ImageType = ImageType.Backdrop; 

                    var images = apiClient.GetBackdropImageUrls(item, imageOptions);
                    if (!images.IsNullOrEmpty())
                    {
                        return images.FirstOrDefault();
                    }
                }
            }
            else if (imageType.Equals("backdropsmall", StringComparison.OrdinalIgnoreCase))
            {
                imageOptions.MaxHeight = 336;
                imageOptions.ImageType = ImageType.Backdrop;

                var images = apiClient.GetBackdropImageUrls(item, imageOptions);
                if (!images.IsNullOrEmpty())
                {
                    return images.FirstOrDefault();
                }
            }
            else if (imageType.Equals("banner", StringComparison.OrdinalIgnoreCase))
            {
                imageOptions.MaxHeight = 140;
                imageOptions.ImageType = ImageType.Banner;
            }
            else if (imageType.Equals("art", StringComparison.OrdinalIgnoreCase))
            {
                imageOptions.ImageType = ImageType.Art;
            }
            else if (imageType.Equals("thumbnail", StringComparison.OrdinalIgnoreCase))
            {
                imageOptions.ImageType = ImageType.Thumb;
            }
            else if (imageType.Equals("icon", StringComparison.OrdinalIgnoreCase))
            {
                imageOptions.MaxHeight = 159;
            }
            else if (imageType.Equals("poster", StringComparison.OrdinalIgnoreCase))
            {
                imageOptions.MaxHeight = 675;
            }
            else if (imageType.Equals("episode", StringComparison.OrdinalIgnoreCase))
            {
                imageOptions.MaxHeight = 382;
            }
            else
            {
                imageOptions.MaxHeight = 300;
            }
            try
            {
                string url = item.Type == "Series" ? apiClient.GetImageUrl(item.Id, imageOptions) : apiClient.GetImageUrl(item, imageOptions);
                return url;
            }
            catch
            {
                return "";
            }
        }
Exemple #9
0
        private async void DownloadImage()
        {
            _imageCancellationTokenSource = new CancellationTokenSource();

            if (_chapter.ImageTag.HasValue) {
                var options = new ImageOptions {
                    Height = 100,
                    ImageIndex = _item.Chapters.IndexOf(_chapter),
                    ImageType = ImageType.Chapter,
                    Tag = _chapter.ImageTag
                };

                Image = await _imageManager.GetRemoteImageAsync(_apiClient.GetImageUrl(_item, options), _imageCancellationTokenSource.Token);
            }
        }
        private async void DownloadImage()
        {
            if (_user == null || !_user.PrimaryImageTag.HasValue) {
                return;
            }

            _imageCancellationTokenSource = new CancellationTokenSource();

            try {
                var options = new ImageOptions { ImageType = ImageType.Primary };
                Image = await _imageManager.GetRemoteBitmapAsync(_apiClient.GetUserImageUrl(_user, options), _imageCancellationTokenSource.Token);
            }
            finally {
                _imageCancellationTokenSource.Dispose();
                _imageCancellationTokenSource = null;
            }
        }
        private void LoadItems()
        {
            if (Items == null) {
                return;
            }

            const double tileWidth = HomeViewModel.TileWidth*2 + HomeViewModel.TileMargin;
            const double tileHeight = tileWidth*9/16;

            var imageOptions = new ImageOptions {
                Width = Convert.ToInt32(tileWidth),
                Height = Convert.ToInt32(tileHeight),
                ImageType = ImageType
            };

            _urlsToItems = Items.ToDictionary(i => _apiClient.GetImageUrl(i, imageOptions));

            Images.Images.Clear();
            Images.Images.AddRange(_urlsToItems.Keys);
            Images.StartRotating(10000);
        }
Exemple #12
0
        private async void DownloadImage()
        {
            _imageCancellationTokenSource = new CancellationTokenSource();

            if (_person.PrimaryImageTag.HasValue) {
                var options = new ImageOptions {
                    Height = 100,
                    ImageType = ImageType.Primary,
                    Tag = _person.PrimaryImageTag
                };

                Artwork = await _imageManager.GetRemoteImageAsync(_apiClient.GetPersonImageUrl(_person, options), _imageCancellationTokenSource.Token);
            }
        }
        private async void loadItems(ApiClient client)
        {
            var totalItems = 10;
            try
            {
                var result = await client.GetItemsAsync(new ItemQuery
                {
                    UserId = client.CurrentUserId,
                    IncludeItemTypes = new[] { "Movie" },
                    Limit = totalItems,
                    SortBy = new[] { ItemSortBy.DateCreated },
                    SortOrder = MediaBrowser.Model.Entities.SortOrder.Descending,
                    Recursive = true,
                    ImageTypes = new[] { ImageType.Backdrop },
                    Filters = new[] { ItemFilter.IsUnplayed },
                    Fields = new[] {
                    ItemFields.Path,
                    ItemFields.MediaStreams,
                    ItemFields.Genres,
                    }                

                });
                
                var items = result.Items.ToList();         
                MyMovieItems = items;
                var movielist = new List<string>();
                var movieimages = new List<BitmapImage>();                

                var imageoptions = new ImageOptions
                {
                    ImageType = ImageType.Primary,
                    Quality =  100                 
                };
                                             
                foreach (BaseItemDto item in items)
                {
                    if (item.HasPrimaryImage)
                    {
                        var uri = client.GetImageUrl(item, imageoptions);                        
                        BitmapImage bitmap = new BitmapImage();                      
                        bitmap.BeginInit();
                        bitmap.UriSource = new Uri(uri);
                        bitmap.EndInit();
                        movieimages.Add(bitmap);                     
                    }
                    movielist.Add(item.Name);
                }
                MyMoviesImages = movieimages;
                MyMovies = movielist;

            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show("error " + e.Message);
            }
        }
        private string GetChapterUrl(ChapterInfoDto chapter)
        {
            var imageOptions = new ImageOptions
            {
                MaxHeight = 173,
                ImageIndex = SelectedMovie.Chapters.IndexOf(chapter),
                ImageType = ImageType.Chapter,
                Tag = chapter.ImageTag,
                EnableImageEnhancers = App.SpecificSettings.EnableImageEnhancers
            };

            return chapter.HasImage ? ApiClient.GetImageUrl(SelectedMovie, imageOptions) : string.Empty;
        }
        public async void DownloadImage()
        {
            _imageCancellationTokenSource = new CancellationTokenSource();

            if (Chapter.ImageTag != null)
            {
                try
                {
                    var options = new ImageOptions
                    {
                        Width = ImageWidth,
                        ImageIndex = Item.Chapters.IndexOf(Chapter),
                        ImageType = ImageType.Chapter,
                        Tag = Chapter.ImageTag
                    };

                    Image = await _imageManager.GetRemoteBitmapAsync(_apiClient, _apiClient.GetImageUrl(Item, options),
                                                           _imageCancellationTokenSource.Token);

                    HasImage = true;
                    IsImageLoading = false;
                }
                catch (OperationCanceledException)
                {

                }
                catch
                {
                    // Logged at lower levels
                    HasImage = false;
                    IsImageLoading = false;
                }
                finally
                {
                    DisposeCancellationTokenSource();
                }
            }
            else
            {
                HasImage = false;
                IsImageLoading = false;
            }

        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                var type = value.GetType();
                var manager = SimpleIoc.Default.GetInstance<IConnectionManager>();
                var apiClient = manager.GetApiClient(App.ServerInfo.Id);
                if (type == typeof(BaseItemDto))
                {

                    var imageType = parameter == null ? string.Empty : (string) parameter;
                    // http://192.168.0.2:8096/mediabrowser/api/image?item.Id=d0aac36ee980d7dc0bcf8323b1884f70&maxheight=173&quality=90
                    var item = (BaseItemDto)value;
                    return GetDtoImage(item, imageType, apiClient);
                }
                
                if (type == typeof(BaseItemPerson))
                {
                    var person = (BaseItemPerson)value;
                    if (person.HasPrimaryImage)
                    {
                        var smallImageSize = parameter == null;
                        return apiClient.GetPersonImageUrl(person, new ImageOptions
                        {
                            MaxWidth = smallImageSize ? 99 : 200, 
                            Quality = Constants.ImageQuality,
                            EnableImageEnhancers = App.SpecificSettings.EnableImageEnhancers
                        });
                    }
                }
                
                if (type == typeof(UserDto))
                {
                    var user = (UserDto)value;
                    if (user.HasPrimaryImage)
                    {
                        var url = apiClient.GetUserImageUrl(user, new ImageOptions { MaxHeight = 250, MaxWidth = 250, Quality = Constants.ImageQuality });
                        return new Uri(url);
                    }
                }

                if (type == typeof (SearchHint))
                {
                    var searchHint = (SearchHint) value;
                    var imageOptions = new ImageOptions
                    {
                        EnableImageEnhancers = App.SpecificSettings.EnableImageEnhancers,
                        MaxHeight = 159,
                        MaxWidth = 159,
                        Quality = Constants.ImageQuality
                    };

                    switch (searchHint.Type)
                    {
                        case "MusicGenre":
                        case "GameGenre":
                            return apiClient.GetGenreImageUrl(searchHint.Name, imageOptions);
                        default:
                            return apiClient.GetImageUrl(searchHint.ItemId, imageOptions);
                    }
                }
                if (type == typeof (BaseItemInfo))
                {
                    var item = (BaseItemInfo) value;
                    var imageType = parameter == null ? string.Empty : (string)parameter;
                    var imageOptions = new ImageOptions
                    {
                        EnableImageEnhancers = App.SpecificSettings.EnableImageEnhancers,
                        ImageType = ImageType.Primary,
                        Quality = Constants.ImageQuality
                    };

                    if (imageType.Equals("backdrop"))
                    {
                        imageOptions.ImageType = ImageType.Backdrop;
                        imageOptions.MaxWidth = 480;
                    }
                    else
                    {
                        imageOptions.MaxHeight = 440;
                    }

                    return apiClient.GetImageUrl(item.Id, imageOptions);
                }
                if (type == typeof (ChannelInfoDto))
                {
                    var item = (ChannelInfoDto) value;
                    var imageOptions = new ImageOptions
                    {
                        ImageType = ImageType.Primary,
                        MaxHeight = 122,
                        Quality = Constants.ImageQuality
                    };

                    return item.HasPrimaryImage ? apiClient.GetImageUrl(item, imageOptions) : string.Empty;
                }
                if (type == typeof(TimerInfoDto))
                {
                    var item = (TimerInfoDto)value;
                    var imageOptions = new ImageOptions
                    {
                        ImageType = ImageType.Primary,
                        Quality = Constants.ImageQuality,
                        MaxHeight = 250
                    };

                    return item.ProgramInfo.HasPrimaryImage ? apiClient.GetImageUrl(item.ProgramInfo, imageOptions) : string.Empty;
                }
                
                if (type == typeof (SyncJob))
                {
                    var item = (SyncJob) value;
                    var imageOptions = new ImageOptions
                    {
                        ImageType = ImageType.Primary,
                        Quality = Constants.ImageQuality,
                        MaxHeight = 250,
                        Tag = item.PrimaryImageTag
                    };

                    return string.IsNullOrEmpty(item.PrimaryImageItemId) ? string.Empty : apiClient.GetImageUrl(item.PrimaryImageItemId, imageOptions);
                }

                if (type == typeof(SyncJobItem))
                {
                    var item = (SyncJobItem)value;
                    var imageOptions = new ImageOptions
                    {
                        ImageType = ImageType.Primary,
                        Quality = Constants.ImageQuality,
                        MaxHeight = 250,
                        Tag = item.PrimaryImageTag
                    };

                    return string.IsNullOrEmpty(item.PrimaryImageItemId) ? string.Empty : apiClient.GetImageUrl(item.PrimaryImageItemId, imageOptions);
                }
            }

            return "";
        }
        public async void DownloadImage()
        {
            _imageCancellationTokenSource = new CancellationTokenSource();

            if (User.PrimaryImageTag.HasValue)
            {
                try
                {
                    var options = new ImageOptions
                    {
                        Width = ImageWidth,
                        Height = ImageHeight,
                        ImageType = ImageType.Primary
                    };

                    Image = await ImageManager.GetRemoteBitmapAsync(ApiClient.GetUserImageUrl(User, options), _imageCancellationTokenSource.Token);

                    HasImage = true;
                }
                catch
                {
                    // Logged at lower levels
                    HasImage = false;
                }
                finally
                {
                    DisposeCancellationTokenSource();
                }
            }
            else
            {
                HasImage = false;
            }

        }
 private async Task GetImageAddToList(BaseItemDto item, IApiClient apiClient, List<Stream> list)
 {
     try
     {
         var options = new ImageOptions
         {
             ImageType = ImageType.Primary,
             MaxWidth = 112,
             Quality = Constants.ImageQuality,
             EnableImageEnhancers = false
         };
         var url = apiClient.GetImageUrl(item, options);
         using (var client = CreateClient())
         {
             var response = await client.GetAsync(url);
             var stream = await response.Content.ReadAsStreamAsync();
             list.Add(stream);
         }
     }
     catch (HttpException ex)
     {
         _logger.ErrorException("CreateNewWideTileAsync()", ex);
     }
 }
Exemple #19
0
        /// <summary>
        ///     Gets an image url that can be used to download an image from the api
        /// </summary>
        /// <param name="imageType">The type of image requested</param>
        /// <param name="imageIndex">
        ///     The image index, if there are multiple. Currently only applies to backdrops. Supply null or 0
        ///     for first backdrop.
        /// </param>
        /// <returns>System.String.</returns>
        private string GetImageUrl(ImageType imageType, int? imageIndex = null)
        {
            var imageOptions = new ImageOptions {
                ImageType = imageType,
                ImageIndex = imageIndex,
                Height = DesiredImageHeight != null && !double.IsPositiveInfinity((double) DesiredImageHeight) ? (int?) Convert.ToInt32(DesiredImageHeight) : null,
                EnableImageEnhancers = EnableServerImageEnhancers
            };

            if (EnforcePreferredImageAspectRatio
                || (imageType == ImageType.Primary && DownloadPrimaryImageAtExactSize)
                || (imageType != ImageType.Primary && DownloadImagesAtExactSize)) {
                if (DesiredImageWidth == null) {
                    imageOptions.Width = (int) ActualWidth;
                } else {
                    imageOptions.Width = DesiredImageWidth != null && !double.IsPositiveInfinity((double) DesiredImageWidth) ? (int?) Convert.ToInt32(DesiredImageWidth) : null;
                }
            }

            if (imageType == ImageType.Thumb) {
                return _apiClient.GetThumbImageUrl(_item, imageOptions);
            }

            return _apiClient.GetImageUrl(_item, imageOptions);
        }
 public string GetImageUrl(BaseItem item, ImageOptions options)
 {
     return item is MusicGenre ? Kernel.ApiClient.GetMusicGenreImageUrl(item.Name, options) :
                             item is Genre ? Kernel.ApiClient.GetGenreImageUrl(item.Name, options) :
                                         Kernel.ApiClient.GetImageUrl(item.ApiId, options);
 }
        /// <summary>
        /// Gets the bitmap image async.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task{BitmapImage}.</returns>
        public Task<BitmapImage> GetBitmapImageAsync(ImageOptions options, CancellationToken cancellationToken)
        {
            var url = _apiClient.GetImageUrl(Item, options);

            return _imageManager.GetRemoteBitmapAsync(url, cancellationToken);
        }