diff --git a/Jellyfin.Plugin.Shikimori/Providers/ShikimoriMovieProvider.cs b/Jellyfin.Plugin.Shikimori/Providers/ShikimoriMovieProvider.cs index 1132b0c..63251b8 100644 --- a/Jellyfin.Plugin.Shikimori/Providers/ShikimoriMovieProvider.cs +++ b/Jellyfin.Plugin.Shikimori/Providers/ShikimoriMovieProvider.cs @@ -64,7 +64,7 @@ public async Task> GetMetadata(MovieInfo info, Cancellatio if (anime == null) { _log.LogDebug($"Searching {info.Name}"); - anime = await _shikimoriClientManager.GetAnimeAsync(info.Name, cancellationToken, AnimeType.Movie).ConfigureAwait(false); + anime = await _shikimoriClientManager.GetAnimeAsync(SearchHelper.PreprocessTitle(info.Name), cancellationToken, AnimeType.Movie).ConfigureAwait(false); result.QueriedById = false; } diff --git a/Jellyfin.Plugin.Shikimori/Providers/ShikimoriSeriesProvider.cs b/Jellyfin.Plugin.Shikimori/Providers/ShikimoriSeriesProvider.cs index d369717..b56ddda 100644 --- a/Jellyfin.Plugin.Shikimori/Providers/ShikimoriSeriesProvider.cs +++ b/Jellyfin.Plugin.Shikimori/Providers/ShikimoriSeriesProvider.cs @@ -65,7 +65,7 @@ public async Task> GetMetadata(SeriesInfo info, Cancellat if (anime == null) { _log.LogDebug($"Searching {info.Name}"); - anime = await _shikimoriClientManager.GetAnimeAsync(info.Name, cancellationToken, AnimeType.Tv).ConfigureAwait(false); + anime = await _shikimoriClientManager.GetAnimeAsync(SearchHelper.PreprocessTitle(info.Name), cancellationToken, AnimeType.Tv).ConfigureAwait(false); result.QueriedById = false; } diff --git a/Jellyfin.Plugin.Shikimori/SearchHelper.cs b/Jellyfin.Plugin.Shikimori/SearchHelper.cs new file mode 100644 index 0000000..24174a2 --- /dev/null +++ b/Jellyfin.Plugin.Shikimori/SearchHelper.cs @@ -0,0 +1,36 @@ +using System.Text.RegularExpressions; + +namespace Jellyfin.Plugin.Shikimori { + public static class SearchHelper { + // Taken from Anilist Jellyfin plugin + public static String PreprocessTitle(String path) { + String input = path; + + //Season designation + input = Regex.Replace( + input, + @"(\s|\.)S[0-9]{1,2}", String.Empty); + // ~ ALT NAME ~ + input = Regex.Replace( + input, + @"\s*~(\w|[0-9]|\s)+~", String.Empty); + + // Native Name (English Name) + // Only replaces if the name ends with a parenthesis to hopefully avoid mangling titles with parens (e.g. Evangelion 1.11 You Are (Not) Alone) + input = Regex.Replace( + input.Trim(), + @"\((\w|[0-9]|\s)+\)$", String.Empty); + + // Replace & with "and" to avoid lookup failures + input = Regex.Replace(input, @"\s?&\s?", " and "); + + // Replace the following characters with a space, to avoid failed lookups + input = Regex.Replace(input, @"\#", " "); + + // Truncate suggested Jellyfin folder format for the shikimori search. Example: The Melancholy of Haruhi Suzumiya (2006) [tvdbid-79414] + input = Regex.Replace(input.Trim(), @"\([0-9]{4}\)\s*\[(\w|[0-9]|-)+\]$", String.Empty); + + return input; + } + } +}