Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix metadata 403's and Add images to search results #54

Merged
merged 3 commits into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose we use a more proper user-agent string, such as;
jellyfin-plugin-anime/5.0.0.0 (+https://github.com/jellyfin/jellyfin-plugin-anime/issues) Jellyfin/10.5.0

https://en.wikipedia.org/wiki/User_agent has examples of how browsers and bots behave in this regard

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's save that for another pull request. This is an improvement and I'm sure people want it working again after the update so I'll push a new version for now.

}
}
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.0</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";
dkanada marked this conversation as resolved.
Show resolved Hide resolved

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);
}
dkanada marked this conversation as resolved.
Show resolved Hide resolved
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