Combined AniDB Series/Movie/Season Image provider into a single class, because they currently do the same thing

This commit is contained in:
Alex Gonzales 2020-03-08 12:16:56 -05:00
parent f45818d54c
commit a2dc42ae48
3 changed files with 6 additions and 121 deletions

View File

@ -8,18 +8,20 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Anime.Providers.AniDB.Metadata
{
public class AniDbSeriesImagesProvider : IRemoteImageProvider
public class AniDbImageProvider : IRemoteImageProvider
{
public string Name => "AniDB";
private readonly IHttpClient _httpClient;
private readonly IApplicationPaths _appPaths;
public AniDbSeriesImagesProvider(IHttpClient httpClient, IApplicationPaths appPaths)
public AniDbImageProvider(IHttpClient httpClient, IApplicationPaths appPaths)
{
_httpClient = httpClient;
_appPaths = appPaths;
@ -38,8 +40,7 @@ namespace Jellyfin.Plugin.Anime.Providers.AniDB.Metadata
public Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var series = (Series)item;
var seriesId = series.GetProviderId(ProviderNames.AniDb);
var seriesId = item.GetProviderId(ProviderNames.AniDb);
return GetImages(seriesId, cancellationToken);
}
@ -70,11 +71,9 @@ namespace Jellyfin.Plugin.Anime.Providers.AniDB.Metadata
return new[] { ImageType.Primary };
}
public string Name => "AniDB";
public bool Supports(BaseItem item)
{
return item is Series;
return item is Series || item is Season || item is Movie;
}
private async Task<string> FindImageUrl(string seriesDataPath)

View File

@ -1,56 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Anime.Providers.AniDB.Metadata
{
/// <summary>
/// Provides movie images fetched from AniDB. Interally, this class uses AniDbSeriesImagesProvider
/// as AniDB does not differentiate between shows and movies.
/// </summary>
public class AniDbMovieImageProvider : IRemoteImageProvider
{
public string Name => "AniDB";
private readonly AniDbSeriesImagesProvider _seriesImagesProvider;
public AniDbMovieImageProvider(IApplicationPaths appPaths, IHttpClient httpClient)
{
_seriesImagesProvider = new AniDbSeriesImagesProvider(httpClient, appPaths);
}
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _seriesImagesProvider.GetImageResponse(url, cancellationToken);
}
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var movie = (Movie)item;
var seriesId = movie.ProviderIds.GetOrDefault(ProviderNames.AniDb);
if (string.IsNullOrEmpty(seriesId))
{
return Enumerable.Empty<RemoteImageInfo>();
}
return await _seriesImagesProvider.GetImages(seriesId, cancellationToken);
}
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
return _seriesImagesProvider.GetSupportedImages(item);
}
public bool Supports(BaseItem item)
{
return item is Movie;
}
}
}

View File

@ -1,58 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Anime.Providers.AniDB.Metadata
{
/// <summary>
/// Copies the series image into a season, if the season does not otherwise have any primary image.
/// </summary>
public class AniDbSeasonImageProvider : IRemoteImageProvider
{
private readonly IApplicationPaths _appPaths;
private readonly IHttpClient _httpClient;
public AniDbSeasonImageProvider(IApplicationPaths appPaths, IHttpClient httpClient)
{
_appPaths = appPaths;
_httpClient = httpClient;
}
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
return new AniDbSeriesImagesProvider(_httpClient, _appPaths).GetImageResponse(url, cancellationToken);
}
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var season = (Season)item;
var series = season.Series;
var seriesId = series.ProviderIds.GetOrDefault(ProviderNames.AniDb);
if (string.IsNullOrEmpty(seriesId))
return Enumerable.Empty<RemoteImageInfo>();
return await new AniDbSeriesImagesProvider(_httpClient, _appPaths).GetImages(seriesId, cancellationToken);
}
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
return new[] { ImageType.Primary };
}
public string Name => "AniDB";
public bool Supports(BaseItem item)
{
return item is Season;
}
}
}