Change to IAsyncEnumerable

This commit is contained in:
Claus Vium 2020-07-15 17:14:39 +02:00
parent 8c0168ef72
commit 6d37a5fe52
3 changed files with 11 additions and 17 deletions

View File

@ -229,49 +229,43 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
return GetEpisodesPageAsync(tvdbId, 1, episodeQuery, language, cancellationToken);
}
public async Task<IEnumerable<KeyType>> GetImageKeyTypesForSeriesAsync(int tvdbId, string language, CancellationToken cancellationToken)
public async IAsyncEnumerable<KeyType> GetImageKeyTypesForSeriesAsync(int tvdbId, string language, CancellationToken cancellationToken)
{
var cacheKey = GenerateKey(nameof(TvDbClient.Series.GetImagesSummaryAsync), tvdbId);
var imagesSummary = await TryGetValue(cacheKey, language, () => TvDbClient.Series.GetImagesSummaryAsync(tvdbId, cancellationToken)).ConfigureAwait(false);
var keyTypes = new List<KeyType>();
if (imagesSummary.Data.Fanart > 0)
{
keyTypes.Add(KeyType.Fanart);
yield return KeyType.Fanart;
}
if (imagesSummary.Data.Series > 0)
{
keyTypes.Add(KeyType.Series);
yield return KeyType.Series;
}
if (imagesSummary.Data.Poster > 0)
{
keyTypes.Add(KeyType.Poster);
yield return KeyType.Poster;
}
return keyTypes;
}
public async Task<IEnumerable<KeyType>> GetImageKeyTypesForSeasonAsync(int tvdbId, string language, CancellationToken cancellationToken)
public async IAsyncEnumerable<KeyType> GetImageKeyTypesForSeasonAsync(int tvdbId, string language, CancellationToken cancellationToken)
{
var cacheKey = GenerateKey(nameof(TvDbClient.Series.GetImagesSummaryAsync), tvdbId);
var imagesSummary = await TryGetValue(cacheKey, language, () => TvDbClient.Series.GetImagesSummaryAsync(tvdbId, cancellationToken)).ConfigureAwait(false);
var keyTypes = new List<KeyType>();
if (imagesSummary.Data.Season > 0)
{
keyTypes.Add(KeyType.Season);
yield return KeyType.Season;
}
if (imagesSummary.Data.Fanart > 0)
{
keyTypes.Add(KeyType.Fanart);
yield return KeyType.Fanart;
}
// TODO seasonwide is not supported in TvDbSharper
return keyTypes;
}
private async Task<T> TryGetValue<T>(string key, string language, Func<Task<T>> resultFactory)

View File

@ -65,8 +65,8 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
var language = item.GetPreferredMetadataLanguage();
var remoteImages = new List<RemoteImageInfo>();
var keyTypes = await _tvdbClientManager.GetImageKeyTypesForSeasonAsync(tvdbId, language, cancellationToken).ConfigureAwait(false);
foreach (var keyType in keyTypes)
var keyTypes = _tvdbClientManager.GetImageKeyTypesForSeasonAsync(tvdbId, language, cancellationToken).ConfigureAwait(false);
await foreach (var keyType in keyTypes)
{
var imageQuery = new ImagesQuery
{

View File

@ -60,9 +60,9 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
var language = item.GetPreferredMetadataLanguage();
var remoteImages = new List<RemoteImageInfo>();
var tvdbId = Convert.ToInt32(item.GetProviderId(MetadataProvider.Tvdb));
var allowedKeyTypes = await _tvdbClientManager.GetImageKeyTypesForSeriesAsync(tvdbId, language, cancellationToken)
var allowedKeyTypes = _tvdbClientManager.GetImageKeyTypesForSeriesAsync(tvdbId, language, cancellationToken)
.ConfigureAwait(false);
foreach (KeyType keyType in allowedKeyTypes)
await foreach (KeyType keyType in allowedKeyTypes)
{
var imageQuery = new ImagesQuery
{