public Task <TvDbResponse <Image[]> > GetImagesAsync(int tvdbId, ImagesQuery imageQuery, string language, CancellationToken cancellationToken) { var cacheKey = GenerateKey("images", tvdbId, language, imageQuery); return(TryGetValue(cacheKey, language, () => TvDbClient.Series.GetImagesAsync(tvdbId, imageQuery, cancellationToken))); }
public async Task <TvDbResponse <Image[]> > GetImagesAsync(int seriesId, ImagesQuery query, CancellationToken cancellationToken) { var request = new ApiRequest("GET", $"/series/{seriesId}/images/query?{this.UrlHelpers.Querify(query)}"); var response = await this.ApiClient.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); return(this.Parser.Parse <TvDbResponse <Image[]> >(response, ErrorMessages.Series.GetImagesAsync)); }
public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken) { if (!TvdbSeriesProvider.IsValidSeries(item.ProviderIds)) { return(Array.Empty <RemoteImageInfo>()); } var language = item.GetPreferredMetadataLanguage(); var remoteImages = new List <RemoteImageInfo>(); var keyTypes = new[] { KeyType.Poster, KeyType.Series, KeyType.Fanart }; var tvdbId = Convert.ToInt32(item.GetProviderId(MetadataProviders.Tvdb)); foreach (KeyType keyType in keyTypes) { var imageQuery = new ImagesQuery { KeyType = keyType }; try { var imageResults = await _tvdbClientManager.GetImagesAsync(tvdbId, imageQuery, language, cancellationToken) .ConfigureAwait(false); remoteImages.AddRange(GetImages(imageResults.Data, language)); } catch (TvDbServerException) { _logger.LogDebug("No images of type {KeyType} exist for series {TvDbId}", keyType, tvdbId); } } return(remoteImages); }
public async Task <IList <Image> > Handle(ImagesQuery query, CancellationToken cancellationToken) { IQueryable <Image> result = db.Images; if (query.Ids != null && query.Ids.Length > 0) { result = result.Where(item => query.Ids.Contains(item.ImageId)); } IList <Image> images = await result.ToListAsync(); return(images); }
// ReSharper disable once InconsistentNaming public Task GetImagesAsync_Makes_The_Right_Request(int seriesId, KeyType keyType, string resolution, string subKey) { var query = new ImagesQuery { Resolution = resolution, SubKey = subKey, KeyType = keyType }; return(CreateClient() .WithErrorMap(ErrorMessages.Series.GetImagesAsync) .SetResultObject(new TvDbResponse <Image[]>()) .WhenCallingAMethod((impl, token) => impl.GetImagesAsync(seriesId, query, token)) .ShouldRequest("GET", $"/series/{seriesId}/images/query?keyType={keyType}&resolution={resolution}&subKey={subKey}") .RunAsync()); }
/// <summary> /// Returns show banners for a show. /// </summary> public async Task <string[]> GetShowBannersAsync(int showTvDbId) => await _cache.GetOrCreateAsync($"{nameof(TvDbSearch)}_GetShowBannersAsync:{showTvDbId}", async entry => { // Cache Settings entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(2); // Result Factory. var imagesQuery = new ImagesQuery { KeyType = KeyType.Poster }; var images = await _client.Series.GetImagesAsync(showTvDbId, imagesQuery); return(images.Data .Select(img => $"https://artworks.thetvdb.com/banners/{img.FileName}") .ToArray()); });
// ReSharper disable once InconsistentNaming public async void GetImagesSummaryAsync_With_CancellationToken_Throws_With_The_Correct_Message(int statusCode) { var jsonClient = CreateJsonClient(); var client = this.CreateClient(jsonClient); var query = new ImagesQuery { KeyType = KeyType.Fanart, Resolution = "1280x720" }; jsonClient.GetJsonAsync <TvDbResponse <Image[]> >(null, CancellationToken.None) .ThrowsForAnyArgs(info => new TvDbServerException(null, (HttpStatusCode)statusCode, null)); var ex = await Assert.ThrowsAsync <TvDbServerException>(async() => await client.GetImagesAsync(42, query)); Assert.Equal(this.ErrorMessages.Series.GetImagesAsync[statusCode], ex.Message); }
static async Task <Image[]> GetSeriesImagesAsync(int seriesID, KeyType type) { await CheckAuthorizationAsync(); ImagesQuery query = new ImagesQuery { KeyType = type }; TvDBRateLimiter.Instance.EnsureRate(); try { var response = await client.Series.GetImagesAsync(seriesID, query); return(response.Data); } catch (TvDbServerException exception) { if (exception.StatusCode == (int)HttpStatusCode.Unauthorized) { client.Authentication.Token = null; await CheckAuthorizationAsync(); if (!string.IsNullOrEmpty(client.Authentication.Token)) { return(await GetSeriesImagesAsync(seriesID, type)); } // suppress 404 and move on } else if (exception.StatusCode == (int)HttpStatusCode.NotFound) { return new Image[] { } } ; logger.Error(exception, $"TvDB returned an error code: {exception.StatusCode}\n {exception.Message}"); Analytics.PostException(exception); } catch { // ignore } return(new Image[] { }); }
static async Task <Image[]> GetSeriesImagesAsync(int seriesID, KeyType type) { await _checkAuthorizationAsync(); ImagesQuery query = new ImagesQuery() { KeyType = type }; TvDBRateLimiter.Instance.EnsureRate(); try { var response = await client.Series.GetImagesAsync(seriesID, query); return(response.Data); } catch (TvDbSharper.Errors.TvDbServerException exception) { if (exception.StatusCode == HttpStatusCode.Unauthorized) { client.Authentication.Token = null; await _checkAuthorizationAsync(); if (client.Authentication.Token != null) { return(await GetSeriesImagesAsync(seriesID, type)); } // suppress 404 and move on } else if (exception.StatusCode == HttpStatusCode.NotFound) { return new Image[] { } } ; logger.Error(exception, "TvDB returned an error code: " + exception.StatusCode + "\n " + exception.Message); } catch { } return(new Image[] { }); }
public Task <TvDbResponse <Image[]> > GetImagesAsync(int seriesId, ImagesQuery query, CancellationToken cancellationToken) { try { string requestUri = $"/series/{seriesId}/images/query?{this.UrlHelpers.Querify(query)}"; return(this.GetAsync <Image[]>(requestUri, cancellationToken)); } catch (TvDbServerException ex) { string message = this.GetMessage(ex.StatusCode, this.ErrorMessages.Series.GetImagesAsync); if (message == null) { throw; } throw new TvDbServerException(message, ex.StatusCode, ex); } }
public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken) { var season = (Season)item; var series = season.Series; if (series == null || !season.IndexNumber.HasValue || !TvdbSeriesProvider.IsValidSeries(series.ProviderIds)) { return(Array.Empty <RemoteImageInfo>()); } var tvdbId = Convert.ToInt32(series.GetProviderId(MetadataProvider.Tvdb)); var seasonNumber = season.IndexNumber.Value; var language = item.GetPreferredMetadataLanguage(); var remoteImages = new List <RemoteImageInfo>(); var keyTypes = _tvdbClientManager.GetImageKeyTypesForSeasonAsync(tvdbId, language, cancellationToken).ConfigureAwait(false); await foreach (var keyType in keyTypes) { var imageQuery = new ImagesQuery { KeyType = keyType, SubKey = seasonNumber.ToString() }; try { var imageResults = await _tvdbClientManager .GetImagesAsync(tvdbId, imageQuery, language, cancellationToken).ConfigureAwait(false); remoteImages.AddRange(GetImages(imageResults.Data, language)); } catch (TvDbServerException) { _logger.LogDebug("No images of type {KeyType} found for series {TvdbId}", keyType, tvdbId); } } return(remoteImages); }
/// <inheritdoc /> public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken) { if (!TvdbSeriesProvider.IsValidSeries(item)) { return(Enumerable.Empty <RemoteImageInfo>()); } var language = item.GetPreferredMetadataLanguage(); var remoteImages = new List <RemoteImageInfo>(); var tvdbId = Convert.ToInt32(item.GetProviderId(TvdbPlugin.ProviderId), CultureInfo.InvariantCulture); var allowedKeyTypes = _tvdbClientManager.GetImageKeyTypesForSeriesAsync(tvdbId, language, cancellationToken) .ConfigureAwait(false); await foreach (KeyType keyType in allowedKeyTypes) { var imageQuery = new ImagesQuery { KeyType = keyType }; try { var imageResults = await _tvdbClientManager.GetImagesAsync(tvdbId, imageQuery, language, cancellationToken) .ConfigureAwait(false); remoteImages.AddRange(GetImages(imageResults.Data, language)); } catch (TvDbServerException) { _logger.LogDebug( "No images of type {KeyType} exist for series {TvDbId}", keyType, tvdbId); } } return(remoteImages); }
// ReSharper disable once InconsistentNaming public async void GetImagesSummaryAsync_With_CancellationToken_Makes_The_Right_Request() { var jsonClient = CreateJsonClient(); var client = this.CreateClient(jsonClient); const int Id = 42; const string Route = "/series/42/images/query?keyType=Fanart&resolution=1280x720"; var query = new ImagesQuery { KeyType = KeyType.Fanart, Resolution = "1280x720" }; var expectedData = new TvDbResponse <Image[]>(); jsonClient.GetJsonAsync <TvDbResponse <Image[]> >(Route, CancellationToken.None).Returns(expectedData); var responseData = await client.GetImagesAsync(Id, query); await jsonClient.Received().GetJsonAsync <TvDbResponse <Image[]> >(Route, CancellationToken.None); Assert.Equal(expectedData, responseData); }
public Task <TvDbResponse <Image[]> > GetImagesAsync(int seriesId, ImagesQuery query) { return(this.GetImagesAsync(seriesId, query, CancellationToken.None)); }
public async Task <IActionResult> Get([FromQuery] ImagesQuery query) { IEnumerable <Image> result = await mediatr.Send(query); return(Json(result)); }