Exemple #1
0
        public virtual async Task <bool> DownloadFanArtAsync(Guid mediaItemId, BaseInfo info)
        {
            if (info == null)
            {
                return(false);
            }

            try
            {
                if (!await InitAsync().ConfigureAwait(false))
                {
                    return(false);
                }
                if (_wrapper == null)
                {
                    return(false);
                }

                TLang  language;
                string fanArtMediaType;
                bool   includeThumbnails;
                if (!TryGetFanArtInfo(info, out language, out fanArtMediaType, out includeThumbnails))
                {
                    return(false);
                }

                ApiWrapperImageCollection <TImg> images = await _wrapper.GetFanArtAsync(info, language, fanArtMediaType).ConfigureAwait(false);

                if (images == null)
                {
                    return(false);
                }

                string name = info.ToString();
                Logger.Debug(_id + " Download: Downloading images for {0} [{1}]", info, mediaItemId);

                await SaveFanArtImagesAsync(images.Id, images.Backdrops, language, mediaItemId, name, FanArtTypes.FanArt).ConfigureAwait(false);
                await SaveFanArtImagesAsync(images.Id, images.Posters, language, mediaItemId, name, FanArtTypes.Poster).ConfigureAwait(false);
                await SaveFanArtImagesAsync(images.Id, images.Banners, language, mediaItemId, name, FanArtTypes.Banner).ConfigureAwait(false);
                await SaveFanArtImagesAsync(images.Id, images.Covers, language, mediaItemId, name, FanArtTypes.Cover).ConfigureAwait(false);

                if (includeThumbnails)
                {
                    await SaveFanArtImagesAsync(images.Id, images.Thumbnails, language, mediaItemId, name, FanArtTypes.Thumbnail).ConfigureAwait(false);
                }
                if (!OnlyBasicFanArt)
                {
                    await SaveFanArtImagesAsync(images.Id, images.ClearArt, language, mediaItemId, name, FanArtTypes.ClearArt).ConfigureAwait(false);
                    await SaveFanArtImagesAsync(images.Id, images.DiscArt, language, mediaItemId, name, FanArtTypes.DiscArt).ConfigureAwait(false);
                    await SaveFanArtImagesAsync(images.Id, images.Logos, language, mediaItemId, name, FanArtTypes.Logo).ConfigureAwait(false);
                }
                Logger.Debug(_id + " Download: Finished saving images for {0} [{1}]", info, mediaItemId);
                return(true);
            }
            catch (WebException)
            {
                //Remote server probably returned an error/not found, just log at debug level
                Logger.Debug(_id + " Download: WebException when downloading images for {0} [{1}]", info, mediaItemId);
            }
            catch (Exception ex)
            {
                Logger.Warn(_id + " Download: Failed downloading images for {0} [{1}]", ex, info, mediaItemId);
            }
            return(false);
        }