From 7bc370bdc72df5dac395b8fee805284b845ed911 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 21 Jan 2015 14:21:19 -0500 Subject: [PATCH] move desktop search --- .../Subtitles/SrtParser.cs | 17 +++++++++++++++++ .../Subtitles/SubtitleEncoder.cs | 2 +- .../MediaEncoding/Subtitles/SrtParserTests.cs | 3 ++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs index ad7db8ddf..9751176cb 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs @@ -1,4 +1,5 @@ using MediaBrowser.Model.Extensions; +using MediaBrowser.Model.Logging; using System; using System.Collections.Generic; using System.Globalization; @@ -10,7 +11,15 @@ namespace MediaBrowser.MediaEncoding.Subtitles { public class SrtParser : ISubtitleParser { + private readonly ILogger _logger; + private readonly CultureInfo _usCulture = new CultureInfo("en-US"); + + public SrtParser(ILogger logger) + { + _logger = logger; + } + public SubtitleTrackInfo Parse(Stream stream, CancellationToken cancellationToken) { var trackInfo = new SubtitleTrackInfo(); @@ -34,6 +43,14 @@ namespace MediaBrowser.MediaEncoding.Subtitles } var time = Regex.Split(line, @"[\t ]*-->[\t ]*"); + + if (time.Length < 2) + { + // This occurs when subtitle text has an empty line as part of the text. + // Need to adjust the break statement below to resolve this. + _logger.Warn("Unrecognized line in srt: {0}", line); + continue; + } subEvent.StartPositionTicks = GetTicks(time[0]); var endTime = time[1]; var idx = endTime.IndexOf(" ", StringComparison.Ordinal); diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs index 4723525e3..b9cad27e0 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs @@ -270,7 +270,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles if (string.Equals(format, SubtitleFormat.SRT, StringComparison.OrdinalIgnoreCase)) { - return new SrtParser(); + return new SrtParser(_logger); } if (string.Equals(format, SubtitleFormat.SSA, StringComparison.OrdinalIgnoreCase)) { diff --git a/MediaBrowser.Tests/MediaEncoding/Subtitles/SrtParserTests.cs b/MediaBrowser.Tests/MediaEncoding/Subtitles/SrtParserTests.cs index 6724ca597..8ea4398e9 100644 --- a/MediaBrowser.Tests/MediaEncoding/Subtitles/SrtParserTests.cs +++ b/MediaBrowser.Tests/MediaEncoding/Subtitles/SrtParserTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Threading; using MediaBrowser.MediaEncoding.Subtitles; +using MediaBrowser.Model.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace MediaBrowser.Tests.MediaEncoding.Subtitles @@ -92,7 +93,7 @@ namespace MediaBrowser.Tests.MediaEncoding.Subtitles } }; - var sut = new SrtParser(); + var sut = new SrtParser(new NullLogger()); var stream = File.OpenRead(@"MediaEncoding\Subtitles\TestSubtitles\unit.srt");