Address comments

This commit is contained in:
Hans Lehnert 2024-09-02 00:55:03 -07:00
parent 702517f71b
commit d8f91ee518
7 changed files with 56 additions and 43 deletions

View File

@ -73,8 +73,7 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
var httpClient = Plugin.Instance.GetHttpClient();
using var httpClient = Plugin.Instance.GetHttpClient();
return await httpClient.GetAsync(url).ConfigureAwait(false);
}
}

View File

@ -212,7 +212,7 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
Variables = new Dictionary<string, string> {{"id", id}},
},
cancellationToken
);
).ConfigureAwait(false);
return result.data?.Media;
}
@ -225,7 +225,7 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
/// <returns></returns>
public async Task<MediaSearchResult> Search_GetSeries(string title, CancellationToken cancellationToken)
{
return (await Search_GetSeries_list(title, cancellationToken)).FirstOrDefault();
return (await Search_GetSeries_list(title, cancellationToken).ConfigureAwait(false)).FirstOrDefault();
}
/// <summary>
@ -242,7 +242,7 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
Variables = new Dictionary<string, string> {{"query", title}},
},
cancellationToken
);
).ConfigureAwait(false);
return result.data.Page.media;
}
@ -260,7 +260,7 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
return result.id.ToString();
}
result = await Search_GetSeries(await Equals_check.Clear_name(title, cancellationToken), cancellationToken);
result = await Search_GetSeries(await Equals_check.Clear_name(title, cancellationToken), cancellationToken).ConfigureAwait(false);
if (result != null)
{
return result.id.ToString();
@ -277,7 +277,7 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
Variables = new Dictionary<string, string> {{"id", id.ToString()}},
},
cancellationToken
);
).ConfigureAwait(false);
return result.data?.Staff;
}
@ -290,7 +290,7 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
Variables = new Dictionary<string, string> {{"query", query}},
},
cancellationToken
);
).ConfigureAwait(false);
return result.data?.Page.staff;
}

View File

@ -43,7 +43,7 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
var aid = info.ProviderIds.GetOrDefault(ProviderNames.AniList);
if (!string.IsNullOrEmpty(aid))
{
media = await _aniListApi.GetAnime(aid, cancellationToken);
media = await _aniListApi.GetAnime(aid, cancellationToken).ConfigureAwait(false);
}
else
{
@ -54,10 +54,10 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
searchName = Anitomy.AnitomyHelper.ExtractAnimeTitle(searchName);
searchName = AnilistSearchHelper.PreprocessTitle(searchName);
_log.LogInformation("Start AniList... Searching({Name})", searchName);
msr = await _aniListApi.Search_GetSeries(searchName, cancellationToken);
msr = await _aniListApi.Search_GetSeries(searchName, cancellationToken).ConfigureAwait(false);
if (msr != null)
{
media = await _aniListApi.GetAnime(msr.id.ToString(), cancellationToken);
media = await _aniListApi.GetAnime(msr.id.ToString(), cancellationToken).ConfigureAwait(false);
}
}
if(!config.UseAnitomyLibrary || media == null)
@ -65,10 +65,10 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
searchName = info.Name;
searchName = AnilistSearchHelper.PreprocessTitle(searchName);
_log.LogInformation("Start AniList... Searching({Name})", searchName);
msr = await _aniListApi.Search_GetSeries(searchName, cancellationToken);
msr = await _aniListApi.Search_GetSeries(searchName, cancellationToken).ConfigureAwait(false);
if (msr != null)
{
media = await _aniListApi.GetAnime(msr.id.ToString(), cancellationToken);
media = await _aniListApi.GetAnime(msr.id.ToString(), cancellationToken).ConfigureAwait(false);
}
}
}
@ -112,7 +112,7 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
var httpClient = Plugin.Instance.GetHttpClient();
using var httpClient = Plugin.Instance.GetHttpClient();
return await httpClient.GetAsync(url).ConfigureAwait(false);
}
}

View File

@ -31,17 +31,20 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
var results = new List<RemoteImageInfo>();
if (!item.TryGetProviderId(ProviderNames.AniList, out string stringId)
|| !int.TryParse(stringId, out int id)) {
|| !int.TryParse(stringId, out int id))
{
return results;
}
Staff staff = await _aniListApi.GetStaff(id, cancellationToken);
if (staff == null) {
Staff staff = await _aniListApi.GetStaff(id, cancellationToken).ConfigureAwait(false);
if (staff == null)
{
return results;
}
string imageUrl = staff.image.GetBestImage();
if (string.IsNullOrEmpty(imageUrl)) {
if (string.IsNullOrEmpty(imageUrl))
{
return results;
}
@ -56,7 +59,7 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
var httpClient = Plugin.Instance.GetHttpClient();
using var httpClient = Plugin.Instance.GetHttpClient();
return await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
}
}

View File

@ -12,7 +12,6 @@ using MediaBrowser.Model.Providers;
using Microsoft.Extensions.Logging;
//API v2
namespace Jellyfin.Plugin.AniList.Providers.AniList
{
public class AniListPersonProvider : IRemoteMetadataProvider<Person, PersonLookupInfo>, IHasOrder
@ -35,9 +34,10 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
var result = new MetadataResult<Person>();
int anilistId = int.Parse(info.GetProviderId(ProviderNames.AniList));
Staff staff = await _aniListApi.GetStaff(anilistId, cancellationToken);
Staff staff = await _aniListApi.GetStaff(anilistId, cancellationToken).ConfigureAwait(false);
if (staff == null) {
if (staff == null)
{
return result;
}
@ -48,13 +48,13 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken)
{
return (await _aniListApi.SearchStaff(searchInfo.Name, cancellationToken))
return (await _aniListApi.SearchStaff(searchInfo.Name, cancellationToken).ConfigureAwait(false))
.Select(s => s.ToSearchResult());
}
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
var httpClient = Plugin.Instance.GetHttpClient();
using var httpClient = Plugin.Instance.GetHttpClient();
return await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
}
}

View File

@ -40,7 +40,7 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
var aid = info.ProviderIds.GetOrDefault(ProviderNames.AniList);
if (!string.IsNullOrEmpty(aid))
{
media = await _aniListApi.GetAnime(aid, cancellationToken);
media = await _aniListApi.GetAnime(aid, cancellationToken).ConfigureAwait(false);
}
else
{
@ -52,10 +52,10 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
//todo Add episode/season?
searchName = AnilistSearchHelper.PreprocessTitle(searchName);
_log.LogInformation("Start AniList... Searching({Name})", searchName);
msr = await _aniListApi.Search_GetSeries(searchName, cancellationToken);
msr = await _aniListApi.Search_GetSeries(searchName, cancellationToken).ConfigureAwait(false);
if (msr != null)
{
media = await _aniListApi.GetAnime(msr.id.ToString(), cancellationToken);
media = await _aniListApi.GetAnime(msr.id.ToString(), cancellationToken).ConfigureAwait(false);
}
}
if(!config.UseAnitomyLibrary || media == null)
@ -63,10 +63,10 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
searchName = info.Name;
searchName = AnilistSearchHelper.PreprocessTitle(searchName);
_log.LogInformation("Start AniList... Searching({Name})", searchName);
msr = await _aniListApi.Search_GetSeries(searchName, cancellationToken);
msr = await _aniListApi.Search_GetSeries(searchName, cancellationToken).ConfigureAwait(false);
if (msr != null)
{
media = await _aniListApi.GetAnime(msr.id.ToString(), cancellationToken);
media = await _aniListApi.GetAnime(msr.id.ToString(), cancellationToken).ConfigureAwait(false);
}
}
}
@ -110,8 +110,7 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
var httpClient = Plugin.Instance.GetHttpClient();
using var httpClient = Plugin.Instance.GetHttpClient();
return await httpClient.GetAsync(url).ConfigureAwait(false);
}
}

View File

@ -32,8 +32,10 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
public int? month { get; set; }
public int? day { get; set; }
public DateTime? ToDateTime() {
if (this.day == null || this.month == null || this.year == null) {
public DateTime? ToDateTime()
{
if (this.day == null || this.month == null || this.year == null)
{
return null;
}
@ -181,13 +183,16 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
{
foreach (Staff va in edge.voiceActors)
{
if (config.PersonLanguageFilterPreference != LanguageFilterType.All) {
if (config.PersonLanguageFilterPreference != LanguageFilterType.All)
{
if (config.PersonLanguageFilterPreference == LanguageFilterType.Japanese
&& !va.language.Equals("Japanese", StringComparison.InvariantCultureIgnoreCase)) {
&& !va.language.Equals("Japanese", StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
if (config.PersonLanguageFilterPreference == LanguageFilterType.Localized
&& va.language.Equals("Japanese", StringComparison.InvariantCultureIgnoreCase)) {
&& va.language.Equals("Japanese", StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
}
@ -324,19 +329,23 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
public string medium { get; set; }
public string large { get; set; }
public string GetBestImage() {
if (IsValidImage(this.large)) {
public string GetBestImage()
{
if (IsValidImage(this.large))
{
return this.large;
}
if (IsValidImage(this.medium)) {
if (IsValidImage(this.medium))
{
return this.medium;
}
return null;
}
private static bool IsValidImage(string imageUrl) {
private static bool IsValidImage(string imageUrl)
{
// Filter out the default "No image" picture.
return !string.IsNullOrEmpty(imageUrl) && !imageUrl.EndsWith("default.jpg");
}
@ -368,7 +377,8 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
public FuzzyDate dateOfDeath { get; set; }
public string homeTown { get; set; }
public Person ToPerson() {
public Person ToPerson()
{
Person person = new Person {
Name = this.name.full,
OriginalTitle = this.name.native,
@ -378,14 +388,16 @@ namespace Jellyfin.Plugin.AniList.Providers.AniList
ProviderIds = new Dictionary<string, string>() {{ProviderNames.AniList, this.id.ToString()}}
};
if (!string.IsNullOrWhiteSpace(this.homeTown)) {
if (!string.IsNullOrWhiteSpace(this.homeTown))
{
person.ProductionLocations = new[] { this.homeTown };
}
return person;
}
public RemoteSearchResult ToSearchResult() {
public RemoteSearchResult ToSearchResult()
{
return new RemoteSearchResult() {
SearchProviderName = ProviderNames.AniList,
Name = this.name.full,