Exemple #1
0
        private bool AnalyzeText(string text)
        {
            if (text.Replace(Environment.NewLine, string.Empty).Length == text.Length)
            {
                return(false);
            }

            var s = HtmlUtils.RemoveTags(text);

            if (s.StartsWith("-") && s.Contains(Environment.NewLine + "-"))
            {
                return(false);
            }
            int index = text.IndexOf(Environment.NewLine);

            if (index > 0)
            {
                string firstLine  = text.Substring(0, index).Trim();
                string secondLine = text.Substring(index).Trim();
                firstLine  = HtmlUtils.RemoveTags(firstLine).Trim();
                secondLine = HtmlUtils.RemoveTags(secondLine).Trim();
                if (!firstLine.Contains(".") && !firstLine.Contains("!") && !firstLine.Contains("?"))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #2
0
        private static bool IsQualifiedNarrator(string line, int colonIdx)
        {
            string noTagCapturedText = HtmlUtils.RemoveTags(line.Substring(0, colonIdx + 1), true);

            if (string.IsNullOrWhiteSpace(noTagCapturedText))
            {
                return(false);
            }
            // e.g: 12:30am...
            if ((colonIdx + 1 < line.Length) && char.IsDigit(line[colonIdx + 1]))
            {
                return(false);
            }

            // Foobar[?!] Narrator: Hello (Note: not really sure if "." (dot) should be include since there are names
            // that are prefixed with Mr. Ivandro Ismael)
            if (noTagCapturedText.ContainsAny(new[] { '!', '?' }))
            {
                return(false);
            }

            if (noTagCapturedText.StartsWith("http", StringComparison.OrdinalIgnoreCase) ||
                noTagCapturedText.EndsWith("improved by", StringComparison.OrdinalIgnoreCase) ||
                noTagCapturedText.EndsWith("corrected by", StringComparison.OrdinalIgnoreCase) ||
                noTagCapturedText.EndsWith("https", StringComparison.OrdinalIgnoreCase) ||
                noTagCapturedText.EndsWith("http", StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }
            return(true);
        }
        public void Action()
        {
            foreach (var p in _paragraphs)
            {
                if (p.NumberOfLines == 1)
                {
                    continue;
                }

                var oldText = p.Text;
                var text    = UnbreakLines(p.Text);

                // only unbreak if text length <= MaxLineLenth
                if (HtmlUtils.RemoveTags(text, true).Length > _configs.MaxLineLength)
                {
                    continue;
                }

                if (text.Length != oldText.Length)
                {
                    //TODO: oldText = Utilities.RemoveHtmlTags(oldText, true);
                    OnTextUnbreaked(p, text);
                }
            }
        }
Exemple #4
0
        public string NarratorToUppercase(string text)
        {
            string noTagText = HtmlUtils.RemoveTags(text, true).TrimEnd().TrimEnd('"');

            if (noTagText.StartsWith("http", StringComparison.OrdinalIgnoreCase))
            {
                return(text);
            }

            // Skip single line that ends with ':'.
            int index = noTagText.IndexOf(':');

            if (index < 0)
            {
                return(text);
            }

            // Lena:
            // A ring?!
            int newLineIdx = noTagText.IndexOf(Environment.NewLine, StringComparison.Ordinal);

            if (!Config.SingleLineNarrator && index + 1 == newLineIdx)
            {
                return(text);
            }

            string[] lines = text.SplitToLines();
            for (int i = 0; i < lines.Length; i++)
            {
                string line      = lines[i];
                string noTagLine = HtmlUtils.RemoveTags(line, true);

                int colonIdx = noTagLine.IndexOf(':');
                if (colonIdx < 1)
                {
                    continue;
                }
                // Only allow colon at last position if it's 1st line.
                if (colonIdx + 1 == noTagLine.Length)
                {
                    continue;
                }

                if (IsQualifiedNarrator(noTagLine, colonIdx))
                {
                    // Find index from original text.
                    colonIdx = line.IndexOf(':') + 1;
                    string preText = line.Substring(0, colonIdx);
                    preText  = Customize(preText);
                    lines[i] = preText + line.Substring(colonIdx);
                }
            }
            return(string.Join(Environment.NewLine, lines));
        }
Exemple #5
0
        private void AddToListView(Paragraph paragraph, string newText)
        {
            var item = new ListViewItem(paragraph.Number.ToString())
            {
                UseItemStyleForSubItems = true
            };

            item.SubItems.Add(paragraph.Text.Length.ToString());
            item.SubItems.Add(HtmlUtils.RemoveTags(paragraph.Text, true).Replace(Environment.NewLine, Options.UILineBreak));
            item.SubItems.Add(HtmlUtils.RemoveTags(newText, true).Replace(Environment.NewLine, Options.UILineBreak));
            listView1.Items.Add(item);
        }
Exemple #6
0
        private bool IsThereText()
        {
            string text = textBox1.Text.Trim();

            if (!string.IsNullOrEmpty(text))
            {
                text = HtmlUtils.RemoveTags(text);
                if (text.Length > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #7
0
 private void buttonUnBreak_Click(object sender, EventArgs e)
 {
     if (IsThereText())
     {
         string text = HtmlUtils.RemoveTags(textBox1.Text).Trim();
         if (text.Length > 0 && text.Length < 47)
         {
             textBox1.Text = textBox1.Text.Replace(Environment.NewLine, " ");
         }
         else
         {
             MessageBox.Show("You are trying to unbreak line > 46 chars");
         }
     }
 }
Exemple #8
0
 public static string GetListViewString(string text, bool noTag)
 {
     if (string.IsNullOrEmpty(text))
     {
         return(string.Empty);
     }
     if (text.Length < 2)
     {
         return(text);
     }
     if (noTag)
     {
         text = HtmlUtils.RemoveTags(text, true);
     }
     return(text.Replace(Environment.NewLine, Options.UILineBreak));
 }
Exemple #9
0
        private string ProcessText(string text)
        {
            char[]   trimChars = { '"', '\\' };
            string[] lines     = text.SplitToLines();
            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];

                //TODO: if text contains 2 hearing text
                string lineNoTags = HtmlUtils.RemoveTags(line, true).TrimEnd(trimChars).TrimEnd();

                if (!ShouldApplyColor(lineNoTags, isFirstLine: i == 0))
                {
                    continue;
                }

                //- MAN: Baby, I put it right over there.
                //- JUNE: No, you did not.
                int colonIdx = line.IndexOf(':');

                string preText = line.Substring(0, colonIdx);

                string firstChr = _regexFirtCharNotTag.Match(preText).Value;
                if (string.IsNullOrEmpty(firstChr))
                {
                    continue;
                }

                int idxFirstChar = preText.IndexOf(firstChr, StringComparison.Ordinal);

                // get only text that should be colored
                string narrator = preText.Substring(idxFirstChar, colonIdx - idxFirstChar).Trim();
                narrator = ApplyColor(_palette.Color, narrator);

                preText = preText.Remove(idxFirstChar, colonIdx - idxFirstChar);
                preText = preText.Insert(idxFirstChar, narrator);

                line = line.Remove(0, colonIdx);
                line = line.Insert(0, preText);

                lines[i] = line;
            }
            // re-construct text
            return(string.Join(Environment.NewLine, lines));
        }
Exemple #10
0
        private string AddHyphenOnBothLine(string text)
        {
            if (!text.Contains(Environment.NewLine) || StringUtils.CountTagInText(text, ':') < 1)
            {
                return(text);
            }

            var  noTagText  = HtmlUtils.RemoveTags(text);
            bool addHyphen  = false;
            var  noTagLines = noTagText.SplitToLines();

            for (int i = 0; i < noTagLines.Length; i++)
            {
                var line    = noTagLines[i];
                var preLine = i - 1 < 0 ? null : noTagLines[i - 1];
                var idx     = line.IndexOf(':');
                // (John): Day's getting on.
                // We got work to do.
                addHyphen = ((idx >= 0 && !StringUtils.IsBetweenNumbers(line, idx)) && (preLine == null || EndLineChars.IndexOf(preLine[preLine.Length - 1]) >= 0)) ? true : false;
            }

            /*
             * foreach (var noTagLine in noTagText.Replace("\r\n", "\n").Split('\n'))
             * {
             *  if (noTagLine.Length == 0)
             *      return text;
             *  var idx = noTagLine.IndexOf(':');
             *  addHyphen = (idx >= 0 && !Utilities.IsBetweenNumbers(noTagLine, idx)) && (endLineChars.IndexOf(noTagLine[noTagLine.Length - 1]) >= 0) ? true : false;
             * }*/
            if (addHyphen && (noTagLines[0].Length > 2 && noTagLines[1].Length > 2))
            {
                if (noTagLines[0][0] != '-')
                {
                    text = "- " + text;
                }

                if (noTagLines[1][0] != '-')
                {
                    text = text.Insert(text.IndexOf(Environment.NewLine) + 2, "- ");
                }
            }
            return(text);
        }
Exemple #11
0
        public string MoodsToUppercase(string text)
        {
            // <font color="#ff00ff">(SIGHS)</font>
            // Remove invalid tags.
            text = text.Replace("()", string.Empty);
            text = text.Replace("()", string.Empty);
            text = text.Replace("( )", string.Empty);
            text = text.Replace("[ ]", string.Empty);

            if (!IsQualifedMoods(text))
            {
                return(text);
            }

            int  idx       = text.IndexOfAny(HIChars);
            char openChar  = text[idx];
            char closeChar = openChar == '(' ? ')' : ']';

            do
            {
                int endIdx = text.IndexOf(closeChar, idx + 1); // ] or )
                // There most be at lease one chars inside brackets.
                if (endIdx < idx + 2)
                {
                    break;
                }
                string parensText = text.Substring(idx, endIdx - idx + 1);
                // remove parents with empty text
                string noTagTextInsideParens = HtmlUtils.RemoveTags(parensText, true);
                text = text.Remove(idx, parensText.Length);
                if (string.IsNullOrWhiteSpace(noTagTextInsideParens))
                {
                    idx = text.IndexOf(openChar, idx);
                }
                else
                {
                    text = text.Insert(idx, Customize(parensText));
                    idx  = text.IndexOf(openChar, endIdx + 1); // ( or [
                }
            }while (idx >= 0);

            return(text);
        }
Exemple #12
0
        private void buttonClear_Click(object sender, EventArgs e)
        {
            string text = textBox1.Text;

            if (!string.IsNullOrEmpty(text))
            {
                text = HtmlUtils.RemoveTags(text).Trim();

                if (text.Length > 2)
                {
                    text = Regex.Replace(text, @"\B-\B", string.Empty).Trim();

                    while (text.Contains(Environment.NewLine + " "))
                    {
                        text = text.Replace(Environment.NewLine + " ", Environment.NewLine);
                    }
                    textBox1.Text = text.Trim();
                }
            }
        }
Exemple #13
0
 private void buttonLower_Click(object sender, EventArgs e)
 {
     if (IsThereText())
     {
         string selected = textBox1.SelectedText;
         if (!string.IsNullOrEmpty(selected))
         {
             textBox1.Text = textBox1.Text.Replace(selected, selected.ToLower());
         }
         else
         {
             string text = textBox1.Text.Trim();
             if (HtmlUtils.RemoveTags(text).Length > 0)
             {
                 textBox1.Text = text.ToLower();
             }
         }
     }
     // TODO: fix tag chasing before proceed
 }
        private string UnbreakLines(string s)
        {
            var temp = HtmlUtils.RemoveTags(s, true);

            temp = temp.Replace("  ", " ").Trim();

            if (_configs.SkipDialogs && (temp.StartsWith('-') || temp.Contains(Environment.NewLine + "-")))
            {
                return(s);
            }
            if (_configs.SkipMoods && temp.IndexOfAny(_moodChars) >= 0)
            {
                return(s);
            }
            if (_configs.SkipNarrator && _regexNarrator.IsMatch(temp))
            {
                return(s);
            }

            return(StringUtils.UnbreakLine(s));
        }
Exemple #15
0
        private void AddToListView(ParagraphEventArgs prgEventArgs)
        {
            string noTagOldText = HtmlUtils.RemoveTags(prgEventArgs.Paragraph.Text);

            // length of only visilbe characters
            int lineLength = noTagOldText.Length - (StringUtils.CountTagInText(noTagOldText, Environment.NewLine) * Environment.NewLine.Length);

            var item = new ListViewItem(string.Empty)
            {
                Checked = true,
                UseItemStyleForSubItems = true,
                SubItems =
                {
                    prgEventArgs.Paragraph.Number.ToString(),
                    lineLength.ToString(CultureInfo.InvariantCulture),                // line length
                    StringUtils.GetListViewString(prgEventArgs.Paragraph.Text, true), // old text
                    StringUtils.GetListViewString(prgEventArgs.NewText, true)         // new text
                },
                Tag = prgEventArgs
            };

            listView1.Items.Add(item);
        }
        private string UnbreakLines(string s)
        {
            string noTagText = HtmlUtils.RemoveTags(s, true);

            s = s.FixExtraSpaces().Trim();

            // dialog
            if (_configs.SkipDialogs && (noTagText.StartsWith('-') || noTagText.Contains(Environment.NewLine + "-")))
            {
                return(s);
            }
            // mood
            if (_configs.SkipMoods && noTagText.IndexOfAny(_moodChars) >= 0)
            {
                return(s);
            }
            // narrator
            if (_configs.SkipNarrator && _regexNarrator.IsMatch(noTagText))
            {
                return(s);
            }

            return(StringUtils.UnbreakLine(s));
        }
Exemple #17
0
        private void AddDash(DialogueType dialogueStyle)
        {
            string text = textBox1.Text.Trim();

            if (text.Replace(Environment.NewLine, string.Empty).Length != text.Length)
            {
                string temp = string.Empty;
                // TODO: REMOVE

                /*
                 * if (num < 1)
                 * {
                 *  if (!string.IsNullOrEmpty(text))
                 *  {
                 *      temp = Utilities.RemoveHtmlTags(text).Trim();
                 *
                 *      if (temp.StartsWith("-"))
                 *      {
                 *          text = Regex.Replace(text, @"\B-\B", string.Empty);
                 *          text = Regex.Replace(text, Environment.NewLine + @"\B-\B", Environment.NewLine);
                 *      }
                 *  }
                 * }*/
                switch (dialogueStyle)
                {
                case DialogueType.SingleDash:
                    // removes the first dash
                    temp = HtmlUtils.RemoveTags(text).Trim();
                    var val = text.Substring(0, text.IndexOf(Environment.NewLine));
                    if (HtmlUtils.RemoveTags(val).Trim().Length > 2 && val.StartsWith("-"))
                    {
                        int index = text.IndexOf("-");
                        text = text.Remove(index, 1);
                        if (text.Length > index && text[index] == 0x20)
                        {
                            text = text.Remove(index, 1);
                        }
                    }

                    // add a new dash
                    if (!temp.Contains(Environment.NewLine + "-"))
                    {
                        text          = text.Replace(Environment.NewLine, Environment.NewLine + "- ");
                        textBox1.Text = text;
                    }
                    break;

                case DialogueType.DoubleDash:
                    temp = HtmlUtils.RemoveTags(text);
                    if (!temp.StartsWith("-"))
                    {
                        text = text.Insert(0, "- ");
                    }

                    if (!temp.Contains(Environment.NewLine + "-"))
                    {
                        text = text.Replace(Environment.NewLine, Environment.NewLine + "- ");
                    }
                    textBox1.Text = text;
                    break;
                }
            }
        }
Exemple #18
0
        private void GeneratePreview()
        {
            if (_isLoading)
            {
                return;
            }

            // update configuration
            _hiConfigs.NarratorToUppercase = checkBoxNames.Checked;
            _hiConfigs.MoodsToUppercase    = checkBoxMoods.Checked;
            _hiConfigs.RemoveExtraSpaces   = checkBoxRemoveSpaces.Checked;
            _hiConfigs.SingleLineNarrator  = checkBoxSingleLineNarrator.Checked;
            _hiConfigs.Style = ((ComboBoxItem)comboBoxStyle.SelectedItem).Style;

            listViewFixes.BeginUpdate();
            listViewFixes.Items.Clear();

            _fixedTexts = new Dictionary <string, string>();

            foreach (Paragraph p in _subtitle.Paragraphs)
            {
                var  text             = p.Text;
                bool containsMood     = false;
                bool containsNarrator = false;

                // Remove Extra Spaces inside brackets ( foobar ) to (foobar)
                string beforeChanges = text;
                if (checkBoxRemoveSpaces.Checked)
                {
                    _hearingImpaired.RemoveExtraSpacesInsideTag(text);
                }
                // (Moods and feelings)
                if (checkBoxMoods.Checked)
                {
                    beforeChanges = text;
                    text          = _hearingImpaired.MoodsToUppercase(text);
                    if (beforeChanges != text)
                    {
                        text         = text.FixExtraSpaces();
                        containsMood = true;
                    }
                }
                // Narrator:
                if (checkBoxNames.Checked)
                {
                    beforeChanges    = text;
                    text             = _hearingImpaired.NarratorToUppercase(text);
                    containsNarrator = !beforeChanges.Equals(text, StringComparison.Ordinal);
                }

                if (containsMood || containsNarrator)
                {
                    _fixedTexts.Add(p.ID, text);
                    string oldText = HtmlUtils.RemoveTags(p.Text, true);
                    text = HtmlUtils.RemoveTags(text, true);
                    AddFixToListView(p, oldText, text, containsMood, containsNarrator);
                }
            }

            int totalConvertParagraphs = _fixedTexts.Count;

            groupBox1.ForeColor = totalConvertParagraphs <= 0 ? Color.Red : Color.Green;
            groupBox1.Text      = string.Format("Total Found: {0}", totalConvertParagraphs);

            /*this.listViewFixes.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
             * this.listViewFixes.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);*/
            //Application.DoEvents();
            listViewFixes.EndUpdate();
            Refresh();
        }
Exemple #19
0
        private void GeneratePreview(Subtitle sub)
        {
            if (_list == null)
            {
                _list = new List <string>();
            }
            else
            {
                _list.Clear();
            }

            listBox1.Items.Clear();
            for (int i = 0; i < sub.Paragraphs.Count; i++)
            {
                var p    = sub.Paragraphs[i];
                var text = p.Text;
                text = text.Replace('[', '(').Replace(']', ')');
                var idx = text.IndexOf('(');
                if (idx < 0)
                {
                    continue;
                }

                var noTagLines = HtmlUtils.RemoveTags(text).Replace(Environment.NewLine, "\n").Split('\n');

                // single line (Sighs)
                if (noTagLines.Length == 1)
                {
                    if (IsStartEndBraces(noTagLines[0], idx))
                    {
                        continue;
                    }

                    FindNamesInText(text, idx);
                }
                else
                {
                    //- (SKIPPER) Flaps.
                    //- KOWALSKI:  Check.

                    //(LIVELY AFRICAN
                    //TRIBAL THEME PLAYS)

                    //(CLICKING) (SNARLING)

                    //- (CLICKING) UASOIDUFA;
                    //- Oh! (LAUGHS) (SQUEALS)

                    //- (SKIPPER) initiate warp drive.
                    //- (WHIRRING)

                    for (int k = 0; k < noTagLines.Length; k++)
                    {
                        var noTagLine = noTagLines[k];
                        idx = noTagLine.IndexOf('(');
                        if (idx < 0)
                        {
                            continue;
                        }
                        if (IsStartEndBraces(noTagLine, idx))
                        {
                            if (k > 0) // continue is second line starts and ends with '(' & ')'
                            {
                                continue;
                            }
                            if (k == 0 && noTagLine.StartsWith("-", StringComparison.Ordinal)) // Continue if it's dialog
                            {
                                continue;
                            }
                        }
                        FindNamesInText(noTagLine, idx);
                    }
                }
            }
            if (listBox1.Items.Count > 0)
            {
                this.label1.Text = "Total found names: " + listBox1.Items.Count;;
            }
        }