Merge branch 'master' into feature/add-sentence-continuation-style

This commit is contained in:
Martijn van Berkel (Flitskikker) 2020-04-12 20:08:37 +02:00
commit c181e92587
11 changed files with 153 additions and 25 deletions

View File

@ -192,6 +192,7 @@
<Word from="daga" to="da ga" />
<Word from="damas" to="danas" />
<Word from="date" to="dane" />
<Word from="dcije" to="dvije" />
<Word from="deca" to="djeca" />
<Word from="Deca" to="Djeca" />
<Word from="dece" to="djece" />
@ -455,6 +456,8 @@
<Word from="izand" to="iznad" />
<Word from="izanf" to="iznad" />
<Word from="iznaf" to="iznad" />
<Word from="izbjeljen" to="izbijeljen" />
<Word from="izbeljen" to="izbijeljen" />
<Word from="izdaće" to="izdat će" />
<Word from="Izdaće" to="Izdat će" />
<Word from="izduvaj" to="ispuši" />
@ -1058,6 +1061,8 @@
<Word from="petla" to="pijetla" />
<Word from="pijesma" to="pjesma" />
<Word from="pijesmu" to="pjesmu" />
<Word from="piksla" to="pepeljara" />
<Word from="pikslu" to="pepeljaru" />
<Word from="Plata" to="Plaća" />
<Word from="plata" to="plaća" />
<Word from="plača" to="plaća" />
@ -1266,6 +1271,9 @@
<Word from="prodata" to="prodana" />
<Word from="prodato" to="prodano" />
<Word from="prohte" to="prohtije" />
<Word from="prohteve" to="prohtjeve" />
<Word from="proje" to="prije" />
<Word from="Proje" to="Prije" />
<Word from="projekat" to="projekt" />
<Word from="Projekat" to="Projekt" />
<Word from="promijena" to="promjena" />
@ -1386,6 +1394,7 @@
<Word from="Sci" to="Svi" />
<Word from="secka" to="sjecka" />
<Word from="seckam" to="sjeckam" />
<Word from="sećanjima" to="sjećanjima" />
<Word from="seče" to="siječe" />
<Word from="sečivo" to="sječivo" />
<Word from="sečiva" to="sječiva" />
@ -1445,7 +1454,8 @@
<Word from="sleću" to="slijeću" />
<Word from="slećemo" to="slijećemo" />
<Word from="sleva" to="slijeva" />
<Word from="sećanjima" to="sjećanjima" />
<Word from="sljedeči" to="sljedeći" />
<Word from="sljedečih" to="sljedećih" />
<Word from="seo" to="sjeo" />
<Word from="Seo" to="Sjeo" />
<Word from="sem" to="osim" />
@ -2427,6 +2437,7 @@
<LinePart from="da li će" to="hoće li" />
<LinePart from="dali će" to="hoće li" />
<LinePart from="dali mogu" to="mogu li" />
<LinePart from="dali možete" to="možete li" />
<LinePart from="do srede" to="do srijede" />
<LinePart from="Dobro veče" to="Dobra večer" />
<LinePart from="Dobro večer" to="Dobra večer" />
@ -3550,6 +3561,7 @@
<RegEx find="jći" replaceWith="jući" />
<RegEx find="jdm" replaceWith="jem" />
<RegEx find="jdin" replaceWith="jedin" />
<RegEx find="kcj" replaceWith="kcij" />
<RegEx find="kodnevnic" replaceWith="kodnevic" />
<RegEx find="([kKpPvVtT])ratić" replaceWith="$1ratit ć" />
<RegEx find="koriš[čć]a" replaceWith="korišta" />
@ -3676,6 +3688,7 @@
<RegEx find="rj?evozn" replaceWith="rijevozn" />
<RegEx find="(?&lt;!r)ojd" replaceWith="ojed" />
<RegEx find="rpeu" replaceWith="preu" />
<RegEx find="rsd" replaceWith="rad" />
<RegEx find="ršč" replaceWith="ršć" />
<RegEx find="rutuje" replaceWith="rutira" />
<RegEx find="rviši" replaceWith="rviraj" />
@ -4033,4 +4046,4 @@
<!-- Skraćenice bez razmaka -->
<RegEx find="d\. o\.o\." replaceWith="d.o.o." />
</RegularExpressions>
</OCRFixReplaceList>
</OCRFixReplaceList>

View File

@ -134,9 +134,9 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.TransportStream
{
var language = GetSubtitleLanguage(packetId);
var uppercaseLanguage = language.ToUpperInvariant();
if (IsoCountryCodes.ThreeToTweLetterLookup.ContainsKey(uppercaseLanguage))
if (IsoCountryCodes.ThreeToTwoLetterLookup.ContainsKey(uppercaseLanguage))
{
return IsoCountryCodes.ThreeToTweLetterLookup[uppercaseLanguage].ToLowerInvariant();
return IsoCountryCodes.ThreeToTwoLetterLookup[uppercaseLanguage].ToLowerInvariant();
}
return language;
}

View File

@ -5,7 +5,7 @@ namespace Nikse.SubtitleEdit.Core
{
public static class IsoCountryCodes
{
public static Dictionary<string, string> ThreeToTweLetterLookup = new Dictionary<string, string>
public static Dictionary<string, string> ThreeToTwoLetterLookup = new Dictionary<string, string>
{
{ "AFG", "AF" },
{ "ALA", "AX" },
@ -256,7 +256,6 @@ namespace Nikse.SubtitleEdit.Core
{ "ZWE", "ZW" },
};
/// <summary>
/// Get three letter language code, from two letter language code.
/// </summary>
@ -264,13 +263,8 @@ namespace Nikse.SubtitleEdit.Core
/// <returns>Three letter language code in lowercase, string.Empty if not found</returns>
public static string GetThreeLetterCodeFromTwoLetterCode(string twoLetterCode)
{
var threeLetters = ThreeToTweLetterLookup.FirstOrDefault(p => p.Value == twoLetterCode.ToUpperInvariant());
if (threeLetters.Key?.Length == 3)
{
return threeLetters.Key.ToLowerInvariant();
}
return string.Empty;
var lookupResult = ThreeToTwoLetterLookup.FirstOrDefault(p => p.Value == twoLetterCode.ToUpperInvariant());
return lookupResult.Key?.Length == 3 ? lookupResult.Key.ToLowerInvariant() : string.Empty;
}
}
}

View File

@ -923,7 +923,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
case "nb": return "1E"; // Norwegian
case "oc": return "1F"; // Occitan
case "pl": return "20"; // Polish
case "pt": return "21"; // Portugese
case "pt": return "21"; // Portuguese
case "ro": return "22"; // Romanian
case "rm": return "23"; // Romansh
case "sr": return "24"; // Serbian

View File

@ -296,7 +296,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
new UnknownSubtitle93(),
new UnknownSubtitle94(),
new UnknownSubtitle95(),
new UnknownSubtitle96()
new UnknownSubtitle96(),
new UnknownSubtitle97(),
};
string path = Configuration.PluginsDirectory;

View File

@ -33,15 +33,15 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
string s;
if (ts.Minutes == 0 && ts.Hours == 0 && ts.Days == 0)
{
s = string.Format("0:{0:00}", ts.Seconds);
s = $"0:{ts.Seconds:00}";
}
else if (ts.Hours == 0 && ts.Days == 0)
{
s = string.Format("{0:0}:{1:00}", ts.Minutes, ts.Seconds);
s = $"{ts.Minutes:0}:{ts.Seconds:00}";
}
else
{
s = string.Format("{0:0}:{1:00}:{2:00}", ts.Hours + ts.Days * 24, ts.Minutes, ts.Seconds);
s = $"{ts.Hours + ts.Days * 24:0}:{ts.Minutes:00}:{ts.Seconds:00}";
}
if (timeCode.TotalMilliseconds >= 0)
@ -69,11 +69,22 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
p.Text = sb.ToString().Trim();
subtitle.Paragraphs.Add(p);
if (string.IsNullOrEmpty(p.Text))
{
_errorCount++;
}
}
p = new Paragraph();
p.StartTime = DecodeTimeCode(m.Value.Trim(), SplitCharColon);
p.Actor = s.Remove(0, m.Value.Length).Trim();
p = new Paragraph
{
StartTime = DecodeTimeCode(m.Value.Trim(), SplitCharColon),
Actor = s.Remove(0, m.Value.Length).Trim(),
};
sb.Clear();
if (p.Actor.Split().Length > 3)
{
_errorCount++;
}
}
else if (p != null)
{
@ -98,10 +109,12 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
return new TimeCode(0, int.Parse(arr[0]), int.Parse(arr[1]), 0);
}
else if (arr.Length == 3)
if (arr.Length == 3)
{
return new TimeCode(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]), 0);
}
throw new InvalidOperationException();
}
}

View File

@ -30,6 +30,16 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return sb.ToString().Trim();
}
public override bool IsMine(List<string> lines, string fileName)
{
if (new UnknownSubtitle97().IsMine(lines, fileName))
{
return false;
}
return base.IsMine(lines, fileName);
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
Paragraph paragraph = null;

View File

@ -0,0 +1,97 @@
using Nikse.SubtitleEdit.Core.Forms.FixCommonErrors;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class UnknownSubtitle97 : SubtitleFormat
{
private static readonly Regex RegexTimeCode = new Regex(@"^\d\d:\d\d:\d\d\s+.+", RegexOptions.Compiled);
public override string Extension => ".txt";
public override string Name => "Unknown 97";
public override string ToText(Subtitle subtitle, string title)
{
//00:00:20 I think weve heard enough.
//
//00:00:22 - Wait, hes the one that…
//\t\t-ENOUGH!
const string writeFormat = "{0:00}:{1:00}:{2:00} {3}";
var sb = new StringBuilder();
foreach (var p in subtitle.Paragraphs)
{
var textBuilder = new StringBuilder();
var list = p.Text.SplitToLines();
for (var index = 0; index < list.Count; index++)
{
var line = list[index];
if (index > 0)
{
textBuilder.Append("\t\t");
}
textBuilder.AppendLine(line);
}
sb.AppendLine(string.Format(writeFormat, p.StartTime.Hours, p.StartTime.Minutes, p.StartTime.Seconds, textBuilder));
}
return sb.ToString().Trim() + Environment.NewLine;
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
Paragraph paragraph = null;
_errorCount = 0;
subtitle.Paragraphs.Clear();
foreach (var line in lines)
{
var s = line.Trim();
if (string.IsNullOrEmpty(s))
{
// ignore
}
else
{
var match = RegexTimeCode.Match(s);
if (match.Success)
{
var arr = match.Value.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length >= 2)
{
var start = GetTimeCode(arr[0].Trim());
var text = s.Remove(0, 8).Trim();
paragraph = new Paragraph(start, new TimeCode(), text);
paragraph.EndTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(paragraph.Text);
subtitle.Paragraphs.Add(paragraph);
}
}
else if (paragraph != null)
{
paragraph.Text = (paragraph.Text + Environment.NewLine + s).Trim();
paragraph.EndTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(paragraph.Text);
}
else
{
_errorCount++;
}
}
}
new FixOverlappingDisplayTimes().Fix(subtitle, new EmptyFixCallback());
subtitle.Renumber();
}
private static TimeCode GetTimeCode(string code)
{
var arr = code.Split(':');
if (arr.Length == 3 && int.TryParse(arr[0], out int hours) && int.TryParse(arr[1], out int minutes) && int.TryParse(arr[2], out int seconds))
{
return new TimeCode(hours, minutes, seconds, 0);
}
return new TimeCode();
}
}
}

View File

@ -726,7 +726,7 @@ namespace Nikse.SubtitleEdit.Forms
}
if (Configuration.Settings.Tools.BatchConvertMkvLanguageCodeStyle == "2" &&
IsoCountryCodes.ThreeToTweLetterLookup.TryGetValue(languageCode.ToUpperInvariant(), out var twoLetterCode))
IsoCountryCodes.ThreeToTwoLetterLookup.TryGetValue(languageCode.ToUpperInvariant(), out var twoLetterCode))
{
return twoLetterCode.ToLowerInvariant() + ".";
}

View File

@ -63,7 +63,7 @@ namespace Nikse.SubtitleEdit.Forms
new LanguageItem("1E", "Norwegian"),
new LanguageItem("1F", "Occitan"),
new LanguageItem("20", "Polish"),
new LanguageItem("21", "Portugese"),
new LanguageItem("21", "Portuguese"),
new LanguageItem("22", "Romanian"),
new LanguageItem("23", "Romansh"),
new LanguageItem("24", "Serbian"),

View File

@ -173,7 +173,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
foreach (var culture in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
{
var twoLetterCode = "?";
if (threeLetterIsoLanguageName != null && IsoCountryCodes.ThreeToTweLetterLookup.TryGetValue(threeLetterIsoLanguageName, out twoLetterCode))
if (threeLetterIsoLanguageName != null && IsoCountryCodes.ThreeToTwoLetterLookup.TryGetValue(threeLetterIsoLanguageName, out twoLetterCode))
{
twoLetterCode = twoLetterCode.ToLowerInvariant();
}