Skip to content

Commit 5272775

Browse files
authored
Merge pull request #54 from Musi13/fix-anidb-searching
Fix metadata 403's and Add images to search results
2 parents f831991 + d1c149a commit 5272775

12 files changed

+29
-16
lines changed

Jellyfin.Plugin.Anime/Constants.cs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Jellyfin.Plugin.Anime
2+
{
3+
static class Constants
4+
{
5+
public const string UserAgent = "jellyfin-plugin-anime";
6+
}
7+
}

Jellyfin.Plugin.Anime/Jellyfin.Plugin.Anime.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<RootNamespace>Jellyfin.Plugin.Anime</RootNamespace>
6-
<AssemblyVersion>4.0.0</AssemblyVersion>
7-
<FileVersion>4.0.0</FileVersion>
6+
<AssemblyVersion>5.0.0</AssemblyVersion>
7+
<FileVersion>5.0.0</FileVersion>
88
</PropertyGroup>
99

1010
<ItemGroup>

Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs

+3-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class AniDbTitleDownloader : IAniDbTitleDownloader
1818
/// <summary>
1919
/// The URL for retrieving a list of all anime titles and their AniDB IDs.
2020
/// </summary>
21-
private const string TitlesUrl = "http://anidb.net/api/animetitles.xml.gz";
21+
private const string TitlesUrl = "http://anidb.net/api/anime-titles.xml.gz";
2222

2323
private readonly IApplicationPaths _paths;
2424
private readonly ILogger _logger;
@@ -79,17 +79,7 @@ public async Task Load(CancellationToken cancellationToken)
7979
private async Task DownloadTitles(string titlesFile)
8080
{
8181
_logger.LogDebug("Downloading new AniDB titles file.");
82-
83-
var client = new WebClient();
84-
85-
await AniDbSeriesProvider.RequestLimiter.Tick().ConfigureAwait(false);
86-
await Task.Delay(Plugin.Instance.Configuration.AniDB_wait_time).ConfigureAwait(false);
87-
using (var stream = await client.OpenReadTaskAsync(TitlesUrl))
88-
using (var unzipped = new GZipStream(stream, CompressionMode.Decompress))
89-
using (var writer = File.Open(titlesFile, FileMode.Create, FileAccess.Write))
90-
{
91-
await unzipped.CopyToAsync(writer).ConfigureAwait(false);
92-
}
82+
await DownloadTitles_static(titlesFile);
9383
}
9484

9585
/// <summary>
@@ -101,6 +91,7 @@ private async Task DownloadTitles(string titlesFile)
10191
private static async Task DownloadTitles_static(string titlesFile)
10292
{
10393
var client = new WebClient();
94+
client.Headers.Add("User-Agent", Constants.UserAgent);
10495

10596
await AniDbSeriesProvider.RequestLimiter.Tick().ConfigureAwait(false);
10697
await Task.Delay(Plugin.Instance.Configuration.AniDB_wait_time).ConfigureAwait(false);

Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbEpisodeProvider.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ await AniDbSeriesProvider.GetSeriesData(
154154

155155
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
156156
{
157-
throw new NotImplementedException();
157+
var imageProvider = new AniDbImageProvider(_httpClient, _configurationManager.ApplicationPaths);
158+
return imageProvider.GetImageResponse(url, cancellationToken);
158159
}
159160

160161
private async Task ParseAdditionalEpisodeXml(FileInfo xml, Episode episode, string metadataLanguage)

Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbImageProvider.cs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public async Task<HttpResponseInfo> GetImageResponse(string url, CancellationTok
3333

3434
return await _httpClient.GetResponse(new HttpRequestOptions
3535
{
36+
UserAgent = Constants.UserAgent,
3637
CancellationToken = cancellationToken,
3738
Url = url
3839
}).ConfigureAwait(false);

Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbPersonProvider.cs

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public async Task<HttpResponseInfo> GetImageResponse(string url, CancellationTok
102102

103103
return await _httpClient.GetResponse(new HttpRequestOptions
104104
{
105+
UserAgent = Constants.UserAgent,
105106
CancellationToken = cancellationToken,
106107
Url = url
107108
}).ConfigureAwait(false);

Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbSeriesProvider.cs

+6
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,15 @@ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo s
9595

9696
if (metadata.HasMetadata)
9797
{
98+
var seriesId = metadata.Item.ProviderIds.GetOrDefault(ProviderNames.AniDb);
99+
var imageProvider = new AniDbImageProvider(_httpClient, _appPaths);
100+
var images = await imageProvider.GetImages(seriesId, cancellationToken);
98101
var res = new RemoteSearchResult
99102
{
100103
Name = metadata.Item.Name,
101104
PremiereDate = metadata.Item.PremiereDate,
102105
ProductionYear = metadata.Item.ProductionYear,
106+
ImageUrl = images.Any() ? images.First().Url : null,
103107
ProviderIds = metadata.Item.ProviderIds,
104108
SearchProviderName = Name
105109
};
@@ -114,6 +118,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
114118
{
115119
return _httpClient.GetResponse(new HttpRequestOptions
116120
{
121+
UserAgent = Constants.UserAgent,
117122
CancellationToken = cancellationToken,
118123
Url = url
119124
});
@@ -518,6 +523,7 @@ private static async Task DownloadSeriesData(string aid, string seriesDataPath,
518523

519524
var requestOptions = new HttpRequestOptions
520525
{
526+
UserAgent = Constants.UserAgent,
521527
Url = string.Format(SeriesQueryUrl, ClientName, aid),
522528
CancellationToken = cancellationToken
523529
};

Jellyfin.Plugin.Anime/Providers/AniList/AniListApi.cs

+1
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ public async Task<RootObject> WebRequestAPI(string link)
371371
string _strContent = "";
372372
using (WebClient client = new WebClient())
373373
{
374+
client.Headers.Add("User-Agent", Constants.UserAgent);
374375
var values = new System.Collections.Specialized.NameValueCollection();
375376

376377
var response = await Task.Run(() => client.UploadValues(new Uri(link),values));

Jellyfin.Plugin.Anime/Providers/AniList/AniListSeriesProvider.cs

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
106106
{
107107
return _httpClient.GetResponse(new HttpRequestOptions
108108
{
109+
UserAgent = Constants.UserAgent,
109110
CancellationToken = cancellationToken,
110111
Url = url
111112
});
@@ -160,6 +161,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
160161
{
161162
return _httpClient.GetResponse(new HttpRequestOptions
162163
{
164+
UserAgent = Constants.UserAgent,
163165
CancellationToken = cancellationToken,
164166
Url = url
165167
});

Jellyfin.Plugin.Anime/Providers/AniSearch/AniSearchApi.cs

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ public static async Task<string> WebRequestAPI(string link)
297297
string _strContent = "";
298298
using (WebClient client = new WebClient())
299299
{
300+
client.Headers.Add("User-Agent", Constants.UserAgent);
300301
Task<string> async_content = client.DownloadStringTaskAsync(link);
301302
_strContent = await async_content;
302303
}

Jellyfin.Plugin.Anime/Providers/AniSearch/AniSearchSeriesProvider.cs

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
9898
{
9999
return _httpClient.GetResponse(new HttpRequestOptions
100100
{
101+
UserAgent = Constants.UserAgent,
101102
CancellationToken = cancellationToken,
102103
Url = url
103104
});
@@ -151,6 +152,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
151152
{
152153
return _httpClient.GetResponse(new HttpRequestOptions
153154
{
155+
UserAgent = Constants.UserAgent,
154156
CancellationToken = cancellationToken,
155157
Url = url
156158
});

build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: "jellyfin-plugin-anime"
33
guid: "a4df60c5-6ab4-412a-8f79-2cab93fb2bc5"
4-
version: "4"
4+
version: "5"
55
jellyfin_version: "10.3.0"
66
owner: "jellyfin"
77
nicename: "Anime"

0 commit comments

Comments
 (0)