Merge pull request #1976 from ivandrofly/phxSub

[PhoenixSubtitle] - Minor fixes/Update.
This commit is contained in:
Nikolaj Olsson 2016-09-26 21:14:06 +02:00 committed by GitHub
commit 1914a4942f
2 changed files with 10 additions and 20 deletions

View File

@ -16,7 +16,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
//2513, 2594, "Yeah. The Drama Club is worried|that you haven't been coming." //2513, 2594, "Yeah. The Drama Club is worried|that you haven't been coming."
//2603, 2675, "I see. Sorry, I'll drop by next time." //2603, 2675, "I see. Sorry, I'll drop by next time."
private static readonly Regex RegexTimeCodes = new Regex(@"^(\d+),\s+(\d+),", RegexOptions.Compiled); private static readonly Regex RegexTimeCodes = new Regex(@"^(\d+),\s*(\d+),", RegexOptions.Compiled);
private static readonly char[] TrimChars = { ' ', '"' }; private static readonly char[] TrimChars = { ' ', '"' };
public override string Extension public override string Extension
@ -31,7 +31,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{ {
get get
{ {
return true; return false;
} }
} }
@ -45,7 +45,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override bool IsMine(List<string> lines, string fileName) public override bool IsMine(List<string> lines, string fileName)
{ {
if (fileName != null && !fileName.EndsWith(".pjs", StringComparison.OrdinalIgnoreCase)) if (fileName?.EndsWith(".pjs", StringComparison.OrdinalIgnoreCase) == false)
{ {
return false; return false;
} }
@ -71,9 +71,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{ {
try try
{ {
// Decode times. // Read frames.
paragraph.StartTime = DecodeTimeCode(match.Groups[1].Value); paragraph.StartFrame = int.Parse(match.Groups[1].Value);
paragraph.EndTime = DecodeTimeCode(match.Groups[2].Value); paragraph.EndFrame = int.Parse(match.Groups[2].Value);
// Decode text. // Decode text.
line = line.Substring(match.Value.Length).Trim(); line = line.Substring(match.Value.Length).Trim();
@ -104,19 +104,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
} }
} }
private static TimeCode DecodeTimeCode(string encodedTime)
{
int time;
if (int.TryParse(encodedTime, out time))
{
return new TimeCode(FramesToMilliseconds(time));
}
return new TimeCode(0);
}
public override string ToText(Subtitle subtitle, string title) public override string ToText(Subtitle subtitle, string title)
{ {
const string writeFormat = "{0}, {1}, \"{2}\"\r\n"; const string writeFormat = "{0},{1},\"{2}\"{3}";
var sb = new StringBuilder(); var sb = new StringBuilder();
foreach (var p in subtitle.Paragraphs) foreach (var p in subtitle.Paragraphs)
{ {
@ -124,7 +114,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
// Pipe character for forced line breaks. // Pipe character for forced line breaks.
text = text.Replace(Environment.NewLine, "|"); text = text.Replace(Environment.NewLine, "|");
sb.AppendFormat(writeFormat, MillisecondsToFrames(p.StartTime.TotalMilliseconds), sb.AppendFormat(writeFormat, MillisecondsToFrames(p.StartTime.TotalMilliseconds),
MillisecondsToFrames(p.EndTime.TotalMilliseconds), text); MillisecondsToFrames(p.EndTime.TotalMilliseconds), text, Environment.NewLine);
} }
return sb.ToString(); return sb.ToString();
} }

View File

@ -887,8 +887,8 @@ Dialogue: Marked=0,0:00:01.00,0:00:03.00,Default,NTP,0000,0000,0000,!Effect," +
Assert.AreEqual("Yeah. The Drama Club is worried\r\nthat you haven't been coming.", subtitle.Paragraphs[1].Text); Assert.AreEqual("Yeah. The Drama Club is worried\r\nthat you haven't been coming.", subtitle.Paragraphs[1].Text);
// Test frames. // Test frames.
Assert.AreEqual(SubtitleFormat.FramesToMilliseconds(2447), subtitle.Paragraphs[0].StartTime.TotalMilliseconds); Assert.AreEqual(SubtitleFormat.FramesToMilliseconds(2447), SubtitleFormat.FramesToMilliseconds(subtitle.Paragraphs[0].StartFrame));
Assert.AreEqual(SubtitleFormat.FramesToMilliseconds(2513), subtitle.Paragraphs[0].EndTime.TotalMilliseconds); Assert.AreEqual(SubtitleFormat.FramesToMilliseconds(2513), SubtitleFormat.FramesToMilliseconds(subtitle.Paragraphs[0].EndFrame));
// Test total lines. // Test total lines.
Assert.AreEqual(2, subtitle.Paragraphs[1].NumberOfLines); Assert.AreEqual(2, subtitle.Paragraphs[1].NumberOfLines);