Merge branch 'master' into split-line

This commit is contained in:
Nikolaj Olsson 2019-02-15 19:30:52 +01:00 committed by GitHub
commit cf0d7364ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 47 additions and 62 deletions

View File

@ -201,7 +201,7 @@
<Word from="can*t" to="can't" />
<Word from="can'i" to="can't" />
<Word from="can'I" to="can't" />
<Word from="canlgetyou" to="canI get you" />
<Word from="canlgetyou" to="can I get you" />
<Word from="cannotchange" to="cannot change" />
<Word from="cannut" to="cannot" />
<Word from="can'T" to="can't" />
@ -404,7 +404,6 @@
<Word from="forthe" to="for the" />
<Word from="Foryears" to="For years" />
<Word from="foryou" to="for you" />
<Word from="Foudeen" to="Fouteen" />
<Word from="Foufleen" to="Fourteen" />
<Word from="FourSeasons" to="Four Seasons" />
<Word from="fr/ends" to="friends" />
@ -1347,7 +1346,6 @@
<Word from="vi/ay" to="way" />
<Word from="visitjails" to="visit jails" />
<Word from="Viva/di's" to="Vivaldi's" />
<Word from="vlll" to="vill" />
<Word from="Voilá" to="Voilà" />
<Word from="Voilé" to="Voilà" />
<Word from="vvasjust" to="was just" />
@ -2243,7 +2241,6 @@
<Word from="Goodjob" to="Good job" />
<Word from="google" to="Google" />
<Word from="gothere" to="go there" />
<Word from="gotta" to="got to" />
<Word from="grafier" to="grafter" />
<Word from="granddad" to="grandad" />
<Word from="Granddad" to="Grandad" />
@ -2342,9 +2339,9 @@
<Word from="lasagna" to="lasagne" />
<Word from="leastpeople" to="least people" />
<Word from="lfl" to="if I" />
<Word from="lfthafs" to="lf that's" />
<Word from="lfthis" to="lf this" />
<Word from="lfwe're" to="lf we're" />
<Word from="lfthafs" to="if that's" />
<Word from="lfthis" to="if this" />
<Word from="lfwe're" to="if we're" />
<Word from="lifeform" to="life form" />
<Word from="lightspeed" to="light speed" />
<Word from="limón" to="lemon" />
@ -2489,7 +2486,6 @@
<Word from="shouldthinkthey're" to="should think they're" />
<Word from="skeleton in the closet" to="skeleton in the cupboard" />
<Word from="slipthrough" to="slip through" />
<Word from="smackeroonyos" to="smackeroonios" />
<Word from="smanish" to="smartish" />
<Word from="smith/es" to="smithies" />
<Word from="someplace" to="some place" />
@ -2508,7 +2504,6 @@
<Word from="sufferthe" to="suffer the" />
<Word from="swifier" to="swifter" />
<Word from="t0" to="to" />
<Word from="tabnur" to="taboor" />
<Word from="takeJuma" to="take Juma" />
<Word from="takethe" to="take the" />
<Word from="tatking" to="talking" />

View File

@ -22,8 +22,8 @@
; preprocessor checks
#if VER < EncodeVer(5,5,9)
#error Update your Inno Setup version (5.5.9 or newer)
#if VER < EncodeVer(5,6,0)
#error Update your Inno Setup version (5.6.0 or newer)
#endif
#ifndef UNICODE
@ -31,7 +31,7 @@
#endif
#define app_copyright "Copyright © 2001-2018, Nikse"
#define app_copyright "Copyright © 2001-2019, Nikse"
; If you don't define "localize", i.e. comment out the following line then no translations
; for SubtitleEdit or the installer itself will be included in the installer
#define localize
@ -88,7 +88,7 @@ UninstallDisplayIcon={app}\SubtitleEdit.exe
DefaultDirName={pf}\Subtitle Edit
DefaultGroupName=Subtitle Edit
VersionInfoVersion={#app_ver_full}
MinVersion=5.1
MinVersion=5.6
LicenseFile=..\LICENSE.txt
InfoAfterFile=..\Changelog.txt
SetupIconFile=..\src\Icons\SE.ico

View File

@ -104,7 +104,7 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
{
foreach (XmlNode item in node.ChildNodes)
{
if (item.Attributes != null && HasValidAttributes(item, false))
if (HasValidAttributes(item, false))
{
string to = item.Attributes["to"].Value;
string from = item.Attributes["from"].Value;
@ -132,7 +132,7 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
{
foreach (XmlNode item in node.ChildNodes)
{
if (item.Attributes != null && HasValidAttributes(item, true))
if (HasValidAttributes(item, true))
{
string to = item.Attributes["replaceWith"].Value;
string from = item.Attributes["find"].Value;

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
namespace Nikse.SubtitleEdit.Core.Forms
{
@ -13,7 +12,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
return true;
}
foreach (string noTagLine in noTagText.SplitToLines())
foreach (var line in s.SplitToLines())
{
if (noTagLine.Length > singleLineMaxCharacters)
{
@ -42,8 +41,6 @@ namespace Nikse.SubtitleEdit.Core.Forms
public static Subtitle SplitLongLinesInSubtitle(Subtitle subtitle, int totalLineMaxCharacters, int singleLineMaxCharacters)
{
var splittedIndexes = new List<int>();
var autoBreakedIndexes = new List<int>();
var splittedSubtitle = new Subtitle(subtitle);
splittedSubtitle.Paragraphs.Clear();
string language = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle);
@ -59,7 +56,6 @@ namespace Nikse.SubtitleEdit.Core.Forms
if (!QualifiesForSplit(text, singleLineMaxCharacters, totalLineMaxCharacters))
{
var newParagraph = new Paragraph(p) { Text = text };
autoBreakedIndexes.Add(splittedSubtitle.Paragraphs.Count);
splittedSubtitle.Paragraphs.Add(newParagraph);
added = true;
}
@ -86,9 +82,6 @@ namespace Nikse.SubtitleEdit.Core.Forms
newParagraph2.Text = Utilities.AutoBreakLine(arr[1], language);
newParagraph2.StartTime.TotalMilliseconds = newParagraph1.EndTime.TotalMilliseconds + spacing2;
splittedIndexes.Add(splittedSubtitle.Paragraphs.Count);
splittedIndexes.Add(splittedSubtitle.Paragraphs.Count + 1);
string p1 = HtmlUtil.RemoveHtmlTags(newParagraph1.Text);
var len = p1.Length - 1;
if (p1.Length > 0 && (p1[len] == '.' || p1[len] == '!' || p1[len] == '?' || p1[len] == ':' || p1[len] == ')' || p1[len] == ']' || p1[len] == '♪'))

View File

@ -454,9 +454,12 @@ namespace Nikse.SubtitleEdit.Core
public void Renumber(int startNumber = 1)
{
foreach (Paragraph p in _paragraphs)
var index = startNumber;
int l = _paragraphs.Count;
while (index < l)
{
p.Number = startNumber++;
var p = _paragraphs[index++];
p.Number = index;
}
}

View File

@ -38,6 +38,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
catch
{
// ignored
}
}
@ -134,26 +135,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return Convert.ToDouble(s) * TimeCode.BaseUnit;
}
public override bool HasStyleSupport
{
get { return true; }
}
public static List<string> GetStylesFromHeader(Subtitle subtitle)
{
var list = new List<string>();
foreach (Paragraph p in subtitle.Paragraphs)
{
if (!string.IsNullOrEmpty(p.Actor))
{
if (list.IndexOf(p.Actor) < 0)
{
list.Add(p.Actor);
}
}
}
return list;
}
public override bool HasStyleSupport => true;
}
}

View File

@ -185,7 +185,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
subtitle.Header = "WEBVTT";
}
else if (p != null && hadEmptyLine && Utilities.IsInteger(line) &&
else if (p != null && hadEmptyLine && Utilities.IsInteger(line.RemoveChar('-')) &&
(RegexTimeCodesMiddle.IsMatch(next) ||
RegexTimeCodesShort.IsMatch(next) ||
RegexTimeCodes.IsMatch(next)))

View File

@ -60,7 +60,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
Paragraph p = null;
string positionInfo = string.Empty;
bool hadEmptyLine = false;
int numbers = 0;
for (var index = 0; index < lines.Count; index++)
{
string line = lines[index];
@ -112,12 +111,12 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
subtitle.Header = "WEBVTT FILE";
}
else if (p != null && hadEmptyLine && Utilities.IsInteger(line) &&
else if (p != null && hadEmptyLine && Utilities.IsInteger(line.RemoveChar('-')) &&
(RegexTimeCodesMiddle.IsMatch(next) ||
RegexTimeCodesShort.IsMatch(next) ||
RegexTimeCodes.IsMatch(next)))
{
numbers++;
// line number
}
else if (p != null)
{

View File

@ -248,19 +248,24 @@ namespace Nikse.SubtitleEdit.Forms
private static int GetLastTimeStampInSeconds(string text)
{
var lines = text.SplitToLines();
lines.Reverse();
foreach (var line in lines)
for (int i = lines.Count - 1; i >= 0; i--)
{
if (!line.StartsWith('<') && !line.StartsWith('['))
string line = lines[i];
if (line.StartsWith('<') || line.StartsWith('['))
{
var parts = line.Split();
if (parts.Length == 4)
{
if (double.TryParse(parts[1], out _) && double.TryParse(parts[2], out var end))
{
return (int)Math.Round(end);
}
}
continue;
}
var words = line.Split();
if (words.Length != 4)
{
continue;
}
if (double.TryParse(words[1], out _) && double.TryParse(words[2], out var end))
{
return (int)Math.Round(end);
}
}

View File

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
@ -34,6 +35,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
private HashSet<string> _nameList = new HashSet<string>();
private HashSet<string> _nameListUppercase = new HashSet<string>();
private HashSet<string> _nameListWithApostrophe = new HashSet<string>();
private List<string> _nameListWithPeriods = new List<string>();
private HashSet<string> _nameMultiWordList = new HashSet<string>(); // case sensitive phrases
private HashSet<string> _abbreviationList;
private HashSet<string> _userWordList = new HashSet<string>();
@ -237,6 +239,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
_nameMultiWordList = _nameListObj.GetMultiNames();
_nameListUppercase = new HashSet<string>();
_nameListWithApostrophe = new HashSet<string>();
_nameListWithPeriods = new List<string>();
_abbreviationList = new HashSet<string>();
bool isEnglish = threeLetterIsoLanguageName.Equals("eng", StringComparison.OrdinalIgnoreCase);
@ -254,11 +257,17 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
_nameListWithApostrophe.Add(name + "'");
}
}
// Abbreviations.
if (name.EndsWith('.'))
{
_abbreviationList.Add(name);
}
if (name.Contains("."))
{
_nameListWithPeriods.Add(name);
}
}
if (isEnglish)
{
@ -1244,7 +1253,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
string tempLine = line;
const string p = " ¡¿,.!?:;()[]{}+-$£\"„”“#&%…—♪\r\n";
foreach (string name in _nameMultiWordList)
foreach (string name in _nameMultiWordList.Concat(_nameListWithPeriods))
{
int start = tempLine.FastIndexOf(name);
if (start == 0 || (start > 0 && p.Contains(tempLine[start - 1])))