diff --git a/Jellyfin.Plugin.Shikimori/AnimeMangaBaseExtensions.cs b/Jellyfin.Plugin.Shikimori/AnimeMangaBaseExtensions.cs index b482496..369941d 100644 --- a/Jellyfin.Plugin.Shikimori/AnimeMangaBaseExtensions.cs +++ b/Jellyfin.Plugin.Shikimori/AnimeMangaBaseExtensions.cs @@ -10,10 +10,19 @@ namespace Jellyfin.Plugin.Shikimori { public static class AnimeMangaBaseExtensions { + private static string? GetPreferedTitle(SearchTitlePreferenceType type, AnimeMangaBase anime) + { + return type switch + { + SearchTitlePreferenceType.Romaji => anime.Name, + SearchTitlePreferenceType.Russian => anime.Russian, + _ => null, + }; + } public static RemoteSearchResult ToSearchResult(this AnimeMangaBase anime) { var result = new RemoteSearchResult(); - result.Name = ShikimoriPlugin.Instance?.Configuration.SearchTitlePreference == SearchTitlePreferenceType.Romaji ? anime.Name : anime.Russian; + result.Name = GetPreferedTitle(ShikimoriPlugin.Instance!.Configuration.SearchTitlePreference, anime); result.ProductionYear = anime.AiredOn?.DateTime.Year; result.PremiereDate = anime.AiredOn?.DateTime; result.ProviderIds = new Dictionary() { { ShikimoriPlugin.ProviderId, anime.Id.ToString() } }; @@ -40,34 +49,51 @@ public static class AnimeIdExtensions _ => null }; } + + private static string? GetPreferedTitle(TitlePreferenceType type, AnimeID anime) + { + // TODO: Fallback languages? + return type switch + { + TitlePreferenceType.Japanese => anime.Japanese.FirstOrDefault(), + TitlePreferenceType.Romaji => anime.Name, + TitlePreferenceType.Russian => anime.Russian, + _ => null + }; + } + + private static string? GetPreferedGenreTitle(GenreTitleLanguagePreferenceType type, Genre genre) + { + return type switch + { + GenreTitleLanguagePreferenceType.English => genre.Name, + GenreTitleLanguagePreferenceType.Russian => genre.Russian, + _ => null + }; + } public static Series ToSeries(this AnimeID anime) { var result = new Series { - Name = anime.Russian, - OriginalTitle = anime.Japanese.FirstOrDefault(), + Name = GetPreferedTitle(ShikimoriPlugin.Instance!.Configuration.TitlePreference, anime), + OriginalTitle = GetPreferedTitle(ShikimoriPlugin.Instance!.Configuration.OriginalTitlePreference, anime), Overview = anime.DescriptionHtml, ProductionYear = anime.AiredOn?.Year, PremiereDate = anime.AiredOn?.DateTime, EndDate = anime.ReleasedOn?.DateTime, - Genres = anime.Genres.Select(i => i.Russian).ToArray(), + Genres = anime.Genres.Select(i => GetPreferedGenreTitle(ShikimoriPlugin.Instance!.Configuration.GenreTitleLanguagePreference, i)).ToArray(), CommunityRating = float.Parse(anime.Score), OfficialRating = FormatRating(anime.Rating), Studios = anime.Studios.Select(i => { return i.Name;}).ToArray(), + Status = anime.Status switch + { + "released" => SeriesStatus.Ended, + "ongoing" => SeriesStatus.Continuing, + "anons" => SeriesStatus.Unreleased, + _ => null, + }, ProviderIds = new Dictionary {{ShikimoriPlugin.ProviderName, anime.Id.ToString()}}, }; - if (anime.Status == "released") - { - result.Status = SeriesStatus.Ended; - } - else if (anime.Status == "ongoing") - { - result.Status = SeriesStatus.Continuing; - } - else if (anime.Status == "anons") - { - result.Status = SeriesStatus.Unreleased; - } return result; } diff --git a/Jellyfin.Plugin.Shikimori/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.Shikimori/Configuration/PluginConfiguration.cs index 5ea6bb5..1982c70 100644 --- a/Jellyfin.Plugin.Shikimori/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.Shikimori/Configuration/PluginConfiguration.cs @@ -3,17 +3,33 @@ namespace Jellyfin.Plugin.Shikimori.Configuration { + public enum TitlePreferenceType + { + Romaji, + Russian, + Japanese + } + public enum SearchTitlePreferenceType { Romaji, Russian } + + public enum GenreTitleLanguagePreferenceType + { + English, + Russian + } public class PluginConfiguration : BasePluginConfiguration { public PluginConfiguration() { SearchLimit = 10; SearchTitlePreference = SearchTitlePreferenceType.Russian; + TitlePreference = TitlePreferenceType.Russian; + OriginalTitlePreference = TitlePreferenceType.Romaji; + GenreTitleLanguagePreference = GenreTitleLanguagePreferenceType.English; } private int _searchLimit; public int SearchLimit @@ -23,6 +39,9 @@ public int SearchLimit set => _searchLimit = (value >= 1 && value <= 50) ? value : _searchLimit; } - public SearchTitlePreferenceType SearchTitlePreference { get; set; } + public SearchTitlePreferenceType SearchTitlePreference { get; set; } + public TitlePreferenceType TitlePreference { get; set; } + public TitlePreferenceType OriginalTitlePreference { get; set; } + public GenreTitleLanguagePreferenceType GenreTitleLanguagePreference { get; set; } } } diff --git a/Jellyfin.Plugin.Shikimori/Configuration/config.html b/Jellyfin.Plugin.Shikimori/Configuration/config.html new file mode 100644 index 0000000..dbdaeae --- /dev/null +++ b/Jellyfin.Plugin.Shikimori/Configuration/config.html @@ -0,0 +1,106 @@ + + + + + Shikimori + + +
+
+
+
+
+ + +
Must be a number in range [1;50]
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+ +
+ + \ No newline at end of file diff --git a/Jellyfin.Plugin.Shikimori/Jellyfin.Plugin.Shikimori.csproj b/Jellyfin.Plugin.Shikimori/Jellyfin.Plugin.Shikimori.csproj index 72e5354..0691eff 100644 --- a/Jellyfin.Plugin.Shikimori/Jellyfin.Plugin.Shikimori.csproj +++ b/Jellyfin.Plugin.Shikimori/Jellyfin.Plugin.Shikimori.csproj @@ -12,4 +12,9 @@ + + + + + diff --git a/Jellyfin.Plugin.Shikimori/ShikimoriPlugin.cs b/Jellyfin.Plugin.Shikimori/ShikimoriPlugin.cs index 0b69682..eb06bf2 100644 --- a/Jellyfin.Plugin.Shikimori/ShikimoriPlugin.cs +++ b/Jellyfin.Plugin.Shikimori/ShikimoriPlugin.cs @@ -2,11 +2,12 @@ using MediaBrowser.Common.Plugins; using Jellyfin.Plugin.Shikimori.Configuration; using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Serialization; namespace Jellyfin.Plugin.Shikimori { - public class ShikimoriPlugin : BasePlugin + public class ShikimoriPlugin : BasePlugin, IHasWebPages { public IHttpClientFactory HttpClientFactory { get; init; } public ShikimoriPlugin( @@ -24,8 +25,19 @@ public ShikimoriPlugin( public const string ShikimoriBaseUrl = "https://shikimori.one"; public override string Name => "Shikimori"; - public override Guid Id => Guid.Parse("7EDB2A28-5B8A-4FE8-AE11-D941315EB862"); + public override Guid Id => Guid.Parse("7edb2a28-5b8a-4fe8-ae11-d941315eb862"); public static ShikimoriPlugin? Instance { get; private set; } + public IEnumerable GetPages() + { + return new[] + { + new PluginPageInfo + { + Name = Name, + EmbeddedResourcePath = $"{GetType().Namespace}.Configuration.config.html" + } + }; + } } }