-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathAniDbPersonProvider.cs
111 lines (91 loc) · 3.49 KB
/
AniDbPersonProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
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.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Anime.Providers.AniDB.Metadata
{
public class AniDbPersonProvider : IRemoteMetadataProvider<Person, PersonLookupInfo>
{
private readonly IApplicationPaths _paths;
public AniDbPersonProvider(IApplicationPaths paths)
{
_paths = paths;
}
public Task<MetadataResult<Person>> GetMetadata(PersonLookupInfo info, CancellationToken cancellationToken)
{
var result = new MetadataResult<Person>();
if (!string.IsNullOrEmpty(info.ProviderIds.GetOrDefault(ProviderNames.AniDb)))
{
return Task.FromResult(result);
}
var person = AniDbSeriesProvider.GetPersonInfo(_paths.CachePath, info.Name);
if (!string.IsNullOrEmpty(person?.Id))
{
result.Item = new Person();
result.HasMetadata = true;
result.Item.SetProviderId(ProviderNames.AniDb, person.Id);
}
return Task.FromResult(result);
}
public string Name => "AniDB";
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken)
{
return Task.FromResult(Enumerable.Empty<RemoteSearchResult>());
}
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
public class AniDbPersonImageProvider : IRemoteImageProvider
{
private readonly IHttpClient _httpClient;
private readonly IApplicationPaths _paths;
public AniDbPersonImageProvider(IApplicationPaths paths, IHttpClient httpClient)
{
_paths = paths;
_httpClient = httpClient;
}
public bool Supports(BaseItem item)
{
return item is Person;
}
public string Name => "AniDB";
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
yield return ImageType.Primary;
}
public Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var infos = new List<RemoteImageInfo>();
var person = AniDbSeriesProvider.GetPersonInfo(_paths.CachePath, item.Name);
if (person != null)
{
infos.Add(new RemoteImageInfo
{
Url = person.Image,
Type = ImageType.Primary,
ProviderName = Name
});
}
return Task.FromResult<IEnumerable<RemoteImageInfo>>(infos);
}
public async Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
await AniDbSeriesProvider.RequestLimiter.Tick().ConfigureAwait(false);
return await _httpClient.GetResponse(new HttpRequestOptions
{
UserAgent = Constants.UserAgent,
CancellationToken = cancellationToken,
Url = url
}).ConfigureAwait(false);
}
}
}