add a method to use custom fallback fonts for subtitle rendering
This commit is contained in:
parent
912946a427
commit
c888b34a62
|
@ -6,6 +6,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
|
@ -122,8 +123,15 @@ namespace MediaBrowser.Api.Subtitles
|
||||||
public int SegmentLength { get; set; }
|
public int SegmentLength { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Route("/FallbackFont/Font", "GET", Summary = "Gets the fallback font file")]
|
||||||
|
[Authenticated]
|
||||||
|
public class GetFallbackFont
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public class SubtitleService : BaseApiService
|
public class SubtitleService : BaseApiService
|
||||||
{
|
{
|
||||||
|
private readonly IServerConfigurationManager _serverConfigurationManager;
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
private readonly ISubtitleManager _subtitleManager;
|
private readonly ISubtitleManager _subtitleManager;
|
||||||
private readonly ISubtitleEncoder _subtitleEncoder;
|
private readonly ISubtitleEncoder _subtitleEncoder;
|
||||||
|
@ -145,6 +153,7 @@ namespace MediaBrowser.Api.Subtitles
|
||||||
IAuthorizationContext authContext)
|
IAuthorizationContext authContext)
|
||||||
: base(logger, serverConfigurationManager, httpResultFactory)
|
: base(logger, serverConfigurationManager, httpResultFactory)
|
||||||
{
|
{
|
||||||
|
_serverConfigurationManager = serverConfigurationManager;
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_subtitleManager = subtitleManager;
|
_subtitleManager = subtitleManager;
|
||||||
_subtitleEncoder = subtitleEncoder;
|
_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,10 @@ namespace MediaBrowser.Model.Configuration
|
||||||
|
|
||||||
public string TranscodingTempPath { get; set; }
|
public string TranscodingTempPath { get; set; }
|
||||||
|
|
||||||
|
public string FallbackFontPath { get; set; }
|
||||||
|
|
||||||
|
public bool EnableFallbackFont { get; set; }
|
||||||
|
|
||||||
public double DownMixAudioBoost { get; set; }
|
public double DownMixAudioBoost { get; set; }
|
||||||
|
|
||||||
public bool EnableThrottling { get; set; }
|
public bool EnableThrottling { get; set; }
|
||||||
|
@ -49,6 +53,7 @@ namespace MediaBrowser.Model.Configuration
|
||||||
|
|
||||||
public EncodingOptions()
|
public EncodingOptions()
|
||||||
{
|
{
|
||||||
|
EnableFallbackFont = false;
|
||||||
DownMixAudioBoost = 2;
|
DownMixAudioBoost = 2;
|
||||||
EnableThrottling = false;
|
EnableThrottling = false;
|
||||||
ThrottleDelaySeconds = 180;
|
ThrottleDelaySeconds = 180;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user