Ejemplo n.º 1
0
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.MergeShortLineAll;
     int noOfShortLines = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = subtitle.Paragraphs[i];
         if (callbacks.AllowFix(p, fixAction))
         {
             string s = HtmlUtil.RemoveHtmlTags(p.Text, true);
             if (s.Replace(Environment.NewLine, " ").Replace("  ", " ").Length < Configuration.Settings.Tools.MergeLinesShorterThan && p.Text.Contains(Environment.NewLine))
             {
                 s = Utilities.AutoBreakLine(p.Text, callbacks.Language);
                 if (s != p.Text)
                 {
                     string oldCurrent = p.Text;
                     p.Text = s;
                     noOfShortLines++;
                     callbacks.AddFixToListView(p, fixAction, oldCurrent, p.Text);
                 }
             }
         }
     }
     callbacks.UpdateFixStatus(noOfShortLines, language.RemoveLineBreaks, string.Format(language.XLinesUnbreaked, noOfShortLines));
 }
Ejemplo n.º 2
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language     = Configuration.Settings.Language.FixCommonErrors;
            string fixAction    = string.Format(language.FixHyphensInDialogs, Configuration.Settings.General.DialogStyle);
            int    iFixes       = 0;
            var    dialogHelper = new DialogSplitMerge {
                DialogStyle = Configuration.Settings.General.DialogStyle
            };

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    string oldText = p.Text;
                    string text    = dialogHelper.FixDashesAndSpaces(p.Text);
                    if (text != oldText)
                    {
                        p.Text = text;
                        iFixes++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(iFixes, fixAction, language.XHyphensInDialogsFixed);
        }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixLongDisplayTime;
            int noOfLongDisplayTimes = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                double maxDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text) * 8.0;
                if (maxDisplayTime > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
                    maxDisplayTime = Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
                double displayTime = p.Duration.TotalMilliseconds;

                bool allowFix = callbacks.AllowFix(p, fixAction);
                if (allowFix && displayTime > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
                {
                    string oldCurrent = p.ToString();
                    p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
                    noOfLongDisplayTimes++;
                    callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                }
                else if (allowFix && maxDisplayTime < displayTime)
                {
                    string oldCurrent = p.ToString();
                    displayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text);
                    p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + displayTime;
                    noOfLongDisplayTimes++;
                    callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                }
            }

            callbacks.UpdateFixStatus(noOfLongDisplayTimes, language.FixLongDisplayTimes, string.Format(language.XDisplayTimesShortned, noOfLongDisplayTimes));
        }
Ejemplo n.º 4
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            string fixAction           = Language.FixInvalidItalicTag;
            int    noOfInvalidHtmlTags = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                if (callbacks.AllowFix(subtitle.Paragraphs[i], fixAction))
                {
                    var text = subtitle.Paragraphs[i].Text;
                    if (text.Contains('<'))
                    {
                        string oldText = text;
                        text = HtmlUtil.FixInvalidItalicTags(text);
                        if (text != oldText)
                        {
                            subtitle.Paragraphs[i].Text = text;
                            noOfInvalidHtmlTags++;
                            callbacks.AddFixToListView(subtitle.Paragraphs[i], fixAction, oldText, text);
                        }
                    }
                }
            }

            callbacks.UpdateFixStatus(noOfInvalidHtmlTags, Language.FixInvalidItalicTags);
        }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            const string beginTagUpper = "<I>";
            const string endTagUpper = "</I>";
            const string beginTag = "<i>";
            const string endTag = "</i>";
            string fixAction = language.FixInvalidItalicTag;
            int noOfInvalidHtmlTags = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                if (callbacks.AllowFix(subtitle.Paragraphs[i], fixAction))
                {
                    var text = subtitle.Paragraphs[i].Text;
                    if (text.Contains('<'))
                    {
                        text = text.Replace(beginTagUpper, beginTag).Replace(endTagUpper, endTag);
                        string oldText = text;

                        text = HtmlUtil.FixInvalidItalicTags(text);
                        if (text != oldText)
                        {
                            subtitle.Paragraphs[i].Text = text;
                            noOfInvalidHtmlTags++;
                            callbacks.AddFixToListView(subtitle.Paragraphs[i], fixAction, oldText, text);
                        }
                    }
                }
            }

            callbacks.UpdateFixStatus(noOfInvalidHtmlTags, language.FixInvalidItalicTags, string.Format(language.XInvalidHtmlTagsFixed, noOfInvalidHtmlTags));
        }
Ejemplo n.º 6
0
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.FixEllipsesStart;
     int fixCount = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = subtitle.Paragraphs[i];
         var text = p.Text;
         if (text.Contains("..") && callbacks.AllowFix(p, fixAction))
         {
             var oldText = text;
             string[] lines = text.SplitToLines();
             for (int k = 0; k < lines.Length; k++)
             {
                 lines[k] = Helper.FixEllipsesStartHelper(lines[k]);
             }
             text = string.Join(Environment.NewLine, lines);
             if (oldText.Length > text.Length)
             {
                 p.Text = text;
                 fixCount++;
                 callbacks.AddFixToListView(p, fixAction, oldText, text);
             }
         }
     }
     callbacks.UpdateFixStatus(fixCount, language.FixEllipsesStart, language.XFixEllipsesStart);
 }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixMusicNotation;
            int fixCount = 0;
            string[] musicSymbols = Configuration.Settings.Tools.MusicSymbolToReplace.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    var oldText = p.Text;
                    var newText = oldText;

                    foreach (string musicSymbol in musicSymbols)
                    {
                        newText = newText.Replace(musicSymbol, Configuration.Settings.Tools.MusicSymbol);
                        newText = newText.Replace(musicSymbol.ToUpper(), Configuration.Settings.Tools.MusicSymbol);
                    }
                    var noTagsText = HtmlUtil.RemoveHtmlTags(newText);
                    if (newText != oldText && noTagsText != HtmlUtil.RemoveHtmlTags(oldText))
                    {
                        p.Text = newText;
                        fixCount++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(fixCount, language.FixMusicNotation, language.XFixMusicNotation);
        }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var          language            = Configuration.Settings.Language.FixCommonErrors;
            const string beginTagUpper       = "<I>";
            const string endTagUpper         = "</I>";
            const string beginTag            = "<i>";
            const string endTag              = "</i>";
            string       fixAction           = language.FixInvalidItalicTag;
            int          noOfInvalidHtmlTags = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                if (callbacks.AllowFix(subtitle.Paragraphs[i], fixAction))
                {
                    var text = subtitle.Paragraphs[i].Text;
                    if (text.Contains('<'))
                    {
                        text = text.Replace(beginTagUpper, beginTag).Replace(endTagUpper, endTag);
                        string oldText = text;

                        text = HtmlUtil.FixInvalidItalicTags(text);
                        if (text != oldText)
                        {
                            subtitle.Paragraphs[i].Text = text;
                            noOfInvalidHtmlTags++;
                            callbacks.AddFixToListView(subtitle.Paragraphs[i], fixAction, oldText, text);
                        }
                    }
                }
            }

            callbacks.UpdateFixStatus(noOfInvalidHtmlTags, language.FixInvalidItalicTags, string.Format(language.XInvalidHtmlTagsFixed, noOfInvalidHtmlTags));
        }
Ejemplo n.º 9
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            string fixAction    = string.Format(Language.FixHyphensInDialogs, Configuration.Settings.General.DialogStyle);
            int    iFixes       = 0;
            var    dialogHelper = new DialogSplitMerge
            {
                DialogStyle           = Configuration.Settings.General.DialogStyle,
                TwoLetterLanguageCode = callbacks.Language,
                ContinuationStyle     = Configuration.Settings.General.ContinuationStyle
            };

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    string oldText = p.Text;
                    var    prev    = subtitle.GetParagraphOrDefault(i - 1);
                    string text    = dialogHelper.FixDashesAndSpaces(p.Text, p, prev);
                    if (text != oldText)
                    {
                        p.Text = text;
                        iFixes++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(iFixes, fixAction);
        }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language  = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.StartWithUppercaseLetterAfterPeriodInsideParagraph;
            int    noOfFixes = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p       = subtitle.Paragraphs[i];
                string    oldText = p.Text;
                if (p.Text.Length > 3 && callbacks.AllowFix(p, fixAction))
                {
                    var    st    = new StrippableText(p.Text);
                    string text  = st.StrippedText;
                    int    start = text.IndexOfAny(ExpectedChars);
                    while (start > 0 && start < text.Length)
                    {
                        char charAtPosition = text[start];
                        // Allow fixing lowercase letter after recursive ??? or !!!.
                        if (charAtPosition != '.') // Dot is not include 'cause I don't capitalize word after the ellipses (...), right?
                        {
                            while (start + 1 < text.Length && text[start + 1] == charAtPosition)
                            {
                                start++;
                            }
                        }

                        // Try to reach the last dot if char at *start is '.'.
                        if (charAtPosition == '.')
                        {
                            while (start + 1 < text.Length && text[start + 1] == '.')
                            {
                                start++;
                            }
                        }

                        if ((start + 3 < text.Length) && (text[start + 1] == ' ') && !IsAbbreviation(text, start, callbacks))
                        {
                            var textBefore = text.Substring(0, start + 1);
                            var subText    = new StrippableText(text.Substring(start + 2));
                            text = text.Substring(0, start + 2) + subText.CombineWithPrePost(ToUpperFirstLetter(textBefore, subText.StrippedText, callbacks));
                        }

                        start += 3;
                        if (start < text.Length)
                        {
                            start = text.IndexOfAny(ExpectedChars, start);
                        }
                    }
                    text = st.CombineWithPrePost(text);
                    if (oldText != text)
                    {
                        p.Text = text;
                        noOfFixes++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(noOfFixes, language.StartWithUppercaseLetterAfterPeriodInsideParagraph, noOfFixes.ToString(CultureInfo.InvariantCulture));
        }
Ejemplo n.º 11
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language  = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixTurkishAnsi;
            int    noOfFixes = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p       = subtitle.Paragraphs[i];
                string    text    = p.Text;
                string    oldText = text;
                text = text.Replace('Ý', 'İ');
                text = text.Replace('Ð', 'Ğ');
                text = text.Replace('Þ', 'Ş');
                text = text.Replace('ý', 'ı');
                text = text.Replace('ð', 'ğ');
                text = text.Replace('þ', 'ş');
                if (oldText != text && callbacks.AllowFix(p, fixAction))
                {
                    p.Text = text;
                    noOfFixes++;
                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(noOfFixes, language.FixCommonOcrErrors, language.FixTurkishAnsi);
        }
Ejemplo n.º 12
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language       = Configuration.Settings.Language.FixCommonErrors;
            string fixAction      = language.MergeShortLineAll;
            int    noOfShortLines = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    string s = HtmlUtil.RemoveHtmlTags(p.Text, true);
                    if (s.Replace(Environment.NewLine, " ").Replace("  ", " ").Length < Configuration.Settings.Tools.MergeLinesShorterThan && p.Text.Contains(Environment.NewLine))
                    {
                        s = Utilities.AutoBreakLine(p.Text, callbacks.Language);
                        if (s != p.Text)
                        {
                            string oldCurrent = p.Text;
                            p.Text = s;
                            noOfShortLines++;
                            callbacks.AddFixToListView(p, fixAction, oldCurrent, p.Text);
                        }
                    }
                }
            }
            callbacks.UpdateFixStatus(noOfShortLines, language.RemoveLineBreaks, string.Format(language.XLinesUnbreaked, noOfShortLines));
        }
Ejemplo n.º 13
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language      = Configuration.Settings.Language.FixCommonErrors;
            double minGap        = Configuration.Settings.General.MinimumMillisecondsBetweenLines;
            string fixAction     = language.FixShortGap;
            int    noOfShortGaps = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count - 1; i++)
            {
                var p    = subtitle.Paragraphs[i];
                var next = subtitle.Paragraphs[i + 1];
                if (!next.StartTime.IsMaxTime && !p.EndTime.IsMaxTime)
                {
                    double gap      = next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds;
                    bool   allowFix = callbacks.AllowFix(p, fixAction);
                    if (allowFix && gap < minGap)
                    {
                        string oldCurrent = p.ToString();
                        p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - minGap;
                        noOfShortGaps++;
                        callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                    }
                }
            }
            callbacks.UpdateFixStatus(noOfShortGaps, language.FixShortGaps, string.Format(language.XGapsFixed, noOfShortGaps));
        }
Ejemplo n.º 14
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language  = Configuration.Settings.Language.FixCommonErrors;
            var fixAction = language.Fix3PlusLine;
            int iFixes    = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p = subtitle.Paragraphs[i];
                if (Utilities.GetNumberOfLines(p.Text) > 2 && callbacks.AllowFix(p, fixAction))
                {
                    var savedMaxNumberOfLines = Configuration.Settings.General.MaxNumberOfLines;
                    Configuration.Settings.General.MaxNumberOfLines = 2;
                    var oldText = p.Text;
                    try
                    {
                        p.Text = Utilities.AutoBreakLine(p.Text, callbacks.Language);
                    }
                    finally
                    {
                        Configuration.Settings.General.MaxNumberOfLines = savedMaxNumberOfLines;
                    }

                    if (oldText != p.Text)
                    {
                        iFixes++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(iFixes, language.Fix3PlusLines, language.X3PlusLinesFixed);
        }
Ejemplo n.º 15
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            int noOfLongDisplayTimes = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                double    maxDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text) * 8.0;
                if (maxDisplayTime > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
                {
                    maxDisplayTime = Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
                }

                double displayTime = p.Duration.TotalMilliseconds;

                bool allowFix = callbacks.AllowFix(p, Language.FixLongDisplayTime);
                if (allowFix && displayTime > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
                {
                    string oldCurrent = p.ToString();
                    p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
                    noOfLongDisplayTimes++;
                    callbacks.AddFixToListView(p, Language.FixLongDisplayTime, oldCurrent, p.ToString());
                }
                else if (allowFix && maxDisplayTime < displayTime)
                {
                    string oldCurrent = p.ToString();
                    displayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text);
                    p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + displayTime;
                    noOfLongDisplayTimes++;
                    callbacks.AddFixToListView(p, Language.FixLongDisplayTime, oldCurrent, p.ToString());
                }
            }

            callbacks.UpdateFixStatus(noOfLongDisplayTimes, Language.FixLongDisplayTime);
        }
Ejemplo n.º 16
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language     = Configuration.Settings.Language.FixCommonErrors;
            string fixAction    = language.UnneededPeriod;
            int    removedCount = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    // Returns processed text.
                    string procText = RemoveDotAfterPunctuation(p.Text);
                    int    diff     = p.Text.Length - procText.Length;
                    if (diff > 0)
                    {
                        // Calculate total removed dots.
                        removedCount += diff;
                        callbacks.AddFixToListView(p, fixAction, p.Text, procText);
                        p.Text = procText;
                    }
                }
            }
            callbacks.UpdateFixStatus(removedCount, language.RemoveUnneededPeriods, string.Format(language.XUnneededPeriodsRemoved, removedCount));
        }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixSpanishInvertedQuestionAndExclamationMarks;
            int fixCount = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                Paragraph last = subtitle.GetParagraphOrDefault(i - 1);

                bool wasLastLineClosed = last == null || last.Text.EndsWith('?') || last.Text.EndsWith('!') || last.Text.EndsWith('.') ||
                                         last.Text.EndsWith(':') || last.Text.EndsWith(')') || last.Text.EndsWith(']');
                string trimmedStart = p.Text.TrimStart('-', ' ');
                if (last != null && last.Text.EndsWith("...", StringComparison.Ordinal) && trimmedStart.Length > 0 && char.IsLower(trimmedStart[0]))
                    wasLastLineClosed = false;
                if (!wasLastLineClosed && last.Text == last.Text.ToUpper())
                    wasLastLineClosed = true;

                string oldText = p.Text;

                FixSpanishInvertedLetter('?', "¿", p, last, ref wasLastLineClosed, fixAction, ref fixCount, callbacks);
                FixSpanishInvertedLetter('!', "¡", p, last, ref wasLastLineClosed, fixAction, ref fixCount, callbacks);

                if (p.Text != oldText)
                {
                    fixCount++;
                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(fixCount, language.FixSpanishInvertedQuestionAndExclamationMarks, fixCount.ToString(CultureInfo.InvariantCulture));
        }
Ejemplo n.º 18
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            int fixCount = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p    = subtitle.Paragraphs[i];
                var       text = p.Text;
                if (text.Contains("..") && callbacks.AllowFix(p, Language.FixEllipsesStart))
                {
                    var oldText = text;
                    var lines   = text.SplitToLines();
                    for (int k = 0; k < lines.Count; k++)
                    {
                        lines[k] = Helper.FixEllipsesStartHelper(lines[k]);
                    }
                    text = string.Join(Environment.NewLine, lines);
                    if (oldText.Length > text.Length)
                    {
                        p.Text = text;
                        fixCount++;
                        callbacks.AddFixToListView(p, Language.FixEllipsesStart, oldText, text);
                    }
                }
            }
            callbacks.UpdateFixStatus(fixCount, Language.FixEllipsesStart);
        }
Ejemplo n.º 19
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language  = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixMusicNotation;
            int    fixCount  = 0;

            string[] musicSymbols = Configuration.Settings.Tools.MusicSymbolToReplace.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    var oldText = p.Text;
                    var newText = oldText;

                    foreach (string musicSymbol in musicSymbols)
                    {
                        newText = newText.Replace(musicSymbol, Configuration.Settings.Tools.MusicSymbol);
                        newText = newText.Replace(musicSymbol.ToUpper(), Configuration.Settings.Tools.MusicSymbol);
                    }
                    var noTagsText = HtmlUtil.RemoveHtmlTags(newText);
                    if (newText != oldText && noTagsText != HtmlUtil.RemoveHtmlTags(oldText))
                    {
                        p.Text = newText;
                        fixCount++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(fixCount, language.FixMusicNotation, language.XFixMusicNotation);
        }
Ejemplo n.º 20
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            string fixAction      = Language.MergeShortLineAll;
            int    noOfShortLines = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    string s = HtmlUtil.RemoveHtmlTags(p.Text, true);
                    if (s.Contains(Environment.NewLine) && s.Replace(Environment.NewLine, " ").Replace("  ", " ").CountCharacters(false) < Configuration.Settings.General.MergeLinesShorterThan)
                    {
                        s = Utilities.AutoBreakLine(p.Text, callbacks.Language);
                        if (s != p.Text)
                        {
                            string oldCurrent = p.Text;
                            p.Text = s;
                            noOfShortLines++;
                            callbacks.AddFixToListView(p, fixAction, oldCurrent, p.Text);
                        }
                    }
                }
            }
            callbacks.UpdateFixStatus(noOfShortLines, Language.RemoveLineBreaks);
        }
Ejemplo n.º 21
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language  = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.Fix3PlusLine;
            int    iFixes    = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                if (Utilities.GetNumberOfLines(p.Text) > 2 && callbacks.AllowFix(p, fixAction))
                {
                    var old = Configuration.Settings.Tools.ListViewSyntaxMoreThanXLinesX;
                    Configuration.Settings.Tools.ListViewSyntaxMoreThanXLinesX = 2;
                    string oldText = p.Text;
                    try
                    {
                        p.Text = Utilities.AutoBreakLine(p.Text);
                    }
                    finally
                    {
                        Configuration.Settings.Tools.ListViewSyntaxMoreThanXLinesX = old;
                    }
                    if (oldText != p.Text)
                    {
                        iFixes++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(iFixes, language.Fix3PlusLines, language.X3PlusLinesFixed);
        }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var fixAction = Language.RemoveDialogFirstInNonDialogs;
            var noOfFixes = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p       = subtitle.Paragraphs[i];
                var oldText = p.Text;
                var text    = p.Text;
                var noHtml  = HtmlUtil.RemoveHtmlTags(text, true).TrimStart();


                var count = Utilities.CountTagInText(text, '-') + Utilities.CountTagInText(text, '‐');
                if (count == 0 || !noHtml.StartsWith('-') && !noHtml.StartsWith('‐'))
                {
                    continue;
                }

                // test the two different dashes
                text = RemoveDash(text, noHtml, '-');
                text = RemoveDash(text, noHtml, '‐');

                if (oldText != text && callbacks.AllowFix(p, fixAction))
                {
                    p.Text = text;
                    noOfFixes++;
                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(noOfFixes, Language.RemoveDialogFirstInNonDialogs);
        }
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.FixTurkishAnsi;
     int noOfFixes = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = subtitle.Paragraphs[i];
         string text = p.Text;
         string oldText = text;
         text = text.Replace('Ý', 'İ');
         text = text.Replace('Ð', 'Ğ');
         text = text.Replace('Þ', 'Ş');
         text = text.Replace('ý', 'ı');
         text = text.Replace('ð', 'ğ');
         text = text.Replace('þ', 'ş');
         if (oldText != text && callbacks.AllowFix(p, fixAction))
         {
             p.Text = text;
             noOfFixes++;
             callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
         }
     }
     callbacks.UpdateFixStatus(noOfFixes, language.FixCommonOcrErrors, language.FixTurkishAnsi);
 }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var fixAction = Language.RemoveDialogFirstInNonDialogs;
            var noOfFixes = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p       = subtitle.Paragraphs[i];
                var oldText = p.Text;
                var text    = p.Text;
                var noHtml  = HtmlUtil.RemoveHtmlTags(text, true).TrimStart();
                var count   = Utilities.CountTagInText(text, '-');
                if (count == 0 || !noHtml.StartsWith('-'))
                {
                    continue;
                }

                if (count == 1)
                {
                    text = RemoveFirstDash(text);
                }
                else if (count > 1)
                {
                    var lines = noHtml.SplitToLines();
                    if (lines.Count == 1)
                    {
                        if (!noHtml.Contains(". -") && !noHtml.Contains("! -") && !noHtml.Contains("? -"))
                        {
                            text = RemoveFirstDash(text);
                        }
                    }
                    else if (lines.Count == 2)
                    {
                        if (!noHtml.Contains(". -") && !noHtml.Contains("! -") && !noHtml.Contains("? -") && !lines[1].StartsWith('-'))
                        {
                            text = RemoveFirstDash(text);
                        }
                    }
                    else if (lines.Count == 3)
                    {
                        if (!noHtml.Contains(". -") && !noHtml.Contains("! -") && !noHtml.Contains("? -") &&
                            !lines[1].StartsWith('-') &&
                            !lines[2].StartsWith('-'))
                        {
                            text = RemoveFirstDash(text);
                        }
                    }
                }

                if (oldText != text && callbacks.AllowFix(p, fixAction))
                {
                    p.Text = text;
                    noOfFixes++;
                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(noOfFixes, Language.RemoveDialogFirstInNonDialogs);
        }
Ejemplo n.º 25
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            int       fixCount  = 0;
            var       language  = Configuration.Settings.Language.FixCommonErrors;
            var       fixAction = language.FixSpanishInvertedQuestionAndExclamationMarks;
            Paragraph p;
            string    oldText;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                p = subtitle.Paragraphs[i];

                var last = subtitle.GetParagraphOrDefault(i - 1);
                if (last != null && p.StartTime.TotalMilliseconds - last.EndTime.TotalMilliseconds > 1000)
                {
                    last = null; // too much time
                }

                var next = subtitle.GetParagraphOrDefault(i + 1);
                if (next != null && next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds > 1000)
                {
                    next = null; // to much time
                }

                oldText = p.Text;

                var isLastLineClosed = last == null || last.Text.Length > 0 && ".!?:)]".Contains(last.Text[last.Text.Length - 1]);
                var trimmedStart     = p.Text.TrimStart('-', ' ');
                if (last != null && last.Text.EndsWith("...", StringComparison.Ordinal) && trimmedStart.Length > 0 && char.IsLower(trimmedStart[0]))
                {
                    isLastLineClosed = false;
                }

                if (!isLastLineClosed && last.Text == last.Text.ToUpperInvariant())
                {
                    isLastLineClosed = true;
                }

                FixSpanishInvertedLetter('?', "¿", p, last, next, ref isLastLineClosed, callbacks);
                FixSpanishInvertedLetter('!', "¡", p, last, next, ref isLastLineClosed, callbacks);

                if (p?.Text != oldText)
                {
                    if (callbacks.AllowFix(p, fixAction))
                    {
                        fixCount++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                    else
                    {
                        p.Text = oldText;
                    }
                }
            }
            callbacks.UpdateFixStatus(fixCount, language.FixSpanishInvertedQuestionAndExclamationMarks, fixCount.ToString(CultureInfo.InvariantCulture));
        }
Ejemplo n.º 26
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var commaDouble            = new Regex(@"([\p{L}\d\s]),,([\p{L}\d\s])");
            var commaTriple            = new Regex(@"([\p{L}\d\s]) *, *, *,([\p{L}\d\s])");
            var commaTripleEndOfLine   = new Regex(@"([\p{L}\d\s]), *, *,$");
            var commaWhiteSpaceBetween = new Regex(@"([\p{L}\d\s]),\s+,([\p{L}\d\s])");
            var commaFollowedByLetter  = new Regex(@",(\p{L})");

            string fixAction = Configuration.Settings.Language.FixCommonErrors.FixCommas;
            int    fixCount  = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    var s       = p.Text;
                    var oldText = s;

                    if (p.Text.IndexOf(',') >= 0)
                    {
                        s = commaDouble.Replace(s, "$1,$2");
                        s = commaTriple.Replace(s, "$1...$2");
                        s = commaTripleEndOfLine.Replace(s, "$1...");
                        s = commaWhiteSpaceBetween.Replace(s, "$1,$2");
                        s = commaFollowedByLetter.Replace(s, ", $1");

                        s = RemoveCommaBeforeSentenceEndingChar(s, ',');
                    }

                    if (p.Text.IndexOf('،') >= 0)
                    {
                        var commaDoubleAr            = new Regex(@"([\p{L}\d\s]) *،،([\p{L}\d\s])");
                        var commaTripleAr            = new Regex(@"([\p{L}\d\s]) *، *، *،([\p{L}\d\s])");
                        var commaTripleEndOfLineAr   = new Regex(@"([\p{L}\d\s]) *، *، *،$");
                        var commaWhiteSpaceBetweenAr = new Regex(@"([\p{L}\d\s]) *،\s+،([\p{L}\d\s])");
                        var commaFollowedByLetterAr  = new Regex(@"،(\p{L})");
                        s = commaDoubleAr.Replace(s, "$1،$2");
                        s = commaTripleAr.Replace(s, "$1...$2");
                        s = commaTripleEndOfLineAr.Replace(s, "$1...");
                        s = commaWhiteSpaceBetweenAr.Replace(s, "$1،$2");
                        s = commaFollowedByLetterAr.Replace(s, "، $1");

                        s = RemoveCommaBeforeSentenceEndingChar(s, '،');
                    }

                    if (oldText != s)
                    {
                        fixCount++;
                        callbacks.AddFixToListView(p, fixAction, oldText, s);
                        p.Text = s;
                    }
                }
            }
            callbacks.UpdateFixStatus(fixCount, Configuration.Settings.Language.FixCommonErrors.FixCommas, fixCount.ToString());
        }
Ejemplo n.º 27
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language             = Configuration.Settings.Language.FixCommonErrors;
            string fixAction            = language.UnneededPeriod;
            int    unneededPeriodsFixed = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p       = subtitle.Paragraphs[i];
                var       oldText = p.Text;
                if (callbacks.AllowFix(p, fixAction))
                {
                    if (p.Text.Contains("!." + Environment.NewLine))
                    {
                        p.Text = p.Text.Replace("!." + Environment.NewLine, "!" + Environment.NewLine);
                        unneededPeriodsFixed++;
                    }
                    if (p.Text.Contains("?." + Environment.NewLine))
                    {
                        p.Text = p.Text.Replace("?." + Environment.NewLine, "?" + Environment.NewLine);
                        unneededPeriodsFixed++;
                    }
                    if (p.Text.EndsWith("!.", StringComparison.Ordinal))
                    {
                        p.Text = p.Text.TrimEnd('.');
                        unneededPeriodsFixed++;
                    }
                    if (p.Text.EndsWith("?.", StringComparison.Ordinal))
                    {
                        p.Text = p.Text.TrimEnd('.');
                        unneededPeriodsFixed++;
                    }

                    var len = p.Text.Length;
                    if (p.Text.Contains("!. "))
                    {
                        p.Text = p.Text.Replace("!. ", "! ");
                        unneededPeriodsFixed += len - p.Text.Length;
                        len = p.Text.Length;
                    }
                    if (p.Text.Contains("?. "))
                    {
                        p.Text = p.Text.Replace("?. ", "? ");
                        unneededPeriodsFixed += len - p.Text.Length;
                    }

                    if (p.Text != oldText)
                    {
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(unneededPeriodsFixed, language.RemoveUnneededPeriods, string.Format(language.XUnneededPeriodsRemoved, unneededPeriodsFixed));
        }
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.StartWithUppercaseLetterAfterPeriodInsideParagraph;
     int noOfFixes = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = subtitle.Paragraphs[i];
         string oldText = p.Text;
         if (p.Text.Length > 3 && callbacks.AllowFix(p, fixAction))
         {
             var st = new StrippableText(p.Text);
             string text = st.StrippedText;
             int start = text.IndexOfAny(ExpectedChars);
             while (start > 0 && start < text.Length)
             {
                 char charAtPosition = text[start];
                 // Allow fixing lowercase letter after recursive ??? or !!!.
                 if (charAtPosition != '.') // Dot is not include 'cause I don't capitalize word after the ellipses (...), right?
                 {
                     while (start + 1 < text.Length && text[start + 1] == charAtPosition)
                     {
                         start++;
                     }
                 }
                 if ((start + 3 < text.Length) && (text[start + 1] == ' ') && !IsAbbreviation(text, start, callbacks))
                 {
                     var subText = new StrippableText(text.Substring(start + 2));
                     text = text.Substring(0, start + 2) + subText.CombineWithPrePost(ToUpperFirstLetter(subText.StrippedText, callbacks));
                 }
                 // Try to reach the last dot if char at *start is '.'.
                 if (charAtPosition == '.')
                 {
                     while (start + 1 < text.Length && text[start + 1] == '.')
                     {
                         start++;
                     }
                 }
                 start += 3;
                 if (start < text.Length)
                     start = text.IndexOfAny(ExpectedChars, start);
             }
             text = st.CombineWithPrePost(text);
             if (oldText != text)
             {
                 p.Text = text;
                 noOfFixes++;
                 callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
             }
         }
     }
     callbacks.UpdateFixStatus(noOfFixes, language.StartWithUppercaseLetterAfterPeriodInsideParagraph, noOfFixes.ToString(CultureInfo.InvariantCulture));
 }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language  = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixUnnecessaryLeadingDots;
            int    fixCount  = 0;

            for (int i = 1; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p    = subtitle.Paragraphs[i];
                var       text = ContinuationUtilities.SanitizeString(p.Text);
                if ((text.StartsWith("..") || text.StartsWith("…")) && callbacks.AllowFix(p, fixAction))
                {
                    var oldText = p.Text;

                    Paragraph pPrev        = subtitle.Paragraphs[i - 1];
                    var       previousText = ContinuationUtilities.SanitizeString(pPrev.Text);

                    if (previousText.EndsWith("..") || previousText.EndsWith("…"))
                    {
                        // Remove starting dots

                        // Get first word
                        string[] split        = text.Split(Convert.ToChar(" "));
                        string   firstWord    = split[0];
                        string   newFirstWord = firstWord;

                        // Remove dots
                        if (newFirstWord.StartsWith("..."))
                        {
                            newFirstWord = newFirstWord.Substring(3);
                        }
                        if (newFirstWord.StartsWith(".."))
                        {
                            newFirstWord = newFirstWord.Substring(2);
                        }
                        if (newFirstWord.StartsWith("…"))
                        {
                            newFirstWord = newFirstWord.Substring(1);
                        }
                        newFirstWord = newFirstWord.Trim();

                        var newText = ContinuationUtilities.ReplaceFirstOccurrence(oldText, firstWord, newFirstWord);

                        // Commit
                        p.Text = newText;
                        fixCount++;
                        callbacks.AddFixToListView(p, fixAction, oldText, newText);
                    }
                }
            }

            callbacks.UpdateFixStatus(fixCount, language.FixUnnecessaryLeadingDots, language.XFixUnnecessaryLeadingDots);
        }
Ejemplo n.º 30
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language  = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixMusicNotation;
            int    fixCount  = 0;

            string[] musicSymbols = Configuration.Settings.Tools.MusicSymbolReplace.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    var  oldText         = p.Text;
                    var  newText         = oldText;
                    bool containsFontTag = oldText.Contains("<font ", StringComparison.OrdinalIgnoreCase);
                    foreach (string musicSymbol in musicSymbols)
                    {
                        var ms = musicSymbol.Trim();
                        if (containsFontTag && ms == "#")
                        {
                            var idx = newText.IndexOf('#');
                            while (idx >= 0)
                            {
                                // <font color="#808080">NATIVE HAWAIIAN CHANTING</font>
                                var isInsideFontTag = (idx < 13) ? false : (newText[idx - 1] == '"' && (newText.Length > idx + 2 && Uri.IsHexDigit(newText[idx + 1]) && Uri.IsHexDigit(newText[idx + 2])));
                                if (!isInsideFontTag)
                                {
                                    newText = newText.Remove(idx, 1);
                                    newText = newText.Insert(idx, Configuration.Settings.Tools.MusicSymbol);
                                }

                                idx = newText.IndexOf('#', idx + 1);
                            }
                        }
                        else
                        {
                            newText = newText.Replace(ms, Configuration.Settings.Tools.MusicSymbol);
                            newText = newText.Replace(ms.ToUpper(), Configuration.Settings.Tools.MusicSymbol);
                        }
                    }
                    var noTagsText = HtmlUtil.RemoveHtmlTags(newText);
                    if (newText != oldText && noTagsText != HtmlUtil.RemoveHtmlTags(oldText))
                    {
                        p.Text = newText;
                        fixCount++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(fixCount, language.FixMusicNotation, language.XFixMusicNotation);
        }
Ejemplo n.º 31
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.UnneededPeriod;
            int unneededPeriodsFixed = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                var oldText = p.Text;
                if (callbacks.AllowFix(p, fixAction))
                {
                    if (p.Text.Contains("!." + Environment.NewLine))
                    {
                        p.Text = p.Text.Replace("!." + Environment.NewLine, "!" + Environment.NewLine);
                        unneededPeriodsFixed++;
                    }
                    if (p.Text.Contains("?." + Environment.NewLine))
                    {
                        p.Text = p.Text.Replace("?." + Environment.NewLine, "?" + Environment.NewLine);
                        unneededPeriodsFixed++;
                    }
                    if (p.Text.EndsWith("!.", StringComparison.Ordinal))
                    {
                        p.Text = p.Text.TrimEnd('.');
                        unneededPeriodsFixed++;
                    }
                    if (p.Text.EndsWith("?.", StringComparison.Ordinal))
                    {
                        p.Text = p.Text.TrimEnd('.');
                        unneededPeriodsFixed++;
                    }

                    var len = p.Text.Length;
                    if (p.Text.Contains("!. "))
                    {
                        p.Text = p.Text.Replace("!. ", "! ");
                        unneededPeriodsFixed += len - p.Text.Length;
                        len = p.Text.Length;
                    }
                    if (p.Text.Contains("?. "))
                    {
                        p.Text = p.Text.Replace("?. ", "? ");
                        unneededPeriodsFixed += len - p.Text.Length;
                    }

                    if (p.Text != oldText)
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(unneededPeriodsFixed, language.RemoveUnneededPeriods, string.Format(language.XUnneededPeriodsRemoved, unneededPeriodsFixed));
        }
Ejemplo n.º 32
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixMusicNotation;
            int fixCount = 0;
            string[] musicSymbols = Configuration.Settings.Tools.MusicSymbolToReplace.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    var oldText = p.Text;
                    var newText = oldText;
                    bool containsFontTag = oldText.Contains("<font ", StringComparison.OrdinalIgnoreCase);
                    foreach (string musicSymbol in musicSymbols)
                    {
                        if (containsFontTag && musicSymbol == "#")
                        {
                            var idx = newText.IndexOf('#');
                            while (idx >= 0)
                            {
                                // <font color="#808080">NATIVE HAWAIIAN CHANTING</font>
                                var isInsideFontTag = (idx < 13) ? false : (newText[idx - 1] == '"' && (newText.Length > idx + 2 && Uri.IsHexDigit(newText[idx + 1]) && Uri.IsHexDigit(newText[idx + 2])));
                                if (!isInsideFontTag)
                                {
                                    newText = newText.Remove(idx, 1);
                                    newText = newText.Insert(idx, Configuration.Settings.Tools.MusicSymbol);
                                }

                                idx = newText.IndexOf('#', idx + 1);
                            }
                        }
                        else
                        {
                            newText = newText.Replace(musicSymbol, Configuration.Settings.Tools.MusicSymbol);
                            newText = newText.Replace(musicSymbol.ToUpper(), Configuration.Settings.Tools.MusicSymbol);
                        }
                    }
                    var noTagsText = HtmlUtil.RemoveHtmlTags(newText);
                    if (newText != oldText && noTagsText != HtmlUtil.RemoveHtmlTags(oldText))
                    {
                        p.Text = newText;
                        fixCount++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(fixCount, language.FixMusicNotation, language.XFixMusicNotation);
        }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language  = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixDoubleGreaterThan;
            int    fixCount  = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    if (!p.Text.Contains(">>", StringComparison.Ordinal))
                    {
                        continue;
                    }
                    var text    = p.Text;
                    var oldText = text;
                    if (!text.Contains(Environment.NewLine))
                    {
                        text = Helper.FixDoubleGreaterThanHelper(text);
                        if (oldText != text)
                        {
                            fixCount++;
                            p.Text = text;
                            callbacks.AddFixToListView(p, fixAction, oldText, text);
                        }
                    }
                    else
                    {
                        var lines = text.SplitToLines();
                        for (int k = 0; k < lines.Length; k++)
                        {
                            lines[k] = Helper.FixDoubleGreaterThanHelper(lines[k]);
                        }
                        text = string.Join(Environment.NewLine, lines);
                        if (oldText != text)
                        {
                            fixCount++;
                            p.Text = text;
                            callbacks.AddFixToListView(p, fixAction, oldText, text);
                        }
                    }
                }
            }
            callbacks.UpdateFixStatus(fixCount, language.FixDoubleGreaterThan, language.XFixDoubleGreaterThan);
        }
Ejemplo n.º 34
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language  = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixEllipsesStart;
            int    fixCount  = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p    = subtitle.Paragraphs[i];
                var       text = p.Text;
                if (text.Contains("..") && callbacks.AllowFix(p, fixAction))
                {
                    var oldText = text;
                    if (!text.Contains(Environment.NewLine))
                    {
                        text = Helper.FixEllipsesStartHelper(text);
                        if (oldText != text)
                        {
                            p.Text = text;
                            fixCount++;
                            callbacks.AddFixToListView(p, fixAction, oldText, text);
                        }
                    }
                    else
                    {
                        var lines          = text.SplitToLines();
                        var fixedParagraph = string.Empty;
                        for (int k = 0; k < lines.Length; k++)
                        {
                            var line = lines[k];
                            fixedParagraph += Environment.NewLine + Helper.FixEllipsesStartHelper(line);
                            fixedParagraph  = fixedParagraph.Trim();
                        }

                        if (fixedParagraph != text)
                        {
                            p.Text = fixedParagraph;
                            fixCount++;
                            callbacks.AddFixToListView(p, fixAction, oldText, fixedParagraph);
                        }
                    }
                }
            }
            callbacks.UpdateFixStatus(fixCount, language.FixEllipsesStart, language.XFixEllipsesStart);
        }
Ejemplo n.º 35
0
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.Fix3PlusLine;
     int iFixes = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = subtitle.Paragraphs[i];
         if (Utilities.GetNumberOfLines(p.Text) > 2 && callbacks.AllowFix(p, fixAction))
         {
             string oldText = p.Text;
             p.Text = Utilities.AutoBreakLine(p.Text);
             iFixes++;
             callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
         }
     }
     callbacks.UpdateFixStatus(iFixes, language.Fix3PlusLines, language.X3PlusLinesFixed);
 }
Ejemplo n.º 36
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixEllipsesStart;
            int fixCount = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                var text = p.Text;
                if (text.Contains("..") && callbacks.AllowFix(p, fixAction))
                {
                    var oldText = text;
                    if (!text.Contains(Environment.NewLine))
                    {
                        text = Helper.FixEllipsesStartHelper(text);
                        if (oldText != text)
                        {
                            p.Text = text;
                            fixCount++;
                            callbacks.AddFixToListView(p, fixAction, oldText, text);
                        }
                    }
                    else
                    {
                        var lines = text.SplitToLines();
                        var fixedParagraph = string.Empty;
                        for (int k = 0; k < lines.Length; k++)
                        {
                            var line = lines[k];
                            fixedParagraph += Environment.NewLine + Helper.FixEllipsesStartHelper(line);
                            fixedParagraph = fixedParagraph.Trim();
                        }

                        if (fixedParagraph != text)
                        {
                            p.Text = fixedParagraph;
                            fixCount++;
                            callbacks.AddFixToListView(p, fixAction, oldText, fixedParagraph);
                        }
                    }
                }
            }
            callbacks.UpdateFixStatus(fixCount, language.FixEllipsesStart, language.XFixEllipsesStart);
        }
Ejemplo n.º 37
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var fixAction = Language.FixDialogsOnOneLine;
            var noOfFixes = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p       = subtitle.Paragraphs[i];
                var oldText = p.Text;
                var text    = Helper.FixDialogsOnOneLine(oldText, callbacks.Language);
                if (oldText != text && callbacks.AllowFix(p, fixAction))
                {
                    p.Text = text;
                    noOfFixes++;
                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(noOfFixes, Language.FixDialogsOnOneLine);
        }
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.FixDoubleGreaterThan;
     int fixCount = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = subtitle.Paragraphs[i];
         if (callbacks.AllowFix(p, fixAction))
         {
             if (!p.Text.Contains(">>", StringComparison.Ordinal))
                 continue;
             var text = p.Text;
             var oldText = text;
             if (!text.Contains(Environment.NewLine))
             {
                 text = Helper.FixDoubleGreaterThanHelper(text);
                 if (oldText != text)
                 {
                     fixCount++;
                     p.Text = text;
                     callbacks.AddFixToListView(p, fixAction, oldText, text);
                 }
             }
             else
             {
                 var lines = text.SplitToLines();
                 for (int k = 0; k < lines.Length; k++)
                 {
                     lines[k] = Helper.FixDoubleGreaterThanHelper(lines[k]);
                 }
                 text = string.Join(Environment.NewLine, lines);
                 if (oldText != text)
                 {
                     fixCount++;
                     p.Text = text;
                     callbacks.AddFixToListView(p, fixAction, oldText, text);
                 }
             }
         }
     }
     callbacks.UpdateFixStatus(fixCount, language.FixDoubleGreaterThan, language.XFixDoubleGreaterThan);
 }
Ejemplo n.º 39
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            string fixAction      = Language.MergeShortLine;
            int    noOfShortLines = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p       = subtitle.Paragraphs[i];
                string    oldText = p.Text;
                var       text    = Helper.FixShortLines(p.Text, callbacks.Language);
                if (callbacks.AllowFix(p, fixAction) && oldText != text)
                {
                    p.Text = text;
                    noOfShortLines++;
                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(noOfShortLines, fixAction);
        }
Ejemplo n.º 40
0
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.MergeShortLine;
     int noOfShortLines = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = subtitle.Paragraphs[i];
         string oldText = p.Text;
         var text = Helper.FixShortLines(p.Text);
         if (callbacks.AllowFix(p, fixAction) && oldText != text)
         {
             p.Text = text;
             noOfShortLines++;
             callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
         }
     }
     callbacks.UpdateFixStatus(noOfShortLines, language.RemoveLineBreaks, string.Format(language.XLinesUnbreaked, noOfShortLines));
 }
Ejemplo n.º 41
0
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.FixDialogsOnOneLine;
     int noOfFixes = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = subtitle.Paragraphs[i];
         string oldText = p.Text;
         var text = Helper.FixDialogsOnOneLine(oldText, callbacks.Language);
         if (oldText != text && callbacks.AllowFix(p, fixAction))
         {
             p.Text = text;
             noOfFixes++;
             callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
         }
     }
     callbacks.UpdateFixStatus(noOfFixes, language.FixCommonOcrErrors, language.FixDialogsOneLineExample);
 }
Ejemplo n.º 42
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language  = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixDialogsOnOneLine;
            int    noOfFixes = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p       = subtitle.Paragraphs[i];
                string    oldText = p.Text;
                var       text    = Helper.FixDialogsOnOneLine(oldText, callbacks.Language);
                if (oldText != text && callbacks.AllowFix(p, fixAction))
                {
                    p.Text = text;
                    noOfFixes++;
                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(noOfFixes, language.FixCommonOcrErrors, language.FixDialogsOneLineExample);
        }
Ejemplo n.º 43
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language       = Configuration.Settings.Language.FixCommonErrors;
            string fixAction      = language.MergeShortLine;
            int    noOfShortLines = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p       = subtitle.Paragraphs[i];
                string    oldText = p.Text;
                var       text    = Helper.FixShortLines(p.Text, callbacks.Language);
                if (callbacks.AllowFix(p, fixAction) && oldText != text)
                {
                    p.Text = text;
                    noOfShortLines++;
                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(noOfShortLines, language.RemoveLineBreaks, string.Format(language.XLinesUnbreaked, noOfShortLines));
        }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            int noOfFixes = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, Language.RemoveSpaceBetweenNumber))
                {
                    var text = Utilities.RemoveSpaceBetweenNumbers(p.Text);
                    if (text != p.Text)
                    {
                        var oldText = p.Text;
                        p.Text = text;
                        noOfFixes++;
                        callbacks.AddFixToListView(p, Language.RemoveSpaceBetweenNumber, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(noOfFixes, Language.RemoveSpaceBetweenNumber);
        }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            int iFixes = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p = subtitle.Paragraphs[i];
                if (Helper.IsOneSentence(p.Text) && callbacks.AllowFix(p, Language.RemoveHyphensSingleLine))
                {
                    string oldText = p.Text;
                    string text    = Helper.FixHyphensRemoveForSingleLine(subtitle, p.Text, i);
                    if (text != oldText)
                    {
                        p.Text = text;
                        iFixes++;
                        callbacks.AddFixToListView(p, Language.RemoveHyphensSingleLine, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(iFixes, Language.RemoveHyphensSingleLine);
        }
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     var fixAction = language.RemoveSpaceBetweenNumber;
     int noOfFixes = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         var p = subtitle.Paragraphs[i];
         if (callbacks.AllowFix(p, fixAction))
         {
             var text = Utilities.RemoveSpaceBetweenNumbers(p.Text);
             if (text != p.Text)
             {
                 var oldText = p.Text;
                 p.Text = text;
                 noOfFixes++;
                 callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
             }
         }
     }
     callbacks.UpdateFixStatus(noOfFixes, language.FixCommonOcrErrors, string.Format(language.RemoveSpaceBetweenNumbersFixed, noOfFixes));
 }
Ejemplo n.º 47
0
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.FixHyphen;
     int iFixes = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         var p = subtitle.Paragraphs[i];
         if (callbacks.AllowFix(p, fixAction))
         {
             string oldText = p.Text;
             string text = Helper.FixHyphensRemove(subtitle, i);
             if (text != oldText)
             {
                 p.Text = text;
                 iFixes++;
                 callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
             }
         }
     }
     callbacks.UpdateFixStatus(iFixes, language.FixHyphens, language.XHyphensFixed);
 }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixFirstLetterToUppercaseAfterParagraph;
            int fixedStartWithUppercaseLetterAfterParagraphTicked = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);

                string oldText = p.Text;
                string fixedText = DoFix(new Paragraph(p), prev, callbacks.Encoding, callbacks.Language);

                if (oldText != fixedText && callbacks.AllowFix(p, fixAction))
                {
                    p.Text = fixedText;
                    fixedStartWithUppercaseLetterAfterParagraphTicked++;
                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(fixedStartWithUppercaseLetterAfterParagraphTicked, language.StartWithUppercaseLetterAfterParagraph, fixedStartWithUppercaseLetterAfterParagraphTicked.ToString(CultureInfo.InvariantCulture));
        }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixDoubleApostrophes;
            int fixCount = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];

                if (p.Text.Contains("''"))
                {
                    if (callbacks.AllowFix(p, fixAction))
                    {
                        string oldText = p.Text;
                        p.Text = p.Text.Replace("''", "\"");
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                        fixCount++;
                    }
                }
            }
            callbacks.UpdateFixStatus(fixCount, language.FixDoubleApostrophes, language.XDoubleApostrophesFixed);
        }
Ejemplo n.º 50
0
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.UnneededSpace;
     int doubleSpaces = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = subtitle.Paragraphs[i];
         if (callbacks.AllowFix(p, fixAction))
         {
             var oldText = p.Text;
             var text = Utilities.RemoveUnneededSpaces(p.Text, callbacks.Language);
             if (text.Length != oldText.Length && (Utilities.CountTagInText(text, ' ') + Utilities.CountTagInText(text, '\t') + Utilities.CountTagInText(text, Environment.NewLine)) < (Utilities.CountTagInText(oldText, ' ') + Utilities.CountTagInText(oldText, '\u00A0') + Utilities.CountTagInText(oldText, '\t') + Utilities.CountTagInText(oldText, Environment.NewLine)))
             {
                 doubleSpaces++;
                 p.Text = text;
                 callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
             }
         }
     }
     callbacks.UpdateFixStatus(doubleSpaces, language.RemoveUnneededSpaces, string.Format(language.XUnneededSpacesRemoved, doubleSpaces));
 }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixMissingOpenBracket;
            int fixCount = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p = subtitle.Paragraphs[i];

                if (callbacks.AllowFix(p, fixAction))
                {
                    var hit = false;
                    string oldText = p.Text;
                    var openIdx = p.Text.IndexOf('(');
                    var closeIdx = p.Text.IndexOf(')');
                    if (closeIdx >= 0 && (closeIdx < openIdx || openIdx < 0))
                    {
                        p.Text = Fix(p.Text, "(");
                        hit = true;
                    }

                    openIdx = p.Text.IndexOf('[');
                    closeIdx = p.Text.IndexOf(']');
                    if (closeIdx >= 0 && (closeIdx < openIdx || openIdx < 0))
                    {
                        p.Text = Fix(p.Text, "[");
                        hit = true;
                    }

                    if (hit)
                    {
                        fixCount++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(fixCount, language.FixMissingOpenBracket, language.XFixMissingOpenBracket);
        }
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.FixLowercaseIToUppercaseI;
     int iFixes = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = subtitle.Paragraphs[i];
         string oldText = p.Text;
         string s = p.Text;
         if (s.Contains('i'))
         {
             s = FixAloneLowercaseIToUppercaseLine(FixAloneLowercaseIToUppercaseIre, oldText, s, 'i');
             if (s != oldText && callbacks.AllowFix(p, fixAction))
             {
                 p.Text = s;
                 iFixes++;
                 callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
             }
         }
     }
     callbacks.UpdateFixStatus(iFixes, language.FixLowercaseIToUppercaseI, language.XIsChangedToUppercase);
 }
Ejemplo n.º 53
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.BreakLongLine;
            int noOfLongLines = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                var lines = p.Text.SplitToLines();
                bool tooLong = false;
                foreach (string line in lines)
                {
                    if (HtmlUtil.RemoveHtmlTags(line, true).Length > Configuration.Settings.General.SubtitleLineMaximumLength)
                    {
                        tooLong = true;
                        break;
                    }
                }
                if (callbacks.AllowFix(p, fixAction) && tooLong)
                {
                    string oldText = p.Text;
                    p.Text = Utilities.AutoBreakLine(p.Text, callbacks.Language);
                    if (oldText != p.Text)
                    {
                        noOfLongLines++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                    else
                    {
                        callbacks.LogStatus(fixAction, string.Format(language.UnableToFixTextXY, i + 1, p));
                        callbacks.AddToTotalErrors(1);
                    }
                }
            }

            callbacks.UpdateFixStatus(noOfLongLines, language.BreakLongLines, string.Format(language.XLineBreaksAdded, noOfLongLines));
        }
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.RemoveSpaceBetweenNumber;
     int noOfFixes = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = subtitle.Paragraphs[i];
         string text = p.Text;
         Match match = RemoveSpaceBetweenNumbersRegEx.Match(text);
         int counter = 0;
         while (match.Success && counter < 100 && text.Length > match.Index + 1)
         {
             string temp = text.Substring(match.Index + 2);
             if (temp != "1/2" &&
                 !temp.StartsWith("1/2 ", StringComparison.Ordinal) &&
                 !temp.StartsWith("1/2.", StringComparison.Ordinal) &&
                 !temp.StartsWith("1/2!", StringComparison.Ordinal) &&
                 !temp.StartsWith("1/2?", StringComparison.Ordinal) &&
                 !temp.StartsWith("1/2<", StringComparison.Ordinal))
             {
                 text = text.Remove(match.Index + 1, 1);
             }
             if (text.Length > match.Index + 1)
                 match = RemoveSpaceBetweenNumbersRegEx.Match(text, match.Index + 2);
             counter++;
         }
         if (callbacks.AllowFix(p, fixAction) && p.Text != text)
         {
             string oldText = p.Text;
             p.Text = text;
             noOfFixes++;
             callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
         }
     }
     callbacks.UpdateFixStatus(noOfFixes, language.FixCommonOcrErrors, string.Format(language.RemoveSpaceBetweenNumbersFixed, noOfFixes));
 }
Ejemplo n.º 55
0
 public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
 {
     var language = Configuration.Settings.Language.FixCommonErrors;
     string fixAction = language.UnneededPeriod;
     int removedCount = 0;
     for (int i = 0; i < subtitle.Paragraphs.Count; i++)
     {
         Paragraph p = subtitle.Paragraphs[i];
         if (callbacks.AllowFix(p, fixAction))
         {
             // Returns processed text.
             string procText = RemoveDotAfterPunctuation(p.Text);
             int diff = p.Text.Length - procText.Length;
             if (diff > 0)
             {
                 // Calculate total removed dots.
                 removedCount += diff;
                 callbacks.AddFixToListView(p, fixAction, p.Text, procText);
                 p.Text = procText;
             }
         }
     }
     callbacks.UpdateFixStatus(removedCount, language.RemoveUnneededPeriods, string.Format(language.XUnneededPeriodsRemoved, removedCount));
 }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixMissingPeriodAtEndOfLine;
            int missigPeriodsAtEndOfLine = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
                string nextText = string.Empty;
                if (next != null)
                {
                    nextText = HtmlUtil.RemoveHtmlTags(next.Text, true).TrimStart('-', '"', '„').TrimStart();
                }
                bool isNextClose = next != null && next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds < 400;
                string tempNoHtml = HtmlUtil.RemoveHtmlTags(p.Text).TrimEnd();

                if (IsOneLineUrl(p.Text) || p.Text.Contains(ExpectedChars) || p.Text.EndsWith('\''))
                {
                    // ignore urls
                }
                else if (!string.IsNullOrEmpty(nextText) && next != null &&
                    next.Text.Length > 0 &&
                    Utilities.UppercaseLetters.Contains(nextText[0]) &&
                    tempNoHtml.Length > 0 &&
                    !ExpectedString1.Contains(tempNoHtml[tempNoHtml.Length - 1]))
                {
                    string tempTrimmed = tempNoHtml.TrimEnd().TrimEnd('\'', '"', '“', '”').TrimEnd();
                    if (tempTrimmed.Length > 0 && !ExpectedString2.Contains(tempTrimmed[tempTrimmed.Length - 1]) && p.Text != p.Text.ToUpper())
                    {
                        //don't end the sentence if the next word is an I word as they're always capped.
                        bool isNextCloseAndStartsWithI = isNextClose && (nextText.StartsWith("I ", StringComparison.Ordinal) ||
                                                                         nextText.StartsWith("I'", StringComparison.Ordinal));

                        if (!isNextCloseAndStartsWithI)
                        {
                            //test to see if the first word of the next line is a name
                            if (!callbacks.IsName(next.Text.Split(WordSplitChars)[0]) && callbacks.AllowFix(p, fixAction))
                            {
                                string oldText = p.Text;
                                if (p.Text.EndsWith('>'))
                                {
                                    int lastLessThan = p.Text.LastIndexOf('<');
                                    if (lastLessThan > 0)
                                        p.Text = p.Text.Insert(lastLessThan, ".");
                                }
                                else
                                {
                                    if (p.Text.EndsWith('“') && tempNoHtml.StartsWith('„'))
                                        p.Text = p.Text.TrimEnd('“') + ".“";
                                    else if (p.Text.EndsWith('"') && tempNoHtml.StartsWith('"'))
                                        p.Text = p.Text.TrimEnd('"') + ".\"";
                                    else
                                        p.Text += ".";
                                }
                                if (p.Text != oldText)
                                {
                                    missigPeriodsAtEndOfLine++;
                                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                                }
                            }
                        }
                    }
                }
                else if (next != null && !string.IsNullOrEmpty(p.Text) && Utilities.AllLettersAndNumbers.Contains(p.Text[p.Text.Length - 1]))
                {
                    if (p.Text != p.Text.ToUpper())
                    {
                        var st = new StripableText(next.Text);
                        if (st.StrippedText.Length > 0 && st.StrippedText != st.StrippedText.ToUpper() &&
                            Utilities.UppercaseLetters.Contains(st.StrippedText[0]))
                        {
                            if (callbacks.AllowFix(p, fixAction))
                            {
                                int j = p.Text.Length - 1;
                                while (j >= 0 && !@".!?¿¡".Contains(p.Text[j]))
                                    j--;
                                string endSign = ".";
                                if (j >= 0 && p.Text[j] == '¿')
                                    endSign = "?";
                                if (j >= 0 && p.Text[j] == '¡')
                                    endSign = "!";

                                string oldText = p.Text;
                                missigPeriodsAtEndOfLine++;
                                p.Text += endSign;
                                callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                            }
                        }
                    }
                }

                if (p.Text.Length > 4)
                {
                    int indexOfNewLine = p.Text.IndexOf(Environment.NewLine + " -", 3, StringComparison.Ordinal);
                    if (indexOfNewLine < 0)
                        indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "-", 3, StringComparison.Ordinal);
                    if (indexOfNewLine < 0)
                        indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "<i>-", 3, StringComparison.Ordinal);
                    if (indexOfNewLine < 0)
                        indexOfNewLine = p.Text.IndexOf(Environment.NewLine + "<i> -", 3, StringComparison.Ordinal);
                    if (indexOfNewLine > 0 && Configuration.Settings.General.UppercaseLetters.Contains(char.ToUpper(p.Text[indexOfNewLine - 1])) && callbacks.AllowFix(p, fixAction))
                    {
                        string oldText = p.Text;

                        string text = p.Text.Substring(0, indexOfNewLine);
                        var st = new StripableText(text);
                        if (st.Pre.TrimEnd().EndsWith('¿')) // Spanish ¿
                            p.Text = p.Text.Insert(indexOfNewLine, "?");
                        else if (st.Pre.TrimEnd().EndsWith('¡')) // Spanish ¡
                            p.Text = p.Text.Insert(indexOfNewLine, "!");
                        else
                            p.Text = p.Text.Insert(indexOfNewLine, ".");

                        missigPeriodsAtEndOfLine++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(missigPeriodsAtEndOfLine, language.AddPeriods, language.XPeriodsAdded);
        }
Ejemplo n.º 57
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            _callbacks = callbacks;

            string fixAction = language.FixShortDisplayTime;
            int noOfShortDisplayTimes = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                var skip = p.StartTime.IsMaxTime || p.EndTime.IsMaxTime;
                double displayTime = p.Duration.TotalMilliseconds;
                if (!skip && displayTime < Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds)
                {
                    Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
                    Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);
                    if (next == null || (p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines) < next.StartTime.TotalMilliseconds)
                    {
                        var temp = new Paragraph(p) { EndTime = { TotalMilliseconds = p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds } };
                        if (Utilities.GetCharactersPerSecond(temp) <= Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
                        {
                            if (callbacks.AllowFix(p, fixAction))
                            {
                                string oldCurrent = p.ToString();
                                p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds;
                                noOfShortDisplayTimes++;
                                callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                            }
                        }
                    }
                    else if (Configuration.Settings.Tools.FixShortDisplayTimesAllowMoveStartTime && p.StartTime.TotalMilliseconds > Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds &&
                             (prev == null || prev.EndTime.TotalMilliseconds < p.EndTime.TotalMilliseconds - Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines))
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            string oldCurrent = p.ToString();
                            if (next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines > p.EndTime.TotalMilliseconds)
                                p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
                            p.StartTime.TotalMilliseconds = p.EndTime.TotalMilliseconds - Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds;
                            noOfShortDisplayTimes++;
                            callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                        }
                    }
                    else
                    {
                        callbacks.LogStatus(language.FixShortDisplayTimes, string.Format(language.UnableToFixTextXY, i + 1, p));
                        callbacks.AddToTotalErrors(1);
                        skip = true;
                    }
                }

                double charactersPerSecond = Utilities.GetCharactersPerSecond(p);
                if (!skip && charactersPerSecond > Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
                {
                    var temp = new Paragraph(p);
                    while (Utilities.GetCharactersPerSecond(temp) > Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
                    {
                        temp.EndTime.TotalMilliseconds++;
                    }
                    Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
                    Paragraph nextNext = subtitle.GetParagraphOrDefault(i + 2);
                    Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);
                    double diffMs = temp.Duration.TotalMilliseconds - p.Duration.TotalMilliseconds;

                    // Normal - just make current subtitle duration longer
                    if (next == null || temp.EndTime.TotalMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines < next.StartTime.TotalMilliseconds)
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            string oldCurrent = p.ToString();
                            p.EndTime.TotalMilliseconds = temp.EndTime.TotalMilliseconds;
                            noOfShortDisplayTimes++;
                            callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                        }
                    }
                    // Start current subtitle earlier (max 50 ms)
                    else if (Configuration.Settings.Tools.FixShortDisplayTimesAllowMoveStartTime && p.StartTime.TotalMilliseconds > Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds &&
                             diffMs < 50 && (prev == null || prev.EndTime.TotalMilliseconds < p.EndTime.TotalMilliseconds - temp.Duration.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines))
                    {
                        noOfShortDisplayTimes = MoveStartTime(fixAction, noOfShortDisplayTimes, p, temp, next);
                    }
                    // Make current subtitle duration longer + move next subtitle
                    else if (diffMs < 1000 &&
                             Configuration.Settings.Tools.FixShortDisplayTimesAllowMoveStartTime &&
                             p.StartTime.TotalMilliseconds > Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds &&
                             (nextNext == null || next.EndTime.TotalMilliseconds + diffMs + Configuration.Settings.General.MinimumMillisecondsBetweenLines * 2 < nextNext.StartTime.TotalMilliseconds))
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            string oldCurrent = p.ToString();
                            p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + temp.Duration.TotalMilliseconds;
                            var nextDurationMs = next.Duration.TotalMilliseconds;
                            next.StartTime.TotalMilliseconds = p.EndTime.TotalMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines;
                            next.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds + nextDurationMs;
                            noOfShortDisplayTimes++;
                            callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                        }
                    }
                    // Make next subtitle duration shorter + make current subtitle duration longer
                    else if (diffMs < 1000 &&
                             Configuration.Settings.Tools.FixShortDisplayTimesAllowMoveStartTime && Utilities.GetCharactersPerSecond(new Paragraph(next.Text, p.StartTime.TotalMilliseconds + temp.Duration.TotalMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines, next.EndTime.TotalMilliseconds)) < Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            string oldCurrent = p.ToString();
                            next.StartTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + temp.Duration.TotalMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines;
                            p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
                            noOfShortDisplayTimes++;
                            callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                        }
                    }
                    // Make next-next subtitle duration shorter + move next + make current subtitle duration longer
                    else if (diffMs < 500 &&
                             Configuration.Settings.Tools.FixShortDisplayTimesAllowMoveStartTime && nextNext != null &&
                             Utilities.GetCharactersPerSecond(new Paragraph(nextNext.Text, nextNext.StartTime.TotalMilliseconds + diffMs + Configuration.Settings.General.MinimumMillisecondsBetweenLines, nextNext.EndTime.TotalMilliseconds - (diffMs))) < Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            string oldCurrent = p.ToString();
                            p.EndTime.TotalMilliseconds += diffMs;
                            next.StartTime.TotalMilliseconds += diffMs;
                            next.EndTime.TotalMilliseconds += diffMs;
                            nextNext.StartTime.TotalMilliseconds += diffMs;
                            noOfShortDisplayTimes++;
                            callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                        }
                    }
                    // Start current subtitle earlier (max 200 ms)
                    else if (Configuration.Settings.Tools.FixShortDisplayTimesAllowMoveStartTime && p.StartTime.TotalMilliseconds > Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds &&
                             diffMs < 200 && (prev == null || prev.EndTime.TotalMilliseconds < p.EndTime.TotalMilliseconds - temp.Duration.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines))
                    {
                        noOfShortDisplayTimes = MoveStartTime(fixAction, noOfShortDisplayTimes, p, temp, next);
                    }
                    else
                    {
                        // move some... though not enough
                        var improvedEndtime = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
                        if (improvedEndtime > p.EndTime.TotalMilliseconds)
                        {
                            if (callbacks.AllowFix(p, fixAction))
                            {
                                string oldCurrent = p.ToString();
                                p.EndTime.TotalMilliseconds = improvedEndtime;
                                noOfShortDisplayTimes++;
                                callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                            }
                        }

                        callbacks.LogStatus(language.FixShortDisplayTimes, string.Format(language.UnableToFixTextXY, i + 1, p));
                        callbacks.AddToTotalErrors(1);
                    }
                }
            }
            callbacks.UpdateFixStatus(noOfShortDisplayTimes, fixAction, string.Format(language.XDisplayTimesProlonged, noOfShortDisplayTimes));
        }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;

            // negative display time
            string fixAction = language.FixOverlappingDisplayTime;
            int noOfOverlappingDisplayTimesFixed = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p = subtitle.Paragraphs[i];
                var oldP = new Paragraph(p);
                if (p.Duration.TotalMilliseconds < 0) // negative display time...
                {
                    bool isFixed = false;
                    string status = string.Format(language.StartTimeLaterThanEndTime,
                                                    i + 1, p.StartTime, p.EndTime, p.Text, Environment.NewLine);

                    var prev = subtitle.GetParagraphOrDefault(i - 1);
                    var next = subtitle.GetParagraphOrDefault(i + 1);

                    double wantedDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text) * 0.9;

                    if (next == null || next.StartTime.TotalMilliseconds > p.StartTime.TotalMilliseconds + wantedDisplayTime)
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + wantedDisplayTime;
                            isFixed = true;
                        }
                    }
                    else if (next.StartTime.TotalMilliseconds > p.StartTime.TotalMilliseconds + 500.0)
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + 500.0;
                            isFixed = true;
                        }
                    }
                    else if (prev == null || next.StartTime.TotalMilliseconds - wantedDisplayTime > prev.EndTime.TotalMilliseconds)
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            p.StartTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - wantedDisplayTime;
                            p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                            isFixed = true;
                        }
                    }
                    else
                    {
                        callbacks.LogStatus(language.FixOverlappingDisplayTimes, string.Format(language.UnableToFixStartTimeLaterThanEndTime, i + 1, p), true);
                        callbacks.AddToTotalErrors(1);
                    }

                    if (isFixed)
                    {
                        noOfOverlappingDisplayTimesFixed++;
                        status = string.Format(language.XFixedToYZ, status, Environment.NewLine, p);
                        callbacks.LogStatus(language.FixOverlappingDisplayTimes, status);
                        callbacks.AddFixToListView(p, fixAction, oldP.ToString(), p.ToString());
                    }
                }
            }

            // overlapping display time
            for (int i = 1; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);
                Paragraph target = prev;
                string oldCurrent = p.ToString();
                string oldPrevious = prev.ToString();
                double prevWantedDisplayTime = Utilities.GetOptimalDisplayMilliseconds(prev.Text, Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds);
                double currentWantedDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text, Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds);
                double prevOptimalDisplayTime = Utilities.GetOptimalDisplayMilliseconds(prev.Text);
                double currentOptimalDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text);
                bool canBeEqual = callbacks.Format != null && callbacks.Format.GetType() == typeof(AdvancedSubStationAlpha) || callbacks.Format.GetType() == typeof(SubStationAlpha);
                if (!canBeEqual)
                    canBeEqual = Configuration.Settings.Tools.FixCommonErrorsFixOverlapAllowEqualEndStart;

                double diff = prev.EndTime.TotalMilliseconds - p.StartTime.TotalMilliseconds;
                if (!prev.StartTime.IsMaxTime && !p.StartTime.IsMaxTime && diff >= 0 && !(canBeEqual && Math.Abs(diff) < 0.001))
                {
                    int diffHalf = (int)(diff / 2);
                    if (!Configuration.Settings.Tools.FixCommonErrorsFixOverlapAllowEqualEndStart && Math.Abs(p.StartTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds) < 0.001 &&
                        prev.Duration.TotalMilliseconds > 100)
                    {
                        if (callbacks.AllowFix(target, fixAction))
                        {
                            if (!canBeEqual)
                            {
                                bool okEqual = true;
                                if (prev.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds)
                                    prev.EndTime.TotalMilliseconds--;
                                else if (p.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds)
                                    p.StartTime.TotalMilliseconds++;
                                else
                                    okEqual = false;
                                if (okEqual)
                                {
                                    noOfOverlappingDisplayTimesFixed++;
                                    callbacks.AddFixToListView(target, fixAction, oldPrevious, prev.ToString());
                                }
                            }
                        }
                        //prev.EndTime.TotalMilliseconds--;
                    }
                    else if (prevOptimalDisplayTime <= (p.StartTime.TotalMilliseconds - prev.StartTime.TotalMilliseconds))
                    {
                        if (callbacks.AllowFix(target, fixAction))
                        {
                            prev.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds - 1;
                            if (canBeEqual)
                                prev.EndTime.TotalMilliseconds++;
                            noOfOverlappingDisplayTimesFixed++;
                            callbacks.AddFixToListView(target, fixAction, oldPrevious, prev.ToString());
                        }
                    }
                    else if (diff > 0 && currentOptimalDisplayTime <= p.Duration.TotalMilliseconds - diffHalf &&
                             prevOptimalDisplayTime <= prev.Duration.TotalMilliseconds - diffHalf)
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            prev.EndTime.TotalMilliseconds -= diffHalf;
                            p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + 1;
                            noOfOverlappingDisplayTimesFixed++;
                            callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                        }
                    }
                    else if (currentOptimalDisplayTime <= p.EndTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds)
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + 1;
                            if (canBeEqual)
                                p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds;
                            noOfOverlappingDisplayTimesFixed++;
                            callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                        }
                    }
                    else if (diff > 0 && currentWantedDisplayTime <= p.Duration.TotalMilliseconds - diffHalf &&
                             prevWantedDisplayTime <= prev.Duration.TotalMilliseconds - diffHalf)
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            prev.EndTime.TotalMilliseconds -= diffHalf;
                            p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + 1;
                            noOfOverlappingDisplayTimesFixed++;
                            callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                        }
                    }
                    else if (prevWantedDisplayTime <= (p.StartTime.TotalMilliseconds - prev.StartTime.TotalMilliseconds))
                    {
                        if (callbacks.AllowFix(target, fixAction))
                        {
                            prev.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds - 1;
                            if (canBeEqual)
                                prev.EndTime.TotalMilliseconds++;
                            noOfOverlappingDisplayTimesFixed++;
                            callbacks.AddFixToListView(target, fixAction, oldPrevious, prev.ToString());
                        }
                    }
                    else if (currentWantedDisplayTime <= p.EndTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds)
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + 1;
                            if (canBeEqual)
                                p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds;
                            noOfOverlappingDisplayTimesFixed++;
                            callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                        }
                    }
                    else if (Math.Abs(p.StartTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds) < 10 && p.Duration.TotalMilliseconds > 1)
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            prev.EndTime.TotalMilliseconds -= 2;
                            p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + 1;
                            if (canBeEqual)
                                p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds;
                            noOfOverlappingDisplayTimesFixed++;
                            callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
                        }
                    }
                    else if (Math.Abs(p.StartTime.TotalMilliseconds - prev.StartTime.TotalMilliseconds) < 10 && Math.Abs(p.EndTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds) < 10)
                    { // merge lines with same time codes
                        if (callbacks.AllowFix(target, fixAction))
                        {
                            prev.Text = prev.Text.Replace(Environment.NewLine, " ");
                            p.Text = p.Text.Replace(Environment.NewLine, " ");

                            string stripped = HtmlUtil.RemoveHtmlTags(prev.Text).TrimStart();
                            if (!stripped.StartsWith("- ", StringComparison.Ordinal))
                                prev.Text = "- " + prev.Text.TrimStart();

                            stripped = HtmlUtil.RemoveHtmlTags(p.Text).TrimStart();
                            if (!stripped.StartsWith("- ", StringComparison.Ordinal))
                                p.Text = "- " + p.Text.TrimStart();

                            prev.Text = prev.Text.Trim() + Environment.NewLine + p.Text;
                            p.Text = string.Empty;
                            noOfOverlappingDisplayTimesFixed++;
                            callbacks.AddFixToListView(target, fixAction, oldCurrent, p.ToString());

                            p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + 1;
                            p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + 1;
                            if (canBeEqual)
                            {
                                p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds;
                                p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds;
                            }
                        }
                    }
                    else
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            callbacks.LogStatus(language.FixOverlappingDisplayTimes, string.Format(language.UnableToFixTextXY, i + 1, Environment.NewLine + prev.Number + "  " + prev + Environment.NewLine + p.Number + "  " + p), true);
                            callbacks.AddToTotalErrors(1);
                        }
                    }
                }
            }

            callbacks.UpdateFixStatus(noOfOverlappingDisplayTimesFixed, fixAction, string.Format(language.XOverlappingTimestampsFixed, noOfOverlappingDisplayTimesFixed));
        }
Ejemplo n.º 59
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;

            string fixAction0 = language.RemovedEmptyLine;
            string fixAction1 = language.RemovedEmptyLineAtTop;
            string fixAction2 = language.RemovedEmptyLineAtBottom;

            if (subtitle.Paragraphs.Count == 0)
                return;

            int emptyLinesRemoved = 0;

            for (int i = subtitle.Paragraphs.Count - 1; i >= 0; i--)
            {
                Paragraph p = subtitle.Paragraphs[i];
                if (!string.IsNullOrEmpty(p.Text))
                {
                    string text = p.Text.Trim(' ');
                    var oldText = text;
                    var pre = string.Empty;
                    var post = string.Empty;

                    // Ssa Tags
                    if (text.StartsWith("{\\", StringComparison.Ordinal))
                    {
                        var endIDx = text.IndexOf('}', 2);
                        if (endIDx > 2)
                        {
                            pre = text.Substring(0, endIDx + 1);
                            text = text.Remove(0, endIDx + 1);
                        }
                    }

                    while (text.LineStartsWithHtmlTag(true, true))
                    {
                        // Three length tag
                        if (text[2] == '>')
                        {
                            pre += text.Substring(0, 3);
                            text = text.Remove(0, 3);
                        }
                        else // <font ...>
                        {
                            var closeIdx = text.IndexOf('>');
                            if (closeIdx <= 2)
                                break;

                            pre += text.Substring(0, closeIdx + 1);
                            text = text.Remove(0, closeIdx + 1);
                        }
                    }
                    while (text.LineEndsWithHtmlTag(true, true))
                    {
                        var len = text.Length;

                        // Three length tag
                        if (text[len - 4] == '<')
                        {
                            post = text.Substring(text.Length - 4) + post;
                            text = text.Remove(text.Length - 4);
                        }
                        else // </font>
                        {
                            post = text.Substring(text.Length - 7) + post;
                            text = text.Remove(text.Length - 7);
                        }
                    }

                    if (callbacks.AllowFix(p, fixAction1) && text.StartsWith(Environment.NewLine, StringComparison.Ordinal))
                    {
                        if (pre.Length > 0)
                            text = pre + text.TrimStart(Utilities.NewLineChars);
                        else
                            text = text.TrimStart(Utilities.NewLineChars);
                        p.Text = text;
                        emptyLinesRemoved++;
                        callbacks.AddFixToListView(p, fixAction1, oldText, p.Text);
                    }
                    else
                    {
                        text = pre + text;
                    }

                    if (callbacks.AllowFix(p, fixAction2) && text.EndsWith(Environment.NewLine, StringComparison.Ordinal))
                    {
                        if (post.Length > 0)
                            text = text.TrimEnd(Utilities.NewLineChars) + post;
                        else
                            text = text.TrimEnd(Utilities.NewLineChars);
                        p.Text = text;
                        emptyLinesRemoved++;
                        callbacks.AddFixToListView(p, fixAction2, oldText, p.Text);
                    }
                }
            }

            // this must be the very last action done, or line numbers will be messed up!!!
            for (int i = subtitle.Paragraphs.Count - 1; i >= 0; i--)
            {
                Paragraph p = subtitle.Paragraphs[i];
                var text = HtmlUtil.RemoveHtmlTags(p.Text, true).Trim();
                if (callbacks.AllowFix(p, fixAction0) && string.IsNullOrEmpty(text))
                {
                    subtitle.Paragraphs.RemoveAt(i);
                    emptyLinesRemoved++;
                    callbacks.AddFixToListView(p, fixAction0, p.Text, string.Format("[{0}]", language.RemovedEmptyLine));
                    callbacks.AddToDeleteIndices(i);
                }
            }

            if (emptyLinesRemoved > 0)
            {
                callbacks.UpdateFixStatus(emptyLinesRemoved, language.RemovedEmptyLinesUnsedLineBreaks, string.Format(language.EmptyLinesRemovedX, emptyLinesRemoved));
                subtitle.Renumber();
            }
        }
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var language = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.StartWithUppercaseLetterAfterPeriodInsideParagraph;
            int noOfFixes = 0;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                string oldText = p.Text;
                var st = new StripableText(p.Text);
                if (p.Text.Length > 3)
                {
                    string text = st.StrippedText.Replace("  ", " ");
                    int start = text.IndexOfAny(ExpectedChars);
                    while (start >= 0 && start < text.Length)
                    {
                        if (start > 0 && char.IsDigit(text[start - 1]))
                        {
                            // ignore periods after a number
                        }
                        else if (start + 4 < text.Length && text[start + 1] == ' ')
                        {
                            if (!IsAbbreviation(text, start, callbacks))
                            {
                                var subText = new StripableText(text.Substring(start + 2));
                                if (subText.StrippedText.Length > 0 && Helper.IsTurkishLittleI(subText.StrippedText[0], callbacks.Encoding, callbacks.Language))
                                {
                                    if (subText.StrippedText.Length > 1 && !(subText.Pre.Contains('\'') && subText.StrippedText.StartsWith('s')))
                                    {
                                        text = text.Substring(0, start + 2) + subText.Pre + Helper.GetTurkishUppercaseLetter(subText.StrippedText[0], callbacks.Encoding) + subText.StrippedText.Substring(1) + subText.Post;
                                        if (callbacks.AllowFix(p, fixAction))
                                        {
                                            p.Text = st.Pre + text + st.Post;
                                        }
                                    }
                                }
                                else if (subText.StrippedText.Length > 0 && Configuration.Settings.General.UppercaseLetters.Contains(char.ToUpper(subText.StrippedText[0])))
                                {
                                    if (subText.StrippedText.Length > 1 && !(subText.Pre.Contains('\'') && subText.StrippedText.StartsWith('s')))
                                    {
                                        text = text.Substring(0, start + 2) + subText.Pre + char.ToUpper(subText.StrippedText[0]) + subText.StrippedText.Substring(1) + subText.Post;
                                        if (callbacks.AllowFix(p, fixAction))
                                        {
                                            p.Text = st.Pre + text + st.Post;
                                        }
                                    }
                                }
                            }
                        }
                        start += 4;
                        if (start < text.Length)
                            start = text.IndexOfAny(ExpectedChars, start);
                    }
                }

                if (oldText != p.Text)
                {
                    noOfFixes++;
                    callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                }
            }
            callbacks.UpdateFixStatus(noOfFixes, language.StartWithUppercaseLetterAfterPeriodInsideParagraph, noOfFixes.ToString(CultureInfo.InvariantCulture));
        }