|
|
|
@ -6,17 +6,31 @@ using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
|
using MediaBrowser.Model.MediaInfo;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Nikse.SubtitleEdit.Core;
|
|
|
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
|
|
|
|
using SubtitleFormat = Nikse.SubtitleEdit.Core.SubtitleFormats.SubtitleFormat;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.MediaEncoding.Subtitles
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// SubStation Alpha subtitle parser.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T">The <see cref="Nikse.SubtitleEdit.Core.SubtitleFormats.SubtitleFormat" />.</typeparam>
|
|
|
|
|
/// <typeparam name="T">The <see cref="SubtitleFormat" />.</typeparam>
|
|
|
|
|
public abstract class SubtitleEditParser<T> : ISubtitleParser
|
|
|
|
|
where T : Nikse.SubtitleEdit.Core.SubtitleFormats.SubtitleFormat, new()
|
|
|
|
|
where T : SubtitleFormat, new()
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="SubtitleEditParser{T}"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
protected SubtitleEditParser(ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public SubtitleTrackInfo Parse(Stream stream, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
@ -24,6 +38,10 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
|
|
|
var subRip = new T();
|
|
|
|
|
var lines = stream.ReadAllLines().ToList();
|
|
|
|
|
subRip.LoadSubtitle(subtitle, lines, "untitled");
|
|
|
|
|
if (subRip.ErrorCount > 0)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError("{ErrorCount} errors encountered while parsing subtitle.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var trackInfo = new SubtitleTrackInfo();
|
|
|
|
|
int len = subtitle.Paragraphs.Count;
|
|
|
|
|