Esempio n. 1
0
        public async Task <bool> HasImagesAsync(string albumId, string category = "Front")
        {
            try
            {
                if (string.IsNullOrEmpty(albumId))
                {
                    return(false);
                }
                string url = GetUrl(URL_FANART_LIST, albumId);
                TrackImageCollection imageCollection = await DownloadAsync <TrackImageCollection>(url).ConfigureAwait(false);

                if (imageCollection != null)
                {
                    foreach (TrackImage image in imageCollection.Images)
                    {
                        foreach (string imageType in image.Types)
                        {
                            if (imageType.Equals(category, StringComparison.InvariantCultureIgnoreCase))
                            {
                                if (!string.IsNullOrEmpty(image.ImageUrl))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            catch { }

            return(false);
        }
        protected async Task <ApiWrapperImageCollection <TrackImage> > GetAlbumFanArtAsync(AlbumInfo album)
        {
            if (album == null || string.IsNullOrEmpty(album.MusicBrainzId))
            {
                return(null);
            }
            // Download all image information, filter later!
            TrackImageCollection albumImages = await _musicBrainzHandler.GetImagesAsync(album.MusicBrainzId).ConfigureAwait(false);

            if (albumImages == null)
            {
                return(null);
            }
            ApiWrapperImageCollection <TrackImage> images = new ApiWrapperImageCollection <TrackImage>();

            images.Id = album.MusicBrainzId;
            images.Covers.AddRange(albumImages.Images);
            return(images);
        }
        public override bool GetFanArt <T>(T infoObject, string language, string fanartMediaType, out ApiWrapperImageCollection <TrackImage> images)
        {
            images = new ApiWrapperImageCollection <TrackImage>();

            try
            {
                if (fanartMediaType == FanArtMediaTypes.Album)
                {
                    TrackInfo track = infoObject as TrackInfo;
                    AlbumInfo album = infoObject as AlbumInfo;
                    if (album == null && track != null)
                    {
                        album = track.CloneBasicInstance <AlbumInfo>();
                    }
                    if (album != null && !string.IsNullOrEmpty(album.MusicBrainzId))
                    {
                        // Download all image information, filter later!
                        TrackImageCollection albumImages = _musicBrainzHandler.GetImages(album.MusicBrainzId);
                        if (albumImages != null)
                        {
                            images.Id = album.MusicBrainzId;
                            images.Covers.AddRange(albumImages.Images);
                            return(true);
                        }
                    }
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Debug(GetType().Name + ": Exception downloading images", ex);
            }
            return(false);
        }