fix subtitle unit tests
This commit is contained in:
parent
6e25c572fa
commit
bdc04cda17
|
@ -62,6 +62,7 @@
|
||||||
<Compile Include="Subtitles\ISubtitleParser.cs" />
|
<Compile Include="Subtitles\ISubtitleParser.cs" />
|
||||||
<Compile Include="Subtitles\ISubtitleWriter.cs" />
|
<Compile Include="Subtitles\ISubtitleWriter.cs" />
|
||||||
<Compile Include="Subtitles\JsonWriter.cs" />
|
<Compile Include="Subtitles\JsonWriter.cs" />
|
||||||
|
<Compile Include="Subtitles\ParserValues.cs" />
|
||||||
<Compile Include="Subtitles\SrtParser.cs" />
|
<Compile Include="Subtitles\SrtParser.cs" />
|
||||||
<Compile Include="Subtitles\SrtWriter.cs" />
|
<Compile Include="Subtitles\SrtWriter.cs" />
|
||||||
<Compile Include="Subtitles\AssParser.cs" />
|
<Compile Include="Subtitles\AssParser.cs" />
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using MediaBrowser.Common.Extensions;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -42,6 +43,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
subEvent.StartPositionTicks = GetTicks(sections[headers["Start"]]);
|
subEvent.StartPositionTicks = GetTicks(sections[headers["Start"]]);
|
||||||
subEvent.EndPositionTicks = GetTicks(sections[headers["End"]]);
|
subEvent.EndPositionTicks = GetTicks(sections[headers["End"]]);
|
||||||
subEvent.Text = string.Join(",", sections.Skip(headers["Text"]));
|
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);
|
subEvent.Text = Regex.Replace(subEvent.Text, @"\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}", string.Empty, RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
trackInfo.TrackEvents.Add(subEvent);
|
trackInfo.TrackEvents.Add(subEvent);
|
||||||
|
|
13
MediaBrowser.MediaEncoding/Subtitles/ParserValues.cs
Normal file
13
MediaBrowser.MediaEncoding/Subtitles/ParserValues.cs
Normal file
|
@ -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";
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using MediaBrowser.Common.Extensions;
|
||||||
|
|
||||||
namespace MediaBrowser.MediaEncoding.Subtitles
|
namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
{
|
{
|
||||||
|
@ -48,7 +49,8 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
}
|
}
|
||||||
multiline.Add(line);
|
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, @"\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}", string.Empty, RegexOptions.IgnoreCase);
|
||||||
subEvent.Text = Regex.Replace(subEvent.Text, "<", "<", RegexOptions.IgnoreCase);
|
subEvent.Text = Regex.Replace(subEvent.Text, "<", "<", RegexOptions.IgnoreCase);
|
||||||
subEvent.Text = Regex.Replace(subEvent.Text, ">", ">", RegexOptions.IgnoreCase);
|
subEvent.Text = Regex.Replace(subEvent.Text, ">", ">", RegexOptions.IgnoreCase);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using MediaBrowser.Common.Extensions;
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
@ -147,7 +148,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
|
|
||||||
public static string GetFormattedText(string text)
|
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;
|
bool italic = false;
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) // just look ten times...
|
for (int i = 0; i < 10; i++) // just look ten times...
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
</Otherwise>
|
</Otherwise>
|
||||||
</Choose>
|
</Choose>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="MediaEncoding\Subtitles\SsaParserTests.cs" />
|
<Compile Include="MediaEncoding\Subtitles\AssParserTests.cs" />
|
||||||
<Compile Include="MediaEncoding\Subtitles\SrtParserTests.cs" />
|
<Compile Include="MediaEncoding\Subtitles\SrtParserTests.cs" />
|
||||||
<Compile Include="MediaEncoding\Subtitles\VttWriterTest.cs" />
|
<Compile Include="MediaEncoding\Subtitles\VttWriterTest.cs" />
|
||||||
<Compile Include="Providers\MovieDbProviderTests.cs" />
|
<Compile Include="Providers\MovieDbProviderTests.cs" />
|
||||||
|
@ -93,7 +93,7 @@
|
||||||
<None Include="MediaEncoding\Subtitles\TestSubtitles\expected.vtt">
|
<None Include="MediaEncoding\Subtitles\TestSubtitles\expected.vtt">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Include="MediaEncoding\Subtitles\TestSubtitles\data.ssa">
|
<None Include="MediaEncoding\Subtitles\TestSubtitles\data.ass">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Include="MediaEncoding\Subtitles\TestSubtitles\unit.srt">
|
<None Include="MediaEncoding\Subtitles\TestSubtitles\unit.srt">
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
using System;
|
using MediaBrowser.MediaEncoding.Subtitles;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using MediaBrowser.MediaEncoding.Subtitles;
|
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Tests.MediaEncoding.Subtitles {
|
namespace MediaBrowser.Tests.MediaEncoding.Subtitles {
|
||||||
|
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class SsaParserTests {
|
public class AssParserTests {
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestParse() {
|
public void TestParse() {
|
||||||
|
@ -21,7 +20,7 @@ namespace MediaBrowser.Tests.MediaEncoding.Subtitles {
|
||||||
StartPositionTicks = 24000000,
|
StartPositionTicks = 24000000,
|
||||||
EndPositionTicks = 72000000,
|
EndPositionTicks = 72000000,
|
||||||
Text =
|
Text =
|
||||||
"Senator, we're <br />making our final <br />approach into Coruscant."
|
"Senator, we're "+ParserValues.NewLine+"making our final "+ParserValues.NewLine+"approach into Coruscant."
|
||||||
},
|
},
|
||||||
new SubtitleTrackEvent {
|
new SubtitleTrackEvent {
|
||||||
Id = "2",
|
Id = "2",
|
||||||
|
@ -34,14 +33,14 @@ namespace MediaBrowser.Tests.MediaEncoding.Subtitles {
|
||||||
Id = "3",
|
Id = "3",
|
||||||
StartPositionTicks = 150400000,
|
StartPositionTicks = 150400000,
|
||||||
EndPositionTicks = 180400000,
|
EndPositionTicks = 180400000,
|
||||||
Text = "It's <br />a <br />trap!"
|
Text = "It's "+ParserValues.NewLine+"a "+ParserValues.NewLine+"trap!"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var sut = new AssParser();
|
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);
|
var result = sut.Parse(stream, CancellationToken.None);
|
||||||
|
|
|
@ -5,16 +5,20 @@ using System.Threading;
|
||||||
using MediaBrowser.MediaEncoding.Subtitles;
|
using MediaBrowser.MediaEncoding.Subtitles;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
namespace MediaBrowser.Tests.MediaEncoding.Subtitles {
|
namespace MediaBrowser.Tests.MediaEncoding.Subtitles
|
||||||
|
{
|
||||||
|
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class SrtParserTests {
|
public class SrtParserTests
|
||||||
|
{
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestParse() {
|
public void TestParse()
|
||||||
|
{
|
||||||
|
|
||||||
var expectedSubs =
|
var expectedSubs =
|
||||||
new SubtitleTrackInfo {
|
new SubtitleTrackInfo
|
||||||
|
{
|
||||||
TrackEvents = new List<SubtitleTrackEvent> {
|
TrackEvents = new List<SubtitleTrackEvent> {
|
||||||
new SubtitleTrackEvent {
|
new SubtitleTrackEvent {
|
||||||
Id = "1",
|
Id = "1",
|
||||||
|
@ -28,7 +32,7 @@ namespace MediaBrowser.Tests.MediaEncoding.Subtitles {
|
||||||
StartPositionTicks = 157120000,
|
StartPositionTicks = 157120000,
|
||||||
EndPositionTicks = 173990000,
|
EndPositionTicks = 173990000,
|
||||||
Text =
|
Text =
|
||||||
"Oh my god, Watch out!<br />It's coming!!"
|
"Oh my god, Watch out!"+ParserValues.NewLine+"It's coming!!"
|
||||||
},
|
},
|
||||||
new SubtitleTrackEvent {
|
new SubtitleTrackEvent {
|
||||||
Id = "3",
|
Id = "3",
|
||||||
|
@ -48,7 +52,7 @@ namespace MediaBrowser.Tests.MediaEncoding.Subtitles {
|
||||||
StartPositionTicks = 320000000,
|
StartPositionTicks = 320000000,
|
||||||
EndPositionTicks = 329990000,
|
EndPositionTicks = 329990000,
|
||||||
Text =
|
Text =
|
||||||
"This is a<br />new line, as is<br />this"
|
"This is a"+ParserValues.NewLine+"new line, as is"+ParserValues.NewLine+"this"
|
||||||
},
|
},
|
||||||
new SubtitleTrackEvent {
|
new SubtitleTrackEvent {
|
||||||
Id = "6",
|
Id = "6",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user