Esempio n. 1
0
 public ComicVineMetadataProvider(ILogger logger, IHttpClient httpClient, IJsonSerializer jsonSerializer, IFileSystem fileSystem, IApplicationPaths appPaths)
 {
     _logger         = logger;
     _httpClient     = httpClient;
     _jsonSerializer = jsonSerializer;
     _fileSystem     = fileSystem;
     _appPaths       = appPaths;
     Current         = this;
 }
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(IHasImages item, CancellationToken cancellationToken)
        {
            var volumeId = item.GetProviderId(ComicVineVolumeExternalId.KeyName);

            var images = new List <RemoteImageInfo>();

            if (!string.IsNullOrEmpty(volumeId))
            {
                var issueNumber = ComicVineMetadataProvider.GetIssueNumberFromName(item.Name).ToString(_usCulture);

                await ComicVineMetadataProvider.Current.EnsureCacheFile(volumeId, issueNumber, cancellationToken).ConfigureAwait(false);

                var cachePath = ComicVineMetadataProvider.Current.GetCacheFilePath(volumeId, issueNumber);

                try
                {
                    var issueInfo = _jsonSerializer.DeserializeFromFile <SearchResult>(cachePath);

                    if (issueInfo.results.Count > 0)
                    {
                        var result = issueInfo.results[0].image;

                        if (!string.IsNullOrEmpty(result.medium_url))
                        {
                            images.Add(new RemoteImageInfo
                            {
                                Url          = result.medium_url,
                                ProviderName = Name
                            });
                        }
                    }
                }
                catch (FileNotFoundException)
                {
                }
                catch (DirectoryNotFoundException)
                {
                }
            }

            return(images);
        }