The Free Software Media System - Server Backend & API
add a method to use custom fallback fonts for subtitle rendering
nyanmisakac888b34a6219
diff --git a/MediaBrowser.Api/Subtitles/SubtitleService.cs b/MediaBrowser.Api/Subtitles/SubtitleService.csindex a70da8e56c..198e459482 100644--- a/MediaBrowser.Api/Subtitles/SubtitleService.cs+++ b/MediaBrowser.Api/Subtitles/SubtitleService.cs@@ -6,6 +6,7 @@ using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;+using MediaBrowser.Common.Configuration;using MediaBrowser.Controller.Configuration;using MediaBrowser.Controller.Entities;using MediaBrowser.Controller.Library;@@ -122,8 +123,15 @@ namespace MediaBrowser.Api.Subtitlespublic int SegmentLength { get; set; }}+ [Route("/FallbackFont/Font", "GET", Summary = "Gets the fallback font file")]+ [Authenticated]+ public class GetFallbackFont+ {+ }+public class SubtitleService : BaseApiService{+ private readonly IServerConfigurationManager _serverConfigurationManager;private readonly ILibraryManager _libraryManager;private readonly ISubtitleManager _subtitleManager;private readonly ISubtitleEncoder _subtitleEncoder;@@ -145,6 +153,7 @@ namespace MediaBrowser.Api.SubtitlesIAuthorizationContext authContext): base(logger, serverConfigurationManager, httpResultFactory){+ _serverConfigurationManager = serverConfigurationManager;_libraryManager = libraryManager;_subtitleManager = subtitleManager;_subtitleEncoder = subtitleEncoder;@@ -298,5 +307,49 @@ namespace MediaBrowser.Api.Subtitles}});}++ public async Task<object> Get(GetFallbackFont request)+ {+ var fallbackFontPath = EncodingConfigurationExtensions.GetEncodingOptions(_serverConfigurationManager).FallbackFontPath;++ if (!string.IsNullOrEmpty(fallbackFontPath))+ {+ var directoryService = new DirectoryService(_fileSystem);++ try+ {+ // 10 Megabytes+ var maxSize = 10485760;+ var fontFile = directoryService.GetFile(fallbackFontPath);+ var fileSize = fontFile?.Length;++ if (fileSize != null && fileSize > 0)+ {+ Logger.LogInformation("Fallback font size is {0} Bytes", fileSize);++ if (fileSize <= maxSize)+ {+ return await ResultFactory.GetStaticFileResult(Request, fontFile.FullName);+ }++ Logger.LogInformation("The selected font is too large. Maximum allowed size is 10 Megabytes");+ }+ else+ {+ Logger.LogInformation("The selected font is null or empty");+ }+ }+ catch (Exception ex)+ {+ Logger.LogError(ex, "Error reading fallback font file");+ }+ }+ else+ {+ Logger.LogInformation("The path of fallback font has not been set");+ }++ return string.Empty;+ }}}diff --git a/MediaBrowser.Model/Configuration/EncodingOptions.cs b/MediaBrowser.Model/Configuration/EncodingOptions.csindex 9a30f7e9f0..aa6ed5bb9f 100644--- a/MediaBrowser.Model/Configuration/EncodingOptions.cs+++ b/MediaBrowser.Model/Configuration/EncodingOptions.cs@@ -9,6 +9,10 @@ namespace MediaBrowser.Model.Configurationpublic string TranscodingTempPath { get; set; }+ public string FallbackFontPath { get; set; }++ public bool EnableFallbackFont { get; set; }+public double DownMixAudioBoost { get; set; }public bool EnableThrottling { get; set; }@@ -49,6 +53,7 @@ namespace MediaBrowser.Model.Configurationpublic EncodingOptions(){+ EnableFallbackFont = false;DownMixAudioBoost = 2;EnableThrottling = false;ThrottleDelaySeconds = 180;