Skip to content

Commit

Permalink
fix bug when year was not considered in search
Browse files Browse the repository at this point in the history
  • Loading branch information
te9c committed Jan 10, 2025
1 parent a1e28c6 commit 809917f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 0 additions & 4 deletions Jellyfin.Plugin.Shikimori/Api/ApiModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

// Yeah I know that this model is total mess.
// But it's works. kinda.

namespace Jellyfin.Plugin.Shikimori.Api
{
public class Data
Expand All @@ -35,7 +32,6 @@ public class SearchOptions
public string? kind { get; set; }
public string? ids { get; set; }

// kostil
public override string ToString()
{
List<string> result = new List<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, Cancellatio
if (anime == null)
{
_log.LogDebug($"Searching {info.Name}");
anime = await _shikimoriClientManager.GetAnimeAsync(SearchHelper.PreprocessTitle(info.Name), cancellationToken, AnimeType.Movie).ConfigureAwait(false);
anime = await _shikimoriClientManager.GetAnimeAsync(SearchHelper.PreprocessTitle(info.Name), cancellationToken, AnimeType.Movie, info.Year).ConfigureAwait(false);
result.QueriedById = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, Cancellat
if (anime == null)
{
_log.LogDebug($"Searching {info.Name}");
anime = await _shikimoriClientManager.GetAnimeAsync(SearchHelper.PreprocessTitle(info.Name), cancellationToken, AnimeType.Tv).ConfigureAwait(false);
anime = await _shikimoriClientManager.GetAnimeAsync(SearchHelper.PreprocessTitle(info.Name), cancellationToken, AnimeType.Tv, info.Year).ConfigureAwait(false);
result.QueriedById = false;
}

Expand Down
18 changes: 14 additions & 4 deletions Jellyfin.Plugin.Shikimori/ShikimoriClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ public async Task<List<RemoteSearchResult>> SearchAnimesAsync(string name, Cance
};
}

public async Task<Anime?> GetAnimeAsync(string name, CancellationToken cancellationToken, AnimeType? type = null)
public async Task<Anime?> GetAnimeAsync(string name, CancellationToken cancellationToken, AnimeType? type = null, int? year = null)
{
var searchResult = await _shikimoriApi.SearchAnimesAsync(new SearchOptions
{
search = name,
limit = 1,
limit = year is null ? 1 : 10,
kind = type switch
{
AnimeType.Movie => string.Join(',', MovieKinds),
Expand All @@ -97,13 +97,23 @@ public async Task<List<RemoteSearchResult>> SearchAnimesAsync(string name, Cance

cancellationToken.ThrowIfCancellationRequested();

searchResult = searchResult.Where(i => {
if (year.HasValue && i.airedOn != null && i.airedOn.year.HasValue)
{
// One year tolerance
return Math.Abs(year.Value - i.airedOn.year.Value) <= 1;
}

return true;
});

if (!searchResult.Any())
{
return null;
}

var anime = await GetAnimeAsync(searchResult.First().id, cancellationToken, type).ConfigureAwait(false);
return anime;
var anime = searchResult.First();
return await GetAnimeAsync(anime.id, cancellationToken, type).ConfigureAwait(false);
}
}
}

0 comments on commit 809917f

Please sign in to comment.