diff --git a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj index 9263a31875..22873d910c 100644 --- a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj +++ b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj @@ -62,6 +62,7 @@ + diff --git a/MediaBrowser.MediaEncoding/Subtitles/AssParser.cs b/MediaBrowser.MediaEncoding/Subtitles/AssParser.cs index e5a7274282..aaaafc2265 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/AssParser.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/AssParser.cs @@ -1,4 +1,5 @@ -using System; +using MediaBrowser.Common.Extensions; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -42,6 +43,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles subEvent.StartPositionTicks = GetTicks(sections[headers["Start"]]); subEvent.EndPositionTicks = GetTicks(sections[headers["End"]]); subEvent.Text = string.Join(",", sections.Skip(headers["Text"])); + subEvent.Text = subEvent.Text.Replace(@"\N", ParserValues.NewLine, StringComparison.OrdinalIgnoreCase); subEvent.Text = Regex.Replace(subEvent.Text, @"\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}", string.Empty, RegexOptions.IgnoreCase); trackInfo.TrackEvents.Add(subEvent); diff --git a/MediaBrowser.MediaEncoding/Subtitles/ParserValues.cs b/MediaBrowser.MediaEncoding/Subtitles/ParserValues.cs new file mode 100644 index 0000000000..d79aeee76b --- /dev/null +++ b/MediaBrowser.MediaEncoding/Subtitles/ParserValues.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MediaBrowser.MediaEncoding.Subtitles +{ + public class ParserValues + { + public const string NewLine = "\r\n"; + } +} diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs index 84cd1eb2d3..ea565f70a5 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.IO; using System.Text.RegularExpressions; using System.Threading; +using MediaBrowser.Common.Extensions; namespace MediaBrowser.MediaEncoding.Subtitles { @@ -48,7 +49,8 @@ namespace MediaBrowser.MediaEncoding.Subtitles } multiline.Add(line); } - subEvent.Text = string.Join(@"\n", multiline); + subEvent.Text = string.Join(ParserValues.NewLine, multiline); + subEvent.Text = subEvent.Text.Replace(@"\N", ParserValues.NewLine, StringComparison.OrdinalIgnoreCase); subEvent.Text = Regex.Replace(subEvent.Text, @"\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}", string.Empty, RegexOptions.IgnoreCase); subEvent.Text = Regex.Replace(subEvent.Text, "<", "<", RegexOptions.IgnoreCase); subEvent.Text = Regex.Replace(subEvent.Text, ">", ">", RegexOptions.IgnoreCase); diff --git a/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs index 559a05bc8a..d82ef4e24a 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs @@ -1,4 +1,5 @@ -using System; +using MediaBrowser.Common.Extensions; +using System; using System.IO; using System.Text; using System.Threading; @@ -147,7 +148,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles public static string GetFormattedText(string text) { - text = text.Replace("\\n", Environment.NewLine).Replace("\\n", Environment.NewLine); + text = text.Replace("\\n", ParserValues.NewLine, StringComparison.OrdinalIgnoreCase) + .Replace("\\n", ParserValues.NewLine, StringComparison.OrdinalIgnoreCase); + bool italic = false; for (int i = 0; i < 10; i++) // just look ten times... diff --git a/MediaBrowser.Tests/MediaBrowser.Tests.csproj b/MediaBrowser.Tests/MediaBrowser.Tests.csproj index dc7393b018..315ec583e9 100644 --- a/MediaBrowser.Tests/MediaBrowser.Tests.csproj +++ b/MediaBrowser.Tests/MediaBrowser.Tests.csproj @@ -50,7 +50,7 @@ - + @@ -93,7 +93,7 @@ Always - + Always diff --git a/MediaBrowser.Tests/MediaEncoding/Subtitles/SsaParserTests.cs b/MediaBrowser.Tests/MediaEncoding/Subtitles/AssParserTests.cs similarity index 93% rename from MediaBrowser.Tests/MediaEncoding/Subtitles/SsaParserTests.cs rename to MediaBrowser.Tests/MediaEncoding/Subtitles/AssParserTests.cs index d869146fdc..17687bc3a9 100644 --- a/MediaBrowser.Tests/MediaEncoding/Subtitles/SsaParserTests.cs +++ b/MediaBrowser.Tests/MediaEncoding/Subtitles/AssParserTests.cs @@ -1,14 +1,13 @@ -using System; +using MediaBrowser.MediaEncoding.Subtitles; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Collections.Generic; using System.IO; using System.Threading; -using MediaBrowser.MediaEncoding.Subtitles; -using Microsoft.VisualStudio.TestTools.UnitTesting; namespace MediaBrowser.Tests.MediaEncoding.Subtitles { [TestClass] - public class SsaParserTests { + public class AssParserTests { [TestMethod] public void TestParse() { @@ -21,7 +20,7 @@ namespace MediaBrowser.Tests.MediaEncoding.Subtitles { StartPositionTicks = 24000000, EndPositionTicks = 72000000, Text = - "Senator, we're
making our final
approach into Coruscant." + "Senator, we're "+ParserValues.NewLine+"making our final "+ParserValues.NewLine+"approach into Coruscant." }, new SubtitleTrackEvent { Id = "2", @@ -34,14 +33,14 @@ namespace MediaBrowser.Tests.MediaEncoding.Subtitles { Id = "3", StartPositionTicks = 150400000, EndPositionTicks = 180400000, - Text = "It's
a
trap!" + Text = "It's "+ParserValues.NewLine+"a "+ParserValues.NewLine+"trap!" } } }; var sut = new AssParser(); - var stream = File.OpenRead(@"MediaEncoding\Subtitles\TestSubtitles\data.ssa"); + var stream = File.OpenRead(@"MediaEncoding\Subtitles\TestSubtitles\data.ass"); var result = sut.Parse(stream, CancellationToken.None); diff --git a/MediaBrowser.Tests/MediaEncoding/Subtitles/SrtParserTests.cs b/MediaBrowser.Tests/MediaEncoding/Subtitles/SrtParserTests.cs index 2c2c944b12..6724ca597a 100644 --- a/MediaBrowser.Tests/MediaEncoding/Subtitles/SrtParserTests.cs +++ b/MediaBrowser.Tests/MediaEncoding/Subtitles/SrtParserTests.cs @@ -5,17 +5,21 @@ using System.Threading; using MediaBrowser.MediaEncoding.Subtitles; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace MediaBrowser.Tests.MediaEncoding.Subtitles { +namespace MediaBrowser.Tests.MediaEncoding.Subtitles +{ [TestClass] - public class SrtParserTests { + public class SrtParserTests + { [TestMethod] - public void TestParse() { + public void TestParse() + { var expectedSubs = - new SubtitleTrackInfo { - TrackEvents = new List { + new SubtitleTrackInfo + { + TrackEvents = new List { new SubtitleTrackEvent { Id = "1", StartPositionTicks = 24000000, @@ -28,7 +32,7 @@ namespace MediaBrowser.Tests.MediaEncoding.Subtitles { StartPositionTicks = 157120000, EndPositionTicks = 173990000, Text = - "Oh my god, Watch out!
It's coming!!" + "Oh my god, Watch out!"+ParserValues.NewLine+"It's coming!!" }, new SubtitleTrackEvent { Id = "3", @@ -48,7 +52,7 @@ namespace MediaBrowser.Tests.MediaEncoding.Subtitles { StartPositionTicks = 320000000, EndPositionTicks = 329990000, Text = - "This is a
new line, as is
this" + "This is a"+ParserValues.NewLine+"new line, as is"+ParserValues.NewLine+"this" }, new SubtitleTrackEvent { Id = "6", @@ -86,7 +90,7 @@ namespace MediaBrowser.Tests.MediaEncoding.Subtitles { "Greater than (<) and less than (>) are shown" } } - }; + }; var sut = new SrtParser(); @@ -95,7 +99,7 @@ namespace MediaBrowser.Tests.MediaEncoding.Subtitles { var result = sut.Parse(stream, CancellationToken.None); Assert.IsNotNull(result); - Assert.AreEqual(expectedSubs.TrackEvents.Count,result.TrackEvents.Count); + Assert.AreEqual(expectedSubs.TrackEvents.Count, result.TrackEvents.Count); for (int i = 0; i < expectedSubs.TrackEvents.Count; i++) { Assert.AreEqual(expectedSubs.TrackEvents[i].Id, result.TrackEvents[i].Id); diff --git a/MediaBrowser.Tests/MediaEncoding/Subtitles/TestSubtitles/data.ssa b/MediaBrowser.Tests/MediaEncoding/Subtitles/TestSubtitles/data.ass similarity index 100% rename from MediaBrowser.Tests/MediaEncoding/Subtitles/TestSubtitles/data.ssa rename to MediaBrowser.Tests/MediaEncoding/Subtitles/TestSubtitles/data.ass