Skip to content

Commit

Permalink
Feature: support plugin option API on Emby 4.8.x (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu authored Feb 5, 2024
1 parent b8a68d8 commit 4bd2be9
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 63 deletions.
207 changes: 156 additions & 51 deletions Jellyfin.Plugin.MetaTube/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,101 +1,190 @@
using Jellyfin.Plugin.MetaTube.Helpers;
using Jellyfin.Plugin.MetaTube.Translation;
#if __EMBY__
using System.ComponentModel;
using Emby.Web.GenericEdit;
using MediaBrowser.Model.Attributes;

#else
using MediaBrowser.Model.Plugins;
#endif

namespace Jellyfin.Plugin.MetaTube.Configuration;

#if __EMBY__
public class PluginConfiguration : EditableOptionsBase
{
public override string EditorTitle => Plugin.Instance.Name;
#else
public class PluginConfiguration : BasePluginConfiguration
{
#region Image
#endif

#if __EMBY__
[DisplayName("Server")]
[Description("Full url of the MetaTube Server, HTTPS protocol is recommended.")]
[Required]
#endif
public string Server { get; set; } = string.Empty;

#if __EMBY__
[DisplayName("Token")]
[Description("Access token for the MetaTube Server, or blank if no token is set by the backend.")]
#endif
public string Token { get; set; } = string.Empty;

public double PrimaryImageRatio { get; set; } = -1;
#if __EMBY__
[DisplayName("Enable collections")]
[Description("Automatically create collections by series.")]
#endif
public bool EnableCollections { get; set; } = false;

public int DefaultImageQuality { get; set; } = 90;
#if __EMBY__
[DisplayName("Enable directors")]
[Description("Add directors to corresponding video metadata.")]
#endif
public bool EnableDirectors { get; set; } = true;

#endregion
#if __EMBY__
[DisplayName("Enable ratings")]
[Description("Display community ratings from the original website.")]
#endif
public bool EnableRatings { get; set; } = true;

#region Badge
#if __EMBY__
[DisplayName("Enable trailers")]
[Description("Generate online video trailers in strm format.")]
#endif
public bool EnableTrailers { get; set; } = false;

#if __EMBY__
[DisplayName("Enable real actor names")]
[Description("Search and replace with real actor names from AVBASE.")]
#endif
public bool EnableRealActorNames { get; set; } = false;

#if __EMBY__
[DisplayName("Enable badges")]
[Description("Add Chinese subtitle badges to primary images.")]
#endif
public bool EnableBadges { get; set; } = false;

#if __EMBY__
[DisplayName("Badge url")]
[Description("Custom badge url, PNG format is recommended. (default: zimu.png)")]
#endif
public string BadgeUrl { get; set; } = "zimu.png";

#endregion

#region General

public string Server { get; set; } = "https://api.metatube.internal";

public string Token { get; set; } = string.Empty;

public bool EnableCollections { get; set; } = false;

public bool EnableDirectors { get; set; } = true;
#if __EMBY__
[DisplayName("Primary image ratio")]
[Description("Aspect ratio for primary images, set a negative value to use the default.")]
#endif
public double PrimaryImageRatio { get; set; } = -1;

public bool EnableRatings { get; set; } = true;
#if __EMBY__
[DisplayName("Default image quality")]
[Description("Default compression quality for JPEG images, set between 0 and 100. (default: 90)")]
[MinValue(0)]
[MaxValue(100)]
[Required]
#endif
public int DefaultImageQuality { get; set; } = 90;

public bool EnableTrailers { get; set; } = false;
#if __EMBY__
[DisplayName("Enable movie provider filter")]
[Description("Filter and reorder search results from movie providers.")]
#endif
public bool EnableMovieProviderFilter { get; set; } = false;

public bool EnableRealActorNames { get; set; } = false;
#if __EMBY__
[DisplayName("Movie provider filter")]
[Description(
"Provider names are case-insensitive, with decreasing precedence from left to right, separated by commas.")]
#endif
public string RawMovieProviderFilter
{
get => _movieProviderFilter?.Any() == true ? string.Join(',', _movieProviderFilter) : string.Empty;
set => _movieProviderFilter = value?.Split(',').Select(s => s.Trim()).Where(s => s.Any())
.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
}

#endregion
public List<string> GetMovieProviderFilter()
{
return _movieProviderFilter;
}

#region Template
private List<string> _movieProviderFilter;

#if __EMBY__
[DisplayName("Enable template")]
#endif
public bool EnableTemplate { get; set; } = false;

#if __EMBY__
[DisplayName("Name template")]
#endif
public string NameTemplate { get; set; } = DefaultNameTemplate;

#if __EMBY__
[DisplayName("Tagline template")]
#endif
public string TaglineTemplate { get; set; } = DefaultTaglineTemplate;

public static string DefaultNameTemplate => "{number} {title}";

public static string DefaultTaglineTemplate => "配信開始日 {date}";

#endregion

#region Translation

#if __EMBY__
[DisplayName("Translation mode")]
#endif
public TranslationMode TranslationMode { get; set; } = TranslationMode.Disabled;

#if __EMBY__
[DisplayName("Translation engine")]
#endif
public TranslationEngine TranslationEngine { get; set; } = TranslationEngine.Baidu;

#if __EMBY__
[DisplayName("Baidu app id")]
[VisibleCondition(nameof(TranslationEngine), ValueCondition.IsEqual, TranslationEngine.Baidu)]
#endif
public string BaiduAppId { get; set; } = string.Empty;

#if __EMBY__
[DisplayName("Baidu app key")]
[VisibleCondition(nameof(TranslationEngine), ValueCondition.IsEqual, TranslationEngine.Baidu)]
#endif
public string BaiduAppKey { get; set; } = string.Empty;

#if __EMBY__
[DisplayName("Google api key")]
[VisibleCondition(nameof(TranslationEngine), ValueCondition.IsEqual, TranslationEngine.Google)]
#endif
public string GoogleApiKey { get; set; } = string.Empty;

#if __EMBY__
[DisplayName("DeepL api key")]
[VisibleCondition(nameof(TranslationEngine), ValueCondition.IsEqual, TranslationEngine.DeepL)]
#endif
public string DeepLApiKey { get; set; } = string.Empty;

#if __EMBY__
[DisplayName("OpenAI api key")]
[VisibleCondition(nameof(TranslationEngine), ValueCondition.IsEqual, TranslationEngine.OpenAi)]
#endif
public string OpenAiApiKey { get; set; } = string.Empty;

#endregion

#region Provider

public bool EnableMovieProviderFilter { get; set; } = false;

public string RawMovieProviderFilter
{
get => _movieProviderFilter?.Any() == true ? string.Join(',', _movieProviderFilter) : string.Empty;
set => _movieProviderFilter = value?.Split(',').Select(s => s.Trim()).Where(s => s.Any())
.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
}

public List<string> GetMovieProviderFilter()
{
return _movieProviderFilter;
}

private List<string> _movieProviderFilter;

#endregion

#region Substitution

#if __EMBY__
[DisplayName("Enable title substitution")]
#endif
public bool EnableTitleSubstitution { get; set; } = false;

#if __EMBY__
[DisplayName("Title substitution table")]
[Description(
"One record per line, separated by equal signs. Leave the target substring blank to delete the source substring.")]
[EditMultiline(5)]
#endif
public string TitleRawSubstitutionTable
{
get => _titleSubstitutionTable?.ToString();
Expand All @@ -109,8 +198,17 @@ public SubstitutionTable GetTitleSubstitutionTable()

private SubstitutionTable _titleSubstitutionTable;

#if __EMBY__
[DisplayName("Enable actor substitution")]
#endif
public bool EnableActorSubstitution { get; set; } = false;

#if __EMBY__
[DisplayName("Actor substitution table")]
[Description(
"One record per line, separated by equal signs. Leave the target actor blank to delete the source actor.")]
[EditMultiline(5)]
#endif
public string ActorRawSubstitutionTable
{
get => _actorSubstitutionTable?.ToString();
Expand All @@ -124,8 +222,17 @@ public SubstitutionTable GetActorSubstitutionTable()

private SubstitutionTable _actorSubstitutionTable;

#if __EMBY__
[DisplayName("Enable genre substitution")]
#endif
public bool EnableGenreSubstitution { get; set; } = false;

#if __EMBY__
[DisplayName("Title substitution table")]
[Description(
"One record per line, separated by equal signs. Leave the target genre blank to delete the source genre.")]
[EditMultiline(5)]
#endif
public string GenreRawSubstitutionTable
{
get => _genreSubstitutionTable?.ToString();
Expand All @@ -138,6 +245,4 @@ public SubstitutionTable GetGenreSubstitutionTable()
}

private SubstitutionTable _genreSubstitutionTable;

#endregion
}
6 changes: 3 additions & 3 deletions Jellyfin.Plugin.MetaTube/Configuration/configPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h2>General</h2>
<input id="chkEnableRealActorNames" is="emby-checkbox" name="chkEnableRealActorNames" type="checkbox"/>
<span>Enable real actor names</span>
</label>
<div class="fieldDescription checkboxFieldDescription">Search and replace with real actor names from AVBASE (AVWIKI).</div>
<div class="fieldDescription checkboxFieldDescription">Search and replace with real actor names from AVBASE.</div>
</div>
</div>

Expand Down Expand Up @@ -99,13 +99,13 @@ <h2 class="sectionTitle">Image</h2>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="txtPrimaryImageRatio">Primary image ratio:</label>
<input id="txtPrimaryImageRatio" is="emby-input" name="txtPrimaryImageRatio" step="any" type="number"/>
<div class="fieldDescription">Aspect ratio for primary images, set a negtive value to use the default.</div>
<div class="fieldDescription">Aspect ratio for primary images, set a negative value to use the default.</div>
</div>

<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="txtDefaultImageQuality">Default image quality:</label>
<input id="txtDefaultImageQuality" is="emby-input" max="100" min="0" name="txtDefaultImageQuality" step="1" type="number"/>
<div class="fieldDescription">Default compression quality for JEPG images, set between 0 and 100. (default: 90)</div>
<div class="fieldDescription">Default compression quality for JPEG images, set between 0 and 100. (default: 90)</div>
</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions Jellyfin.Plugin.MetaTube/Jellyfin.Plugin.MetaTube.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='Debug.Emby' or '$(Configuration)'=='Release.Emby'">
<PackageReference Include="MediaBrowser.Server.Core" Version="4.7.1"/>
<PackageReference Include="MediaBrowser.Server.Core" Version="4.8.0.80"/>
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug' or '$(Configuration)'=='Release'">
<None Remove="Configuration\configPage.html"/>
<EmbeddedResource Include="Configuration\configPage.html"/>
</ItemGroup>
Expand Down
23 changes: 18 additions & 5 deletions Jellyfin.Plugin.MetaTube/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
using Jellyfin.Plugin.MetaTube.Configuration;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
#if __EMBY__
using MediaBrowser.Common;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Drawing;

#else
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Common.Configuration;
#endif

namespace Jellyfin.Plugin.MetaTube;

#if __EMBY__
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages, IHasThumbImage
public class Plugin : BasePluginSimpleUI<PluginConfiguration>, IHasThumbImage
{
public Plugin(IApplicationHost applicationHost) : base(applicationHost)
{
Instance = this;
}
#else
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
#endif
{
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) : base(applicationPaths,
xmlSerializer)
{
Instance = this;
}
#endif

public override string Name => "MetaTube";

Expand All @@ -29,6 +38,7 @@ public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)

public static Plugin Instance { get; private set; }

#if !__EMBY__
public IEnumerable<PluginPageInfo> GetPages()
{
return new[]
Expand All @@ -40,8 +50,11 @@ public IEnumerable<PluginPageInfo> GetPages()
}
};
}
#endif

#if __EMBY__
public PluginConfiguration Configuration => GetOptions();

public Stream GetThumbImage()
{
return GetType().Assembly.GetManifestResourceStream($"{GetType().Namespace}.thumb.png");
Expand Down
Loading

0 comments on commit 4bd2be9

Please sign in to comment.