diff --git a/libse/SubtitleFormats/LambdaCap.cs b/libse/SubtitleFormats/LambdaCap.cs index 9aab7feb8c..d4eae2e609 100644 --- a/libse/SubtitleFormats/LambdaCap.cs +++ b/libse/SubtitleFormats/LambdaCap.cs @@ -159,11 +159,11 @@ private static string DecodeStyle(string line) else if (ch == '@') { var part = line.Substring(i); - if (part.StartsWith("@ルビ上[", StringComparison.Ordinal)) // Bouten on first line - horizontal positioning + if (part.StartsWith("@ルビ上[", StringComparison.Ordinal)) // Bouten and Ruby on first line - horizontal positioning { readUntilEndCode = true; } - else if (part.StartsWith("@ルビ下[", StringComparison.Ordinal)) // Bouten on second line - horizontal positioning + else if (part.StartsWith("@ルビ下[", StringComparison.Ordinal)) // Bouten and Ruby on second line - horizontal positioning { readUntilEndCode = true; } @@ -171,26 +171,10 @@ private static string DecodeStyle(string line) { readUntilEndCode = true; } - else if (part.StartsWith("@ルビ左[", StringComparison.Ordinal)) // Bouten on second line - vertical positioning + else if (part.StartsWith("@ルビ左[", StringComparison.Ordinal)) // Bouten and Ruby on second line - vertical positioning { readUntilEndCode = true; - } - else if (part.StartsWith("@ルビ上[", StringComparison.Ordinal)) // Ruby on first line - horizontal positioning - { - readUntilEndCode = true; - } - else if (part.StartsWith("@ルビ下[", StringComparison.Ordinal)) // Ruby on second line - horizontal positioning - { - readUntilEndCode = true; - } - else if (part.StartsWith("@ルビ右[", StringComparison.Ordinal)) // Ruby on first line - vertical positioning - { - readUntilEndCode = true; - } - else if (part.StartsWith("@ルビ左[", StringComparison.Ordinal)) // Ruby on second line - vertical positioning - { - readUntilEndCode = true; - } + } else if (part.StartsWith("@組[", StringComparison.Ordinal)) // Kumi-moji / Tatechuyoko (up to 3 half width digits including numerical punctuation) { readUntilEndCode = true; @@ -286,11 +270,7 @@ public override void LoadSubtitle(Subtitle subtitle, List lines, string subtitle.Paragraphs.Add(p); } } - } - else if (string.IsNullOrWhiteSpace(line)) - { - // skip these lines - } + } else if (p != null) { if (string.IsNullOrEmpty(p.Text)) diff --git a/libse/SubtitleFormats/MacCaption.cs b/libse/SubtitleFormats/MacCaption.cs index f321fae151..fc1333c1ce 100644 --- a/libse/SubtitleFormats/MacCaption.cs +++ b/libse/SubtitleFormats/MacCaption.cs @@ -91,9 +91,9 @@ public override void LoadSubtitle(Subtitle subtitle, List lines, string { string s = line.Trim(); - if (s.StartsWith("//", StringComparison.Ordinal) || s.StartsWith("File Format=MacCaption_MCC", StringComparison.Ordinal) || s.StartsWith("UUID=", StringComparison.Ordinal) || + if (string.IsNullOrEmpty(s) || s.StartsWith("//", StringComparison.Ordinal) || s.StartsWith("File Format=MacCaption_MCC", StringComparison.Ordinal) || s.StartsWith("UUID=", StringComparison.Ordinal) || s.StartsWith("Creation Program=") || s.StartsWith("Creation Date=") || s.StartsWith("Creation Time=") || - s.StartsWith("Code Rate=", StringComparison.Ordinal) || s.StartsWith("Time Code Rate=", StringComparison.Ordinal) || string.IsNullOrEmpty(s)) + s.StartsWith("Code Rate=", StringComparison.Ordinal) || s.StartsWith("Time Code Rate=", StringComparison.Ordinal)) { header.AppendLine(line); } diff --git a/libse/SubtitleFormats/NetflixTimedText.cs b/libse/SubtitleFormats/NetflixTimedText.cs index b80be349d9..9ab5e4d843 100644 --- a/libse/SubtitleFormats/NetflixTimedText.cs +++ b/libse/SubtitleFormats/NetflixTimedText.cs @@ -67,17 +67,16 @@ public override string ToText(Subtitle subtitle, string title) try { var ssaStyle = AdvancedSubStationAlpha.GetSsaStyle(styleName, subtitle.Header); - if (ssaStyle != null) - { - string fontStyle = "normal"; - if (ssaStyle.Italic) - fontStyle = "italic"; - string fontWeight = "normal"; - if (ssaStyle.Bold) - fontWeight = "bold"; - AddStyleToXml(x, styleHead, xnsmgr, ssaStyle.Name, ssaStyle.FontName, fontWeight, fontStyle, Utilities.ColorToHex(ssaStyle.Primary), ssaStyle.FontSize.ToString()); - convertedFromSubStationAlpha = true; - } + + string fontStyle = "normal"; + if (ssaStyle.Italic) + fontStyle = "italic"; + string fontWeight = "normal"; + if (ssaStyle.Bold) + fontWeight = "bold"; + AddStyleToXml(x, styleHead, xnsmgr, ssaStyle.Name, ssaStyle.FontName, fontWeight, fontStyle, Utilities.ColorToHex(ssaStyle.Primary), ssaStyle.FontSize.ToString()); + convertedFromSubStationAlpha = true; + } catch { diff --git a/libse/SubtitleFormats/ScenaristClosedCaptions.cs b/libse/SubtitleFormats/ScenaristClosedCaptions.cs index 73ade8c9b9..7e5b9fcfa6 100644 --- a/libse/SubtitleFormats/ScenaristClosedCaptions.cs +++ b/libse/SubtitleFormats/ScenaristClosedCaptions.cs @@ -1617,7 +1617,7 @@ public static string GetSccText(string s, ref int errorCount) var cp = GetColorAndPosition(part); if (cp != null) { - if (cp.Y > 0 && y >= 0 && cp.Y > y && !sb.ToString().EndsWith(Environment.NewLine, StringComparison.Ordinal) && !string.IsNullOrWhiteSpace(sb.ToString())) + if (!string.IsNullOrWhiteSpace(sb.ToString()) && cp.Y > 0 && y >= 0 && cp.Y > y && !sb.ToString().EndsWith(Environment.NewLine, StringComparison.Ordinal)) sb.AppendLine(); if (cp.Y > 0) y = cp.Y; diff --git a/libse/SubtitleFormats/SmpteTt2052.cs b/libse/SubtitleFormats/SmpteTt2052.cs index 5d67d36c01..71e667f52c 100644 --- a/libse/SubtitleFormats/SmpteTt2052.cs +++ b/libse/SubtitleFormats/SmpteTt2052.cs @@ -64,17 +64,15 @@ public override string ToText(Subtitle subtitle, string title) try { var ssaStyle = AdvancedSubStationAlpha.GetSsaStyle(styleName, subtitle.Header); - if (ssaStyle != null) - { - string fontStyle = "normal"; - if (ssaStyle.Italic) - fontStyle = "italic"; - string fontWeight = "normal"; - if (ssaStyle.Bold) - fontWeight = "bold"; - AddStyleToXml(x, styleHead, xnsmgr, ssaStyle.Name, ssaStyle.FontName, fontWeight, fontStyle, Utilities.ColorToHex(ssaStyle.Primary), ssaStyle.FontSize.ToString()); - convertedFromSubStationAlpha = true; - } + + string fontStyle = "normal"; + if (ssaStyle.Italic) + fontStyle = "italic"; + string fontWeight = "normal"; + if (ssaStyle.Bold) + fontWeight = "bold"; + AddStyleToXml(x, styleHead, xnsmgr, ssaStyle.Name, ssaStyle.FontName, fontWeight, fontStyle, Utilities.ColorToHex(ssaStyle.Primary), ssaStyle.FontSize.ToString()); + convertedFromSubStationAlpha = true; } catch { diff --git a/libse/SubtitleFormats/SubStationAlpha.cs b/libse/SubtitleFormats/SubStationAlpha.cs index 97b25d89e1..6294b67e92 100644 --- a/libse/SubtitleFormats/SubStationAlpha.cs +++ b/libse/SubtitleFormats/SubStationAlpha.cs @@ -148,53 +148,52 @@ private static void LoadStylesFromAdvancedSubstationAlpha(Subtitle subtitle, str try { var ssaStyle = AdvancedSubStationAlpha.GetSsaStyle(styleName, subtitle.Header); - if (ssaStyle != null) + + string bold = "0"; + if (ssaStyle.Bold) + bold = "-1"; + string italic = "0"; + if (ssaStyle.Italic) + italic = "-1"; + + string newAlignment = "2"; + switch (ssaStyle.Alignment) { - string bold = "0"; - if (ssaStyle.Bold) - bold = "-1"; - string italic = "0"; - if (ssaStyle.Italic) - italic = "-1"; - - string newAlignment = "2"; - switch (ssaStyle.Alignment) - { - case "1": - newAlignment = "1"; - break; - case "3": - newAlignment = "3"; - break; - case "4": - newAlignment = "9"; - break; - case "5": - newAlignment = "10"; - break; - case "6": - newAlignment = "11"; - break; - case "7": - newAlignment = "5"; - break; - case "8": - newAlignment = "6"; - break; - case "9": - newAlignment = "7"; - break; - } + case "1": + newAlignment = "1"; + break; + case "3": + newAlignment = "3"; + break; + case "4": + newAlignment = "9"; + break; + case "5": + newAlignment = "10"; + break; + case "6": + newAlignment = "11"; + break; + case "7": + newAlignment = "5"; + break; + case "8": + newAlignment = "6"; + break; + case "9": + newAlignment = "7"; + break; + } - //Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding - const string styleFormat = "Style: {0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},0,1"; - // N FN FS PC SC TC BC Bo It BS O Sh Ali ML MR MV A Encoding + //Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding + const string styleFormat = "Style: {0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},0,1"; + // N FN FS PC SC TC BC Bo It BS O Sh Ali ML MR MV A Encoding - ttStyles.AppendLine(string.Format(styleFormat, ssaStyle.Name, ssaStyle.FontName, ssaStyle.FontSize, ssaStyle.Primary.ToArgb(), ssaStyle.Secondary.ToArgb(), - ssaStyle.Outline.ToArgb(), ssaStyle.Background.ToArgb(), bold, italic, ssaStyle.BorderStyle, ssaStyle.OutlineWidth, ssaStyle.ShadowWidth, - newAlignment, ssaStyle.MarginLeft, ssaStyle.MarginRight, ssaStyle.MarginVertical)); - styleFound = true; - } + ttStyles.AppendLine(string.Format(styleFormat, ssaStyle.Name, ssaStyle.FontName, ssaStyle.FontSize, ssaStyle.Primary.ToArgb(), ssaStyle.Secondary.ToArgb(), + ssaStyle.Outline.ToArgb(), ssaStyle.Background.ToArgb(), bold, italic, ssaStyle.BorderStyle, ssaStyle.OutlineWidth, ssaStyle.ShadowWidth, + newAlignment, ssaStyle.MarginLeft, ssaStyle.MarginRight, ssaStyle.MarginVertical)); + styleFound = true; + } catch { @@ -333,13 +332,13 @@ public override void LoadSubtitle(Subtitle subtitle, List lines, string if (!eventsStarted) header.AppendLine(line); - if (line.Trim().Equals("[events]", StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrEmpty(line) && line.TrimStart().StartsWith(';')) { - eventsStarted = true; + // skip comment lines } - else if (!string.IsNullOrEmpty(line) && line.TrimStart().StartsWith(';')) + else if (line.Trim().Equals("[events]", StringComparison.OrdinalIgnoreCase)) { - // skip comment lines + eventsStarted = true; } else if (eventsStarted && !string.IsNullOrWhiteSpace(line)) { diff --git a/libse/SubtitleFormats/Ted20.cs b/libse/SubtitleFormats/Ted20.cs index 5e002c36f2..8eeba4363b 100644 --- a/libse/SubtitleFormats/Ted20.cs +++ b/libse/SubtitleFormats/Ted20.cs @@ -82,10 +82,8 @@ public override void LoadSubtitle(Subtitle subtitle, List lines, string buffer[i + TextBufferSize] == 0xff) { var text = ReadText(buffer, i); - if (text != null) - { - texts.Add(text); - } + texts.Add(text); + i += TextBufferSize; } else diff --git a/libse/SubtitleFormats/UnknownSubtitle6.cs b/libse/SubtitleFormats/UnknownSubtitle6.cs index 4a7845bcaf..be5f9d0668 100644 --- a/libse/SubtitleFormats/UnknownSubtitle6.cs +++ b/libse/SubtitleFormats/UnknownSubtitle6.cs @@ -45,8 +45,8 @@ public override string ToText(Subtitle subtitle, string title) { lines = Utilities.AutoBreakLine(p.Text).SplitToLines(); } - if (lines.Count > 0) - firstLine = lines[0]; + firstLine = lines[0]; + if (lines.Count > 1) secondLine = lines[1]; diff --git a/libse/TransportStream/TransportStreamParser.cs b/libse/TransportStream/TransportStreamParser.cs index 75d6114bb9..47ebe89154 100644 --- a/libse/TransportStream/TransportStreamParser.cs +++ b/libse/TransportStream/TransportStreamParser.cs @@ -268,27 +268,26 @@ public void Parse(Stream ms, LoadTransportStreamCallback callback) var subtitles = new List(); var list = ParseAndRemoveEmpty(GetSubtitlePesPackets(pid)); - if (list != null) + + for (int i = 0; i < list.Count; i++) { - for (int i = 0; i < list.Count; i++) + var pes = list[i]; + pes.ParseSegments(); + if (pes.ObjectDataList.Count > 0) { - var pes = list[i]; - pes.ParseSegments(); - if (pes.ObjectDataList.Count > 0) - { - var sub = new TransportStreamSubtitle(); - sub.StartMilliseconds = pes.PresentationTimestampToMilliseconds(); - sub.Pes = pes; - if (i + 1 < list.Count && list[i + 1].PresentationTimestampToMilliseconds() > 25) - sub.EndMilliseconds = list[i + 1].PresentationTimestampToMilliseconds() - 25; - if (sub.EndMilliseconds < sub.StartMilliseconds || sub.EndMilliseconds - sub.StartMilliseconds > (ulong)Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds) - sub.EndMilliseconds = sub.StartMilliseconds + 3500; - subtitles.Add(sub); - if (sub.StartMilliseconds < firstVideoMs) - firstVideoMs = sub.StartMilliseconds; - } + var sub = new TransportStreamSubtitle(); + sub.StartMilliseconds = pes.PresentationTimestampToMilliseconds(); + sub.Pes = pes; + if (i + 1 < list.Count && list[i + 1].PresentationTimestampToMilliseconds() > 25) + sub.EndMilliseconds = list[i + 1].PresentationTimestampToMilliseconds() - 25; + if (sub.EndMilliseconds < sub.StartMilliseconds || sub.EndMilliseconds - sub.StartMilliseconds > (ulong)Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds) + sub.EndMilliseconds = sub.StartMilliseconds + 3500; + subtitles.Add(sub); + if (sub.StartMilliseconds < firstVideoMs) + firstVideoMs = sub.StartMilliseconds; } } + foreach (var s in subtitles) { s.OffsetMilliseconds = firstVideoMs; diff --git a/libse/VobSub/VobSubParser.cs b/libse/VobSub/VobSubParser.cs index db7768deec..0f9567ebc6 100644 --- a/libse/VobSub/VobSubParser.cs +++ b/libse/VobSub/VobSubParser.cs @@ -80,7 +80,10 @@ public void OpenSubIdx(string vobSubFileName, string idxFileName) else position += 0x800; - int currentSubPictureStreamId = vsp.PacketizedElementaryStream.SubPictureStreamId.Value; + int currentSubPictureStreamId = 0; + if(vsp.PacketizedElementaryStream.SubPictureStreamId != null) + currentSubPictureStreamId = vsp.PacketizedElementaryStream.SubPictureStreamId.Value; + while (vsp.PacketizedElementaryStream != null && vsp.PacketizedElementaryStream.SubPictureStreamId.HasValue && (vsp.PacketizedElementaryStream.Length == PacketizedElementaryStreamMaximumLength || diff --git a/libse/WaveToVisualizer.cs b/libse/WaveToVisualizer.cs index 263fd0cfd1..195384bbbf 100644 --- a/libse/WaveToVisualizer.cs +++ b/libse/WaveToVisualizer.cs @@ -533,7 +533,7 @@ internal WavePeakData LoadPeaks() peaks[peakIndex++] = new WavePeak(max, min); } } - else if (_header.NumberOfChannels == 1) + else { // single sample value (for backwards compatibility) int byteIndex = 0;