Files
ersatztv/ErsatzTV.FFmpeg/Filter/SubtitlesFilter.cs
T
Jason DoveandGitHub 245c4ec359 code analysis and cleanup (#1411)
* cleanup scanner project

* cleanup infrastructure projects

* cleanup ffmpeg project

* cleanup core project

* cleanup app project

* cleanup main project

* update dependencies

* code cleanup
2023-09-03 06:23:42 -05:00

51 lines
1.5 KiB
C#

using System.Runtime.InteropServices;
namespace ErsatzTV.FFmpeg.Filter;
public class SubtitlesFilter : BaseFilter
{
private readonly string _fontsDir;
private readonly SubtitleInputFile _subtitleInputFile;
public SubtitlesFilter(string fontsDir, SubtitleInputFile subtitleInputFile)
{
_fontsDir = fontsDir;
_subtitleInputFile = subtitleInputFile;
}
public override string Filter
{
get
{
string fontsDir = _fontsDir;
string effectiveFile = _subtitleInputFile.Path;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
fontsDir = fontsDir
.Replace(@"\", @"/\")
.Replace(@":/", @"\\:/");
effectiveFile = effectiveFile
.Replace(@"\", @"/\");
if (!effectiveFile.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
effectiveFile = effectiveFile.Replace(@":/", @"\\:/");
}
}
// escape brackets after escaping for windows
effectiveFile = effectiveFile
.Replace(@"[", @"\[")
.Replace(@"]", @"\]")
.Replace(@"http://localhost:", @"http\\://localhost\\:");
return $"subtitles={effectiveFile}:fontsdir={fontsDir}";
}
}
public override FrameState NextState(FrameState currentState) =>
currentState with { FrameDataLocation = FrameDataLocation.Software };
}