From 70a1c54f79c2a27575031b9fd10b90c0ff5e310b Mon Sep 17 00:00:00 2001 From: Alex Gonzales Date: Sun, 8 Mar 2020 20:40:15 -0500 Subject: [PATCH 1/3] Include User-Agent in AniDB titles request, add ImageUrl to search results --- .../Jellyfin.Plugin.Anime.csproj | 4 ++-- .../AniDB/Identity/AniDbTitleDownloader.cs | 16 ++++------------ .../AniDB/Metadata/AniDbEpisodeProvider.cs | 3 ++- .../AniDB/Metadata/AniDbSeriesProvider.cs | 4 ++++ build.yaml | 2 +- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Jellyfin.Plugin.Anime/Jellyfin.Plugin.Anime.csproj b/Jellyfin.Plugin.Anime/Jellyfin.Plugin.Anime.csproj index 435b116..3cb316a 100644 --- a/Jellyfin.Plugin.Anime/Jellyfin.Plugin.Anime.csproj +++ b/Jellyfin.Plugin.Anime/Jellyfin.Plugin.Anime.csproj @@ -3,8 +3,8 @@ netstandard2.0 Jellyfin.Plugin.Anime - 4.0.0 - 4.0.0 + 5.0.0 + 5.0.0 diff --git a/Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs b/Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs index 7a7306a..0fe44b0 100644 --- a/Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs +++ b/Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs @@ -18,7 +18,8 @@ public class AniDbTitleDownloader : IAniDbTitleDownloader /// /// The URL for retrieving a list of all anime titles and their AniDB IDs. /// - private const string TitlesUrl = "http://anidb.net/api/animetitles.xml.gz"; + private const string TitlesUrl = "http://anidb.net/api/anime-titles.xml.gz"; + private const string UserAgent = "mediabrowser"; private readonly IApplicationPaths _paths; private readonly ILogger _logger; @@ -79,17 +80,7 @@ public async Task Load(CancellationToken cancellationToken) private async Task DownloadTitles(string titlesFile) { _logger.LogDebug("Downloading new AniDB titles file."); - - var client = new WebClient(); - - await AniDbSeriesProvider.RequestLimiter.Tick().ConfigureAwait(false); - await Task.Delay(Plugin.Instance.Configuration.AniDB_wait_time).ConfigureAwait(false); - using (var stream = await client.OpenReadTaskAsync(TitlesUrl)) - using (var unzipped = new GZipStream(stream, CompressionMode.Decompress)) - using (var writer = File.Open(titlesFile, FileMode.Create, FileAccess.Write)) - { - await unzipped.CopyToAsync(writer).ConfigureAwait(false); - } + await DownloadTitles_static(titlesFile); } /// @@ -101,6 +92,7 @@ private async Task DownloadTitles(string titlesFile) private static async Task DownloadTitles_static(string titlesFile) { var client = new WebClient(); + client.Headers.Add("User-Agent", UserAgent); await AniDbSeriesProvider.RequestLimiter.Tick().ConfigureAwait(false); await Task.Delay(Plugin.Instance.Configuration.AniDB_wait_time).ConfigureAwait(false); diff --git a/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbEpisodeProvider.cs b/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbEpisodeProvider.cs index 3c3aee9..75201b4 100644 --- a/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbEpisodeProvider.cs +++ b/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbEpisodeProvider.cs @@ -154,7 +154,8 @@ await AniDbSeriesProvider.GetSeriesData( public Task GetImageResponse(string url, CancellationToken cancellationToken) { - throw new NotImplementedException(); + var imageProvider = new AniDbImageProvider(_httpClient, _configurationManager.ApplicationPaths); + return imageProvider.GetImageResponse(url, cancellationToken); } private async Task ParseAdditionalEpisodeXml(FileInfo xml, Episode episode, string metadataLanguage) diff --git a/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbSeriesProvider.cs b/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbSeriesProvider.cs index 9ad84a5..aebe307 100644 --- a/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbSeriesProvider.cs +++ b/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbSeriesProvider.cs @@ -95,11 +95,15 @@ public async Task> GetSearchResults(SeriesInfo s if (metadata.HasMetadata) { + var seriesId = metadata.Item.ProviderIds.GetOrDefault(ProviderNames.AniDb); + var imageProvider = new AniDbImageProvider(_httpClient, _appPaths); + var images = await imageProvider.GetImages(seriesId, cancellationToken); var res = new RemoteSearchResult { Name = metadata.Item.Name, PremiereDate = metadata.Item.PremiereDate, ProductionYear = metadata.Item.ProductionYear, + ImageUrl = images.Any() ? images.First().Url : null, ProviderIds = metadata.Item.ProviderIds, SearchProviderName = Name }; diff --git a/build.yaml b/build.yaml index 41677ce..7f28dfa 100644 --- a/build.yaml +++ b/build.yaml @@ -1,7 +1,7 @@ --- name: "jellyfin-plugin-anime" guid: "a4df60c5-6ab4-412a-8f79-2cab93fb2bc5" -version: "4" +version: "5" jellyfin_version: "10.3.0" owner: "jellyfin" nicename: "Anime" From a72991ebef3c9399dace4b17e7184a17b728ed09 Mon Sep 17 00:00:00 2001 From: Alex Gonzales Date: Mon, 9 Mar 2020 09:03:30 -0500 Subject: [PATCH 2/3] Change user agent to jellyfin specific --- .../Providers/AniDB/Identity/AniDbTitleDownloader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs b/Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs index 0fe44b0..e7a1418 100644 --- a/Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs +++ b/Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs @@ -19,7 +19,7 @@ public class AniDbTitleDownloader : IAniDbTitleDownloader /// The URL for retrieving a list of all anime titles and their AniDB IDs. /// private const string TitlesUrl = "http://anidb.net/api/anime-titles.xml.gz"; - private const string UserAgent = "mediabrowser"; + private const string UserAgent = "jellyfin-plugin-anime"; private readonly IApplicationPaths _paths; private readonly ILogger _logger; From d1c149a40c0d184fd8c4a1f3bd477ed9ea08c114 Mon Sep 17 00:00:00 2001 From: Alex Gonzales Date: Mon, 9 Mar 2020 23:08:36 -0500 Subject: [PATCH 3/3] Add User-Agent header to all requests --- Jellyfin.Plugin.Anime/Constants.cs | 7 +++++++ .../Providers/AniDB/Identity/AniDbTitleDownloader.cs | 3 +-- .../Providers/AniDB/Metadata/AniDbImageProvider.cs | 1 + .../Providers/AniDB/Metadata/AniDbPersonProvider.cs | 1 + .../Providers/AniDB/Metadata/AniDbSeriesProvider.cs | 2 ++ Jellyfin.Plugin.Anime/Providers/AniList/AniListApi.cs | 1 + .../Providers/AniList/AniListSeriesProvider.cs | 2 ++ Jellyfin.Plugin.Anime/Providers/AniSearch/AniSearchApi.cs | 1 + .../Providers/AniSearch/AniSearchSeriesProvider.cs | 2 ++ 9 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 Jellyfin.Plugin.Anime/Constants.cs diff --git a/Jellyfin.Plugin.Anime/Constants.cs b/Jellyfin.Plugin.Anime/Constants.cs new file mode 100644 index 0000000..3b9e8a4 --- /dev/null +++ b/Jellyfin.Plugin.Anime/Constants.cs @@ -0,0 +1,7 @@ +namespace Jellyfin.Plugin.Anime +{ + static class Constants + { + public const string UserAgent = "jellyfin-plugin-anime"; + } +} diff --git a/Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs b/Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs index e7a1418..3041026 100644 --- a/Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs +++ b/Jellyfin.Plugin.Anime/Providers/AniDB/Identity/AniDbTitleDownloader.cs @@ -19,7 +19,6 @@ public class AniDbTitleDownloader : IAniDbTitleDownloader /// The URL for retrieving a list of all anime titles and their AniDB IDs. /// private const string TitlesUrl = "http://anidb.net/api/anime-titles.xml.gz"; - private const string UserAgent = "jellyfin-plugin-anime"; private readonly IApplicationPaths _paths; private readonly ILogger _logger; @@ -92,7 +91,7 @@ private async Task DownloadTitles(string titlesFile) private static async Task DownloadTitles_static(string titlesFile) { var client = new WebClient(); - client.Headers.Add("User-Agent", UserAgent); + client.Headers.Add("User-Agent", Constants.UserAgent); await AniDbSeriesProvider.RequestLimiter.Tick().ConfigureAwait(false); await Task.Delay(Plugin.Instance.Configuration.AniDB_wait_time).ConfigureAwait(false); diff --git a/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbImageProvider.cs b/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbImageProvider.cs index c1e169b..42cb114 100644 --- a/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbImageProvider.cs +++ b/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbImageProvider.cs @@ -33,6 +33,7 @@ public async Task GetImageResponse(string url, CancellationTok return await _httpClient.GetResponse(new HttpRequestOptions { + UserAgent = Constants.UserAgent, CancellationToken = cancellationToken, Url = url }).ConfigureAwait(false); diff --git a/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbPersonProvider.cs b/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbPersonProvider.cs index 015902d..00755c8 100644 --- a/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbPersonProvider.cs +++ b/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbPersonProvider.cs @@ -102,6 +102,7 @@ public async Task GetImageResponse(string url, CancellationTok return await _httpClient.GetResponse(new HttpRequestOptions { + UserAgent = Constants.UserAgent, CancellationToken = cancellationToken, Url = url }).ConfigureAwait(false); diff --git a/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbSeriesProvider.cs b/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbSeriesProvider.cs index aebe307..18643ce 100644 --- a/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbSeriesProvider.cs +++ b/Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbSeriesProvider.cs @@ -118,6 +118,7 @@ public Task GetImageResponse(string url, CancellationToken can { return _httpClient.GetResponse(new HttpRequestOptions { + UserAgent = Constants.UserAgent, CancellationToken = cancellationToken, Url = url }); @@ -522,6 +523,7 @@ private static async Task DownloadSeriesData(string aid, string seriesDataPath, var requestOptions = new HttpRequestOptions { + UserAgent = Constants.UserAgent, Url = string.Format(SeriesQueryUrl, ClientName, aid), CancellationToken = cancellationToken }; diff --git a/Jellyfin.Plugin.Anime/Providers/AniList/AniListApi.cs b/Jellyfin.Plugin.Anime/Providers/AniList/AniListApi.cs index 7444ec0..be42b1e 100644 --- a/Jellyfin.Plugin.Anime/Providers/AniList/AniListApi.cs +++ b/Jellyfin.Plugin.Anime/Providers/AniList/AniListApi.cs @@ -371,6 +371,7 @@ public async Task WebRequestAPI(string link) string _strContent = ""; using (WebClient client = new WebClient()) { + client.Headers.Add("User-Agent", Constants.UserAgent); var values = new System.Collections.Specialized.NameValueCollection(); var response = await Task.Run(() => client.UploadValues(new Uri(link),values)); diff --git a/Jellyfin.Plugin.Anime/Providers/AniList/AniListSeriesProvider.cs b/Jellyfin.Plugin.Anime/Providers/AniList/AniListSeriesProvider.cs index 71bed51..b210296 100644 --- a/Jellyfin.Plugin.Anime/Providers/AniList/AniListSeriesProvider.cs +++ b/Jellyfin.Plugin.Anime/Providers/AniList/AniListSeriesProvider.cs @@ -106,6 +106,7 @@ public Task GetImageResponse(string url, CancellationToken can { return _httpClient.GetResponse(new HttpRequestOptions { + UserAgent = Constants.UserAgent, CancellationToken = cancellationToken, Url = url }); @@ -160,6 +161,7 @@ public Task GetImageResponse(string url, CancellationToken can { return _httpClient.GetResponse(new HttpRequestOptions { + UserAgent = Constants.UserAgent, CancellationToken = cancellationToken, Url = url }); diff --git a/Jellyfin.Plugin.Anime/Providers/AniSearch/AniSearchApi.cs b/Jellyfin.Plugin.Anime/Providers/AniSearch/AniSearchApi.cs index b05d69b..4c35bc9 100644 --- a/Jellyfin.Plugin.Anime/Providers/AniSearch/AniSearchApi.cs +++ b/Jellyfin.Plugin.Anime/Providers/AniSearch/AniSearchApi.cs @@ -297,6 +297,7 @@ public static async Task WebRequestAPI(string link) string _strContent = ""; using (WebClient client = new WebClient()) { + client.Headers.Add("User-Agent", Constants.UserAgent); Task async_content = client.DownloadStringTaskAsync(link); _strContent = await async_content; } diff --git a/Jellyfin.Plugin.Anime/Providers/AniSearch/AniSearchSeriesProvider.cs b/Jellyfin.Plugin.Anime/Providers/AniSearch/AniSearchSeriesProvider.cs index 7713752..a39cb1b 100644 --- a/Jellyfin.Plugin.Anime/Providers/AniSearch/AniSearchSeriesProvider.cs +++ b/Jellyfin.Plugin.Anime/Providers/AniSearch/AniSearchSeriesProvider.cs @@ -98,6 +98,7 @@ public Task GetImageResponse(string url, CancellationToken can { return _httpClient.GetResponse(new HttpRequestOptions { + UserAgent = Constants.UserAgent, CancellationToken = cancellationToken, Url = url }); @@ -151,6 +152,7 @@ public Task GetImageResponse(string url, CancellationToken can { return _httpClient.GetResponse(new HttpRequestOptions { + UserAgent = Constants.UserAgent, CancellationToken = cancellationToken, Url = url });