|
@@ -35,6 +35,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
private readonly IMediaEncoder _mediaEncoder;
|
|
private readonly IMediaEncoder _mediaEncoder;
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
private readonly IMediaSourceManager _mediaSourceManager;
|
|
private readonly IMediaSourceManager _mediaSourceManager;
|
|
|
|
+ private readonly ISubtitleParser _subtitleParser;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// The _semaphoreLocks.
|
|
/// The _semaphoreLocks.
|
|
@@ -48,7 +49,8 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
IFileSystem fileSystem,
|
|
IFileSystem fileSystem,
|
|
IMediaEncoder mediaEncoder,
|
|
IMediaEncoder mediaEncoder,
|
|
IHttpClientFactory httpClientFactory,
|
|
IHttpClientFactory httpClientFactory,
|
|
- IMediaSourceManager mediaSourceManager)
|
|
|
|
|
|
+ IMediaSourceManager mediaSourceManager,
|
|
|
|
+ ISubtitleParser subtitleParser)
|
|
{
|
|
{
|
|
_logger = logger;
|
|
_logger = logger;
|
|
_appPaths = appPaths;
|
|
_appPaths = appPaths;
|
|
@@ -56,6 +58,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
_mediaEncoder = mediaEncoder;
|
|
_mediaEncoder = mediaEncoder;
|
|
_httpClientFactory = httpClientFactory;
|
|
_httpClientFactory = httpClientFactory;
|
|
_mediaSourceManager = mediaSourceManager;
|
|
_mediaSourceManager = mediaSourceManager;
|
|
|
|
+ _subtitleParser = subtitleParser;
|
|
}
|
|
}
|
|
|
|
|
|
private string SubtitleCachePath => Path.Combine(_appPaths.DataPath, "subtitles");
|
|
private string SubtitleCachePath => Path.Combine(_appPaths.DataPath, "subtitles");
|
|
@@ -73,8 +76,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
|
|
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- var reader = GetReader(inputFormat);
|
|
|
|
- var trackInfo = reader.Parse(stream, cancellationToken);
|
|
|
|
|
|
+ var trackInfo = _subtitleParser.Parse(stream, inputFormat);
|
|
|
|
|
|
FilterEvents(trackInfo, startTimeTicks, endTimeTicks, preserveOriginalTimestamps);
|
|
FilterEvents(trackInfo, startTimeTicks, endTimeTicks, preserveOriginalTimestamps);
|
|
|
|
|
|
@@ -233,7 +235,8 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
var currentFormat = (Path.GetExtension(subtitleStream.Path) ?? subtitleStream.Codec)
|
|
var currentFormat = (Path.GetExtension(subtitleStream.Path) ?? subtitleStream.Codec)
|
|
.TrimStart('.');
|
|
.TrimStart('.');
|
|
|
|
|
|
- if (!TryGetReader(currentFormat, out _))
|
|
|
|
|
|
+ // Fallback to ffmpeg conversion
|
|
|
|
+ if (!_subtitleParser.SupportsFileExtension(currentFormat))
|
|
{
|
|
{
|
|
// Convert
|
|
// Convert
|
|
var outputPath = GetSubtitleCachePath(mediaSource, subtitleStream.Index, ".srt");
|
|
var outputPath = GetSubtitleCachePath(mediaSource, subtitleStream.Index, ".srt");
|
|
@@ -243,44 +246,10 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
return new SubtitleInfo(outputPath, MediaProtocol.File, "srt", true);
|
|
return new SubtitleInfo(outputPath, MediaProtocol.File, "srt", true);
|
|
}
|
|
}
|
|
|
|
|
|
- // It's possbile that the subtitleStream and mediaSource don't share the same protocol (e.g. .STRM file with local subs)
|
|
|
|
|
|
+ // It's possible that the subtitleStream and mediaSource don't share the same protocol (e.g. .STRM file with local subs)
|
|
return new SubtitleInfo(subtitleStream.Path, _mediaSourceManager.GetPathProtocol(subtitleStream.Path), currentFormat, true);
|
|
return new SubtitleInfo(subtitleStream.Path, _mediaSourceManager.GetPathProtocol(subtitleStream.Path), currentFormat, true);
|
|
}
|
|
}
|
|
|
|
|
|
- private bool TryGetReader(string format, [NotNullWhen(true)] out ISubtitleParser? value)
|
|
|
|
- {
|
|
|
|
- if (string.Equals(format, SubtitleFormat.SRT, StringComparison.OrdinalIgnoreCase))
|
|
|
|
- {
|
|
|
|
- value = new SrtParser(_logger);
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (string.Equals(format, SubtitleFormat.SSA, StringComparison.OrdinalIgnoreCase))
|
|
|
|
- {
|
|
|
|
- value = new SsaParser(_logger);
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (string.Equals(format, SubtitleFormat.ASS, StringComparison.OrdinalIgnoreCase))
|
|
|
|
- {
|
|
|
|
- value = new AssParser(_logger);
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- value = null;
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private ISubtitleParser GetReader(string format)
|
|
|
|
- {
|
|
|
|
- if (TryGetReader(format, out var reader))
|
|
|
|
- {
|
|
|
|
- return reader;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- throw new ArgumentException("Unsupported format: " + format);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private bool TryGetWriter(string format, [NotNullWhen(true)] out ISubtitleWriter? value)
|
|
private bool TryGetWriter(string format, [NotNullWhen(true)] out ISubtitleWriter? value)
|
|
{
|
|
{
|
|
if (string.Equals(format, SubtitleFormat.ASS, StringComparison.OrdinalIgnoreCase))
|
|
if (string.Equals(format, SubtitleFormat.ASS, StringComparison.OrdinalIgnoreCase))
|