aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.MediaEncoding
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.MediaEncoding')
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/AssParser.cs14
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs4
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs10
3 files changed, 19 insertions, 9 deletions
diff --git a/MediaBrowser.MediaEncoding/Subtitles/AssParser.cs b/MediaBrowser.MediaEncoding/Subtitles/AssParser.cs
index 86b87fddd..e0b7914fb 100644
--- a/MediaBrowser.MediaEncoding/Subtitles/AssParser.cs
+++ b/MediaBrowser.MediaEncoding/Subtitles/AssParser.cs
@@ -24,7 +24,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
using (var reader = new StreamReader(stream))
{
string line;
- while (reader.ReadLine() != "[Events]")
+ while (!string.Equals(reader.ReadLine(), "[Events]", StringComparison.Ordinal))
{
}
@@ -46,12 +46,13 @@ namespace MediaBrowser.MediaEncoding.Subtitles
var subEvent = new SubtitleTrackEvent { Id = eventIndex.ToString(_usCulture) };
eventIndex++;
- var sections = line.Substring(10).Split(',');
+ const string Dialogue = "Dialogue: ";
+ var sections = line.Substring(Dialogue.Length).Split(',');
subEvent.StartPositionTicks = GetTicks(sections[headers["Start"]]);
subEvent.EndPositionTicks = GetTicks(sections[headers["End"]]);
- subEvent.Text = string.Join(",", sections.Skip(headers["Text"]));
+ subEvent.Text = string.Join(',', sections[headers["Text"]..]);
RemoteNativeFormatting(subEvent);
subEvent.Text = subEvent.Text.Replace("\\n", ParserValues.NewLine, StringComparison.OrdinalIgnoreCase);
@@ -62,7 +63,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
}
}
- trackInfo.TrackEvents = trackEvents.ToArray();
+ trackInfo.TrackEvents = trackEvents;
return trackInfo;
}
@@ -72,9 +73,10 @@ namespace MediaBrowser.MediaEncoding.Subtitles
? span.Ticks : 0;
}
- private Dictionary<string, int> ParseFieldHeaders(string line)
+ internal static Dictionary<string, int> ParseFieldHeaders(string line)
{
- var fields = line.Substring(8).Split(',').Select(x => x.Trim()).ToList();
+ const string Format = "Format: ";
+ var fields = line.Substring(Format.Length).Split(',').Select(x => x.Trim()).ToList();
return new Dictionary<string, int>
{
diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs
index cc35efb3f..4a87f87dc 100644
--- a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs
+++ b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs
@@ -69,7 +69,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
var multiline = new List<string>();
while ((line = reader.ReadLine()) != null)
{
- if (string.IsNullOrEmpty(line))
+ if (line.Length == 0)
{
break;
}
@@ -87,7 +87,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
}
}
- trackInfo.TrackEvents = trackEvents.ToArray();
+ trackInfo.TrackEvents = trackEvents;
return trackInfo;
}
diff --git a/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs
index db6b47583..bc84c5074 100644
--- a/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs
+++ b/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs
@@ -325,7 +325,15 @@ namespace MediaBrowser.MediaEncoding.Subtitles
text = text.Insert(start, "<font color=\"" + color + "\"" + extraTags + ">");
}
- text += "</font>";
+ int indexOfEndTag = text.IndexOf("{\\1c}", start, StringComparison.Ordinal);
+ if (indexOfEndTag > 0)
+ {
+ text = text.Remove(indexOfEndTag, "{\\1c}".Length).Insert(indexOfEndTag, "</font>");
+ }
+ else
+ {
+ text += "</font>";
+ }
}
}
}