From f1e87b4625cbe01e0806bb50e8c09537eec1276c Mon Sep 17 00:00:00 2001 From: zyd16888 Date: Tue, 8 Apr 2025 04:58:46 +0800 Subject: [PATCH] Feature: add `openai` custom translation support (#436) --- .../Configuration/PluginConfiguration.cs | 14 ++++++++++++++ .../Configuration/configPage.html | 14 ++++++++++++++ .../Translation/TranslationHelper.cs | 4 +++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Jellyfin.Plugin.MetaTube/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.MetaTube/Configuration/PluginConfiguration.cs index 323b56e..98c133d 100644 --- a/Jellyfin.Plugin.MetaTube/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.MetaTube/Configuration/PluginConfiguration.cs @@ -180,6 +180,20 @@ public class PluginConfiguration : BasePluginConfiguration #endif public string OpenAiApiKey { get; set; } = string.Empty; +#if __EMBY__ + [DisplayName("OpenAI api url")] + [Description("Custom OpenAI-compatible api url. (optional)")] + [VisibleCondition(nameof(TranslationEngine), ValueCondition.IsEqual, TranslationEngine.OpenAi)] +#endif + public string OpenAiApiUrl { get; set; } = string.Empty; + +#if __EMBY__ + [DisplayName("OpenAI model")] + [Description("Custom OpenAI-compatible api model. (optional)")] + [VisibleCondition(nameof(TranslationEngine), ValueCondition.IsEqual, TranslationEngine.OpenAi)] +#endif + public string OpenAiModel { get; set; } = string.Empty; + #if __EMBY__ [DisplayName("Enable title substitution")] #endif diff --git a/Jellyfin.Plugin.MetaTube/Configuration/configPage.html b/Jellyfin.Plugin.MetaTube/Configuration/configPage.html index 8326834..eab0660 100644 --- a/Jellyfin.Plugin.MetaTube/Configuration/configPage.html +++ b/Jellyfin.Plugin.MetaTube/Configuration/configPage.html @@ -217,6 +217,16 @@
+
+ + +
Custom OpenAI-compatible api url. (optional)
+
+
+ + +
Custom OpenAI-compatible api model. (optional)
+
@@ -350,6 +360,8 @@ $('#txtDeepLApiKey', page).val(config.DeepLApiKey).change(); $('#txtDeepLAltUrl', page).val(config.DeepLAltUrl).change(); $('#txtOpenAiApiKey', page).val(config.OpenAiApiKey).change(); + $('#txtOpenAiApiUrl', page).val(config.OpenAiApiUrl).change(); + $('#txtOpenAiModel', page).val(config.OpenAiModel).change(); page.querySelector('#chkEnableTitleSubstitution').checked = config.EnableTitleSubstitution; $('#txtTitleRawSubstitutionTable', page).val(config.TitleRawSubstitutionTable).change(); page.querySelector('#chkEnableActorSubstitution').checked = config.EnableActorSubstitution; @@ -388,6 +400,8 @@ config.DeepLApiKey = $('#txtDeepLApiKey', form).val(); config.DeepLXAltUrl = $('#txtDeepLAltUrl', form).val(); config.OpenAiApiKey = $('#txtOpenAiApiKey', form).val(); + config.OpenAiApiUrl = $('#txtOpenAiApiUrl', form).val(); + config.OpenAiModel = $('#txtOpenAiModel', form).val(); config.EnableTitleSubstitution = $('#chkEnableTitleSubstitution', form).prop('checked'); config.TitleRawSubstitutionTable = $('#txtTitleRawSubstitutionTable', form).val(); config.EnableActorSubstitution = $('#chkEnableActorSubstitution', form).prop('checked'); diff --git a/Jellyfin.Plugin.MetaTube/Translation/TranslationHelper.cs b/Jellyfin.Plugin.MetaTube/Translation/TranslationHelper.cs index 76aee5a..ba36ba1 100644 --- a/Jellyfin.Plugin.MetaTube/Translation/TranslationHelper.cs +++ b/Jellyfin.Plugin.MetaTube/Translation/TranslationHelper.cs @@ -51,7 +51,9 @@ public static class TranslationHelper millisecondsDelay = 1000; nv.Add(new NameValueCollection { - { "openai-api-key", Configuration.OpenAiApiKey } + { "openai-api-key", Configuration.OpenAiApiKey }, + { "openai-api-url", Configuration.OpenAiApiUrl }, + { "openai-model", Configuration.OpenAiModel } }); break; default: