Skip to content

Commit

Permalink
add title preprocessing for better searching
Browse files Browse the repository at this point in the history
  • Loading branch information
te9c committed Jan 10, 2025
1 parent 052bfbf commit a1e28c6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
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(info.Name, cancellationToken, AnimeType.Movie).ConfigureAwait(false);
anime = await _shikimoriClientManager.GetAnimeAsync(SearchHelper.PreprocessTitle(info.Name), cancellationToken, AnimeType.Movie).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(info.Name, cancellationToken, AnimeType.Tv).ConfigureAwait(false);
anime = await _shikimoriClientManager.GetAnimeAsync(SearchHelper.PreprocessTitle(info.Name), cancellationToken, AnimeType.Tv).ConfigureAwait(false);
result.QueriedById = false;
}

Expand Down
36 changes: 36 additions & 0 deletions Jellyfin.Plugin.Shikimori/SearchHelper.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit a1e28c6

Please sign in to comment.