|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Threading; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using MediaBrowser.Common.Configuration; |
| 5 | +using MediaBrowser.Common.Net; |
| 6 | +using MediaBrowser.Controller.Entities.Movies; |
| 7 | +using MediaBrowser.Controller.Providers; |
| 8 | +using MediaBrowser.Model.Providers; |
| 9 | +using Microsoft.Extensions.Logging; |
| 10 | + |
| 11 | +namespace Jellyfin.Plugin.Anime.Providers.AniDB.Metadata |
| 12 | +{ |
| 13 | + public class AniDbMovieProvider : IRemoteMetadataProvider<Movie, MovieInfo> |
| 14 | + { |
| 15 | + private readonly AniDbSeriesProvider _seriesProvider; |
| 16 | + private readonly ILogger _log; |
| 17 | + |
| 18 | + public string Name => "AniDB"; |
| 19 | + |
| 20 | + public AniDbMovieProvider(IApplicationPaths appPaths, IHttpClient httpClient, ILoggerFactory loggerFactory) |
| 21 | + { |
| 22 | + _seriesProvider = new AniDbSeriesProvider(appPaths, httpClient); |
| 23 | + _log = loggerFactory.CreateLogger("AniDB"); |
| 24 | + } |
| 25 | + |
| 26 | + public async Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, CancellationToken cancellationToken) |
| 27 | + { |
| 28 | + // Empty result |
| 29 | + var result = new MetadataResult<Movie> |
| 30 | + { |
| 31 | + HasMetadata = false, |
| 32 | + Item = new Movie |
| 33 | + { |
| 34 | + Name = info.Name |
| 35 | + } |
| 36 | + }; |
| 37 | + |
| 38 | + var seriesId = info.ProviderIds.GetOrDefault(ProviderNames.AniDb); |
| 39 | + if (seriesId == null) |
| 40 | + { |
| 41 | + return result; |
| 42 | + } |
| 43 | + |
| 44 | + var seriesInfo = new SeriesInfo(); |
| 45 | + seriesInfo.ProviderIds.Add(ProviderNames.AniDb, seriesId); |
| 46 | + |
| 47 | + var seriesResult = await _seriesProvider.GetMetadata(seriesInfo, cancellationToken); |
| 48 | + if (seriesResult.HasMetadata) |
| 49 | + { |
| 50 | + result = new MetadataResult<Movie> |
| 51 | + { |
| 52 | + HasMetadata = true, |
| 53 | + Item = new Movie |
| 54 | + { |
| 55 | + Name = seriesResult.Item.Name, |
| 56 | + Overview = seriesResult.Item.Overview, |
| 57 | + PremiereDate = seriesResult.Item.PremiereDate, |
| 58 | + ProductionYear = seriesResult.Item.ProductionYear, |
| 59 | + EndDate = seriesResult.Item.EndDate, |
| 60 | + CommunityRating = seriesResult.Item.CommunityRating, |
| 61 | + Studios = seriesResult.Item.Studios, |
| 62 | + Genres = seriesResult.Item.Genres, |
| 63 | + ProviderIds = seriesResult.Item.ProviderIds, |
| 64 | + }, |
| 65 | + People = seriesResult.People, |
| 66 | + Images = seriesResult.Images |
| 67 | + }; |
| 68 | + } |
| 69 | + |
| 70 | + return result; |
| 71 | + } |
| 72 | + |
| 73 | + public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken) |
| 74 | + { |
| 75 | + var seriesInfo = new SeriesInfo(); |
| 76 | + var seriesId = searchInfo.ProviderIds.GetOrDefault(ProviderNames.AniDb); |
| 77 | + if (seriesId != null) |
| 78 | + { |
| 79 | + seriesInfo.ProviderIds.Add(ProviderNames.AniDb, seriesId); |
| 80 | + } |
| 81 | + seriesInfo.Name = searchInfo.Name; |
| 82 | + |
| 83 | + return await _seriesProvider.GetSearchResults(seriesInfo, cancellationToken); |
| 84 | + } |
| 85 | + |
| 86 | + public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken) |
| 87 | + { |
| 88 | + return _seriesProvider.GetImageResponse(url, cancellationToken); |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments