Skip to content

Commit

Permalink
Merge pull request #54 from Musi13/fix-anidb-searching
Browse files Browse the repository at this point in the history
Fix metadata 403's and Add images to search results
  • Loading branch information
dkanada authored Mar 15, 2020
2 parents f831991 + d1c149a commit 5272775
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 16 deletions.
7 changes: 7 additions & 0 deletions Jellyfin.Plugin.Anime/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Jellyfin.Plugin.Anime
{
static class Constants
{
public const string UserAgent = "jellyfin-plugin-anime";
}
}
4 changes: 2 additions & 2 deletions Jellyfin.Plugin.Anime/Jellyfin.Plugin.Anime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Jellyfin.Plugin.Anime</RootNamespace>
<AssemblyVersion>4.0.0</AssemblyVersion>
<FileVersion>4.0.0</FileVersion>
<AssemblyVersion>5.0.0</AssemblyVersion>
<FileVersion>5.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AniDbTitleDownloader : IAniDbTitleDownloader
/// <summary>
/// The URL for retrieving a list of all anime titles and their AniDB IDs.
/// </summary>
private const string TitlesUrl = "http://anidb.net/api/animetitles.xml.gz";
private const string TitlesUrl = "http://anidb.net/api/anime-titles.xml.gz";

private readonly IApplicationPaths _paths;
private readonly ILogger _logger;
Expand Down Expand Up @@ -79,17 +79,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);
}

/// <summary>
Expand All @@ -101,6 +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", Constants.UserAgent);

await AniDbSeriesProvider.RequestLimiter.Tick().ConfigureAwait(false);
await Task.Delay(Plugin.Instance.Configuration.AniDB_wait_time).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ await AniDbSeriesProvider.GetSeriesData(

public Task<HttpResponseInfo> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public async Task<HttpResponseInfo> GetImageResponse(string url, CancellationTok

return await _httpClient.GetResponse(new HttpRequestOptions
{
UserAgent = Constants.UserAgent,
CancellationToken = cancellationToken,
Url = url
}).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public async Task<HttpResponseInfo> GetImageResponse(string url, CancellationTok

return await _httpClient.GetResponse(new HttpRequestOptions
{
UserAgent = Constants.UserAgent,
CancellationToken = cancellationToken,
Url = url
}).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ public async Task<IEnumerable<RemoteSearchResult>> 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
};
Expand All @@ -114,6 +118,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
{
return _httpClient.GetResponse(new HttpRequestOptions
{
UserAgent = Constants.UserAgent,
CancellationToken = cancellationToken,
Url = url
});
Expand Down Expand Up @@ -518,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
};
Expand Down
1 change: 1 addition & 0 deletions Jellyfin.Plugin.Anime/Providers/AniList/AniListApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ public async Task<RootObject> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
{
return _httpClient.GetResponse(new HttpRequestOptions
{
UserAgent = Constants.UserAgent,
CancellationToken = cancellationToken,
Url = url
});
Expand Down Expand Up @@ -160,6 +161,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
{
return _httpClient.GetResponse(new HttpRequestOptions
{
UserAgent = Constants.UserAgent,
CancellationToken = cancellationToken,
Url = url
});
Expand Down
1 change: 1 addition & 0 deletions Jellyfin.Plugin.Anime/Providers/AniSearch/AniSearchApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public static async Task<string> WebRequestAPI(string link)
string _strContent = "";
using (WebClient client = new WebClient())
{
client.Headers.Add("User-Agent", Constants.UserAgent);
Task<string> async_content = client.DownloadStringTaskAsync(link);
_strContent = await async_content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
{
return _httpClient.GetResponse(new HttpRequestOptions
{
UserAgent = Constants.UserAgent,
CancellationToken = cancellationToken,
Url = url
});
Expand Down Expand Up @@ -151,6 +152,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
{
return _httpClient.GetResponse(new HttpRequestOptions
{
UserAgent = Constants.UserAgent,
CancellationToken = cancellationToken,
Url = url
});
Expand Down
2 changes: 1 addition & 1 deletion build.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 5272775

Please sign in to comment.