当前位置: 首页>>代码示例>>C#>>正文


C# Subtitle.RemoveEmptyLines方法代码示例

本文整理汇总了C#中Subtitle.RemoveEmptyLines方法的典型用法代码示例。如果您正苦于以下问题:C# Subtitle.RemoveEmptyLines方法的具体用法?C# Subtitle.RemoveEmptyLines怎么用?C# Subtitle.RemoveEmptyLines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subtitle的用法示例。


在下文中一共展示了Subtitle.RemoveEmptyLines方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();
            foreach (string s in lines)
                sb.Append(s);

            string allText = sb.ToString();
            if (!allText.Contains("\"text\""))
                return;

            var startTimes = Json.ReadArray(allText, "start");
            var endTimes = Json.ReadArray(allText, "end");
            var texts = Json.ReadArray(allText, "text");

            for (int i = 0; i < Math.Min(Math.Min(startTimes.Count, texts.Count), endTimes.Count); i++)
            {
                try
                {
                    string text = Json.DecodeJsonText(texts[i]);
                    var p = new Paragraph(text, int.Parse(startTimes[i]), int.Parse(endTimes[i]));
                    subtitle.Paragraphs.Add(p);
                }
                catch
                {
                    _errorCount++;
                }
            }
            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
开发者ID:LeonCheung,项目名称:subtitleedit,代码行数:32,代码来源:JsonType7.cs

示例2: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();
            foreach (string s in lines)
                sb.Append(s);

            string allText = sb.ToString();
            if (!allText.Contains("\"words\"") && !allText.Contains("'words'"))
                return;
            var words = Json.ReadArray(allText, "words");

            foreach (string word in words)
            {
                var elements = Json.ReadArray(word);
                if (elements.Count == 2)
                {
                    string milliseconds = elements[0].Trim('"').Trim();
                    string text = elements[1].Trim();
                    if (text.StartsWith('"'))
                        text = text.Remove(0, 1);
                    if (text.EndsWith('"'))
                        text = text.Remove(text.Length - 1, 1);

                    long number;
                    if (long.TryParse(milliseconds, out number))
                        subtitle.Paragraphs.Add(new Paragraph(text, number, number));
                    else
                        _errorCount++;
                }
            }

            sb = new StringBuilder();
            var sub = new Subtitle();
            double startMilliseconds = 0;
            if (subtitle.Paragraphs.Count > 0)
                startMilliseconds = subtitle.Paragraphs[0].StartTime.TotalMilliseconds;
            for (int i = 0; i < subtitle.Paragraphs.Count - 1; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                Paragraph next = subtitle.Paragraphs[i + 1];
                Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);
                if (sb.Length + p.Text.Length > (Configuration.Settings.General.SubtitleLineMaximumLength * 2) - 15) // text too big
                {
                    var newParagraph = new Paragraph(sb.ToString(), startMilliseconds, prev.EndTime.TotalMilliseconds);
                    sub.Paragraphs.Add(newParagraph);
                    sb = new StringBuilder();
                    if (!string.IsNullOrWhiteSpace(p.Text))
                    {
                        sb.Append(p.Text);
                        startMilliseconds = p.StartTime.TotalMilliseconds;
                    }
                }
                else if (next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds > 2000) // long time to next sub
                {
                    if (!string.IsNullOrWhiteSpace(p.Text))
                    {
                        sb.Append(' ');
                        sb.Append(p.Text);
                    }
                    var newParagraph = new Paragraph(sb.ToString(), startMilliseconds, next.StartTime.TotalMilliseconds);
                    sub.Paragraphs.Add(newParagraph);
                    sb = new StringBuilder();
                    startMilliseconds = next.StartTime.TotalMilliseconds;
                }
                else if (string.IsNullOrWhiteSpace(p.Text)) // empty text line
                {
                    if (string.IsNullOrWhiteSpace(next.Text) && sb.Length > 0)
                    {
                        var newParagraph = new Paragraph(sb.ToString(), startMilliseconds, next.StartTime.TotalMilliseconds);
                        sub.Paragraphs.Add(newParagraph);
                        sb = new StringBuilder();
                    }
                }
                else // just add word to current sub
                {
                    if (sb.Length == 0)
                        startMilliseconds = p.StartTime.TotalMilliseconds;
                    if (!string.IsNullOrWhiteSpace(p.Text))
                    {
                        sb.Append(' ');
                        sb.Append(p.Text);
                    }
                }
            }
            if (sb.Length > 0)
            {
                var newParagraph = new Paragraph(sb.ToString().Trim(), startMilliseconds, Utilities.GetOptimalDisplayMilliseconds(sb.ToString()));
                sub.Paragraphs.Add(newParagraph);
            }

            subtitle.Paragraphs.Clear();
            foreach (Paragraph p in sub.Paragraphs)
            {
                p.Text = Utilities.AutoBreakLine(p.Text);
                subtitle.Paragraphs.Add(new Paragraph(p));
            }
            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
//.........这里部分代码省略.........
开发者ID:ItsJustSean,项目名称:subtitleedit,代码行数:101,代码来源:JsonType6.cs

示例3: LoadSubtitle

 public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
 {
     _errorCount = 0;
     Paragraph p = null;
     foreach (string line in lines)
     {
         if (line.StartsWith("# SUBTITLE"))
         {
             if (p != null)
                 subtitle.Paragraphs.Add(p);
             p = new Paragraph();
         }
         else if (p != null && line.StartsWith("# TIMEIN"))
         {
             string timeCode = line.Remove(0, 8).Trim();
             if (timeCode != "--:--:--:--" && !GetTimeCode(p.StartTime, timeCode))
                 _errorCount++;
         }
         else if (p != null && line.StartsWith("# DURATION"))
         {
             // # DURATION 01:17 AUTO
             string timecode = line.Remove(0, 10).Replace("AUTO", string.Empty).Trim();
             if (timecode != "--:--")
             {
                 var arr = timecode.Split(new[] { ':', ' ' });
                 if (arr.Length > 1)
                 {
                     int sec;
                     int frame;
                     if (int.TryParse(arr[0], out sec) && int.TryParse(arr[1], out frame))
                     {
                         p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + FramesToMillisecondsMax999(frame);
                         p.EndTime.TotalSeconds += sec;
                     }
                 }
             }
         }
         else if (p != null && line.StartsWith("# TIMEOUT"))
         {
             string timeCode = line.Remove(0, 9).Trim();
             if (timeCode != "--:--:--:--" && !GetTimeCode(p.EndTime, timeCode))
                 _errorCount++;
         }
         else if (p != null && !line.StartsWith('#'))
         {
             if (p.Text.Length > 500)
             {
                 _errorCount += 10;
                 return;
             }
             p.Text = (p.Text + Environment.NewLine + line).Trim();
         }
     }
     if (p != null)
         subtitle.Paragraphs.Add(p);
     subtitle.RemoveEmptyLines();
     subtitle.Renumber();
 }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:58,代码来源:SwiftInterchange2.cs

示例4: ToolStripMenuItemInsertSubtitleClick

        private void ToolStripMenuItemInsertSubtitleClick(object sender, EventArgs e)
        {
            openFileDialog1.Title = _languageGeneral.OpenSubtitle;
            openFileDialog1.FileName = string.Empty;
            openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                if (!File.Exists(openFileDialog1.FileName))
                    return;

                var fi = new FileInfo(openFileDialog1.FileName);
                if (fi.Length > 1024 * 1024 * 10) // max 10 mb
                {
                    var text = string.Format(_language.FileXIsLargerThan10MB + Environment.NewLine + Environment.NewLine + _language.ContinueAnyway, openFileDialog1.FileName);
                    if (MessageBox.Show(this, text, Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                        return;
                }

                MakeHistoryForUndo(string.Format(_language.BeforeInsertLine, openFileDialog1.FileName));

                Encoding encoding;
                var subtitle = new Subtitle();
                SubtitleFormat format = subtitle.LoadSubtitle(openFileDialog1.FileName, out encoding, null);

                if (format != null)
                {
                    SaveSubtitleListviewIndices();
                    if (format.IsFrameBased)
                        subtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
                    else
                        subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);

                    if (Configuration.Settings.General.RemoveBlankLinesWhenOpening)
                        subtitle.RemoveEmptyLines();

                    int index = FirstSelectedIndex + 1;
                    if (index < 0)
                        index = 0;
                    foreach (var p in subtitle.Paragraphs)
                    {
                        _subtitle.Paragraphs.Insert(index, new Paragraph(p));
                        index++;
                    }

                    if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
                    {
                        index = FirstSelectedIndex;
                        if (index < 0)
                            index = 0;
                        var current = _subtitle.GetParagraphOrDefault(index);
                        if (current != null)
                        {
                            var original = Utilities.GetOriginalParagraph(index, current, _subtitleAlternate.Paragraphs);
                            if (original != null)
                            {
                                index = _subtitleAlternate.GetIndex(original);
                                foreach (var p in subtitle.Paragraphs)
                                {
                                    _subtitleAlternate.Paragraphs.Insert(index, new Paragraph(p));
                                    index++;
                                }
                                if (subtitle.Paragraphs.Count > 0)
                                    _subtitleAlternate.Renumber();
                            }
                        }
                    }
                    _subtitle.Renumber();
                    ShowSource();
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    RestoreSubtitleListviewIndices();
                }
            }
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:73,代码来源:Main.cs

示例5: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            var sb = new StringBuilder();
            foreach (string line in lines)
                sb.AppendLine(line);

            string rtf = sb.ToString().Trim();
            if (!rtf.StartsWith("{\\rtf"))
                return;

            string text = string.Empty;
            var rtBox = new System.Windows.Forms.RichTextBox();
            try
            {
                rtBox.Rtf = rtf;
                text = rtBox.Text.Replace("\r\n", "\n");
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.Message);
                return;
            }
            finally
            {
                rtBox.Dispose();
            }

            lines = new List<string>();
            foreach (string line in text.Split('\n'))
                lines.Add(line);

            _errorCount = 0;
            Paragraph p = null;
            foreach (string line in lines)
            {
                string s = line.TrimEnd();
                if (RegexTimeCode1.IsMatch(s))
                {
                    try
                    {
                        if (p != null)
                            subtitle.Paragraphs.Add(p);
                        string[] arr = s.Split('\t');
                        if (arr.Length > 2)
                            p = new Paragraph(DecodeTimeCode(arr[1]), new TimeCode(0, 0, 0, 0), arr[2].Trim());
                        else
                            p = new Paragraph(DecodeTimeCode(arr[1]), new TimeCode(0, 0, 0, 0), string.Empty);
                    }
                    catch
                    {
                        _errorCount++;
                        p = null;
                    }
                }
                else if (s.StartsWith("\t\t"))
                {
                    if (p != null)
                        p.Text = p.Text + Environment.NewLine + s.Trim();
                }
                else if (s.Trim().Length > 0)
                {
                    _errorCount++;
                }
            }
            if (p != null)
                subtitle.Paragraphs.Add(p);

            for (int j = 0; j < subtitle.Paragraphs.Count - 1; j++)
            {
                p = subtitle.Paragraphs[j];
                Paragraph next = subtitle.Paragraphs[j + 1];
                p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MininumMillisecondsBetweenLines;
            }
            if (subtitle.Paragraphs.Count > 0)
            {
                p = subtitle.Paragraphs[subtitle.Paragraphs.Count - 1];
                p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(p.Text);
            }
            subtitle.RemoveEmptyLines();
            subtitle.Renumber(1);
        }
开发者ID:athikan,项目名称:subtitleedit,代码行数:82,代码来源:UnknownSubtitle21.cs

示例6: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            bool expectStartTime = true;
            var p = new Paragraph();
            subtitle.Paragraphs.Clear();
            foreach (string line in lines)
            {
                string s = line.Trim();
                var match = regexTimeCodes1.Match(s);
                if (match.Success && s.Length == 11)
                {
                    if (!expectStartTime)
                        _errorCount++;

                    if (p.StartTime.TotalMilliseconds > 0)
                    {
                        subtitle.Paragraphs.Add(p);
                        if (string.IsNullOrEmpty(p.Text))
                            _errorCount++;
                    }

                    p = new Paragraph();
                    string[] parts = s.Split(new[] { ':', '.' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length == 4)
                    {
                        try
                        {
                            p.StartTime = DecodeTimeCode(parts);
                            expectStartTime = false;
                        }
                        catch (Exception exception)
                        {
                            _errorCount++;
                            System.Diagnostics.Debug.WriteLine(exception.Message);
                            expectStartTime = true;
                        }
                    }
                }
                else if (line.Trim().Length > 0 && !expectStartTime)
                {
                    p.Text = (p.Text + Environment.NewLine + line).Trim();
                    if (p.Text.Length > 5000)
                    {
                        _errorCount += 10;
                        return;
                    }
                }
                else if (line.Trim().Length == 0)
                {
                    expectStartTime = true;
                }
                else
                {
                    _errorCount++;
                }
            }
            if (p.StartTime.TotalMilliseconds > 0)
                subtitle.Paragraphs.Add(p);

            bool allNullEndTime = true;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                p = subtitle.Paragraphs[i];
                if (p.EndTime.TotalMilliseconds != 0)
                    allNullEndTime = false;

                p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(p.Text);
                if (i < subtitle.Paragraphs.Count - 2 && p.EndTime.TotalMilliseconds >= subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds)
                    p.EndTime.TotalMilliseconds = subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds - Configuration.Settings.General.MininumMillisecondsBetweenLines;
            }
            if (!allNullEndTime)
                subtitle.Paragraphs.Clear();

            subtitle.RemoveEmptyLines();
            subtitle.Renumber(1);
        }
开发者ID:rragu,项目名称:subtitleedit,代码行数:77,代码来源:UnknownSubtitle61.cs

示例7: LoadSubtitle

 public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
 {
     _errorCount = 0;
     var sb = new StringBuilder();
     lines.ForEach(line => sb.AppendLine(line));
     var xml = new XmlDocument { XmlResolver = null };
     xml.LoadXml(sb.ToString().Trim());
     var nsmgr = new XmlNamespaceManager(xml.NameTable);
     nsmgr.AddNamespace("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
     foreach (XmlNode node in xml.DocumentElement.SelectNodes("//w:tr", nsmgr))
     {
         try
         {
             Paragraph p = new Paragraph();
             XmlNode t = node.SelectSingleNode("w:tc/w:p/w:r/w:t", nsmgr);
             if (t != null)
             {
                 p.StartTime = DecodeTimeCodeFrames(t.InnerText.Trim(), SplitCharColon);
                 sb = new StringBuilder();
                 foreach (XmlNode wrNode in node.SelectNodes("w:tc/w:p/w:r", nsmgr))
                 {
                     foreach (XmlNode child in wrNode.ChildNodes)
                     {
                         if (child.Name == "w:t")
                         {
                             bool isTimeCode = child.InnerText.Length == 11 && child.InnerText.Replace(":", string.Empty).Length == 8;
                             if (!isTimeCode)
                                 sb.Append(child.InnerText);
                         }
                         else if (child.Name == "w:br")
                         {
                             sb.AppendLine();
                         }
                     }
                 }
                 p.Text = sb.ToString();
                 subtitle.Paragraphs.Add(p);
             }
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             _errorCount++;
         }
     }
     for (int i = 0; i < subtitle.Paragraphs.Count - 1; i++)
     {
         subtitle.Paragraphs[i].EndTime.TotalMilliseconds = subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds;
     }
     subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].EndTime.TotalMilliseconds = 2500;
     subtitle.RemoveEmptyLines();
     for (int i = 0; i < subtitle.Paragraphs.Count - 1; i++)
     {
         if (subtitle.Paragraphs[i].EndTime.TotalMilliseconds == subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds)
             subtitle.Paragraphs[i].EndTime.TotalMilliseconds = subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds - 1;
     }
     subtitle.Renumber();
 }
开发者ID:ARASHz4,项目名称:subtitleedit,代码行数:58,代码来源:OresmeDocXDocument.cs

示例8: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            var sb = new StringBuilder();
            foreach (string line in lines)
                sb.AppendLine(line);

            string rtf = sb.ToString().Trim();
            if (!rtf.StartsWith("{\\rtf"))
                return;

            string[] arr = null;
            var rtBox = new System.Windows.Forms.RichTextBox();
            try
            {
                rtBox.Rtf = rtf;
                arr = rtBox.Text.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.Message);
                return;
            }
            finally
            {
                rtBox.Dispose();
            }

            bool expectStartTime = true;
            var p = new Paragraph();
            subtitle.Paragraphs.Clear();
            foreach (string line in arr)
            {
                string s = line.Trim().Replace("*", string.Empty);
                var match = regexTimeCodes.Match(s);
                if (match.Success)
                {
                    string[] parts = s.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length == 4)
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(p.Text))
                            {
                                subtitle.Paragraphs.Add(p);
                                p = new Paragraph();
                            }
                            p.StartTime = DecodeTimeCode(parts[1]);
                            p.EndTime = DecodeTimeCode(parts[2]);
                            expectStartTime = false;
                        }
                        catch (Exception exception)
                        {
                            _errorCount++;
                            System.Diagnostics.Debug.WriteLine(exception.Message);
                        }
                    }
                }
                else if (line.Trim().Length == 0)
                {
                    if (p != null)
                    {
                        if (p.StartTime.TotalMilliseconds == 0 && p.EndTime.TotalMilliseconds == 0)
                            _errorCount++;
                        else
                            subtitle.Paragraphs.Add(p);
                        p = new Paragraph();
                    }
                }
                else if (line.Trim().Length > 0 && !expectStartTime)
                {
                    p.Text = (p.Text + Environment.NewLine + line).Trim();
                    if (p.Text.Length > 500)
                    {
                        _errorCount += 10;
                        return;
                    }
                    while (p.Text.Contains(Environment.NewLine + " "))
                        p.Text = p.Text.Replace(Environment.NewLine + " ", Environment.NewLine);
                }
            }
            if (!string.IsNullOrEmpty(p.Text))
                subtitle.Paragraphs.Add(p);

            subtitle.RemoveEmptyLines();
            subtitle.Renumber(1);
        }
开发者ID:radinamatic,项目名称:subtitleedit,代码行数:87,代码来源:UnknownSubtitle55.cs

示例9: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            Paragraph paragraph = null;
            _errorCount = 0;
            subtitle.Paragraphs.Clear();
            var text = new StringBuilder();
            foreach (string line in lines)
            {
                string s = line.Trim();
                if (s.Length > 19 && RegexTimeCode.IsMatch(s))
                {
                    var lineParts = s.Split('\t');
                    var parts = lineParts[1].Split('/');
                    if (parts.Length == 2)
                    {
                        if (text.Length > 0 && paragraph != null)
                        {
                            paragraph.Text = text.ToString().Trim();
                        }
                        try
                        {
                            var startTime = parts[0].Trim();
                            var endTime = parts[1].Trim();

                            string[] startTimeParts = { startTime.Substring(0, 2), startTime.Substring(2, 2), startTime.Substring(4, 2), startTime.Substring(6, 2) };
                            string[] endTimeParts = { startTime.Substring(0, 2), startTime.Substring(2, 2), startTime.Substring(4, 2), startTime.Substring(6, 2) };

                            paragraph = new Paragraph { StartTime = DecodeTimeCode(startTimeParts), EndTime = DecodeTimeCode(endTimeParts) };
                            subtitle.Paragraphs.Add(paragraph);
                            text = new StringBuilder();
                            s = s.Remove(0, 18 + lineParts[0].Length).Trim();
                            var idxA = s.IndexOf("@");
                            if (idxA > 0)
                            {
                                s = s.Substring(0, idxA - 1).Trim();
                            }
                            text.Append(s);
                        }
                        catch (Exception)
                        {
                            _errorCount++;
                        }
                    }
                    else
                    {
                        _errorCount++;
                    }
                }
                else if (paragraph != null && text.Length < 150)
                {
                    var idxA = s.IndexOf("@");
                    if (idxA > 0)
                    {
                        s = s.Substring(0, idxA - 1).Trim();
                    }
                    text.Append(Environment.NewLine + s);
                }
                else
                {
                    _errorCount++;
                    if (_errorCount > 10)
                        return;
                }
            }
            if (text.Length > 0 && paragraph != null)
            {
                paragraph.Text = text.ToString().Trim();
            }
            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
开发者ID:YangEunYong,项目名称:subtitleedit,代码行数:71,代码来源:UnknownSubtitle80.cs

示例10: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();
            lines.ForEach(line => sb.AppendLine(line));
            if (!sb.ToString().Contains("<StTextList"))
            {
                _errorCount++;
                return;
            }

            var xml = new XmlDocument { XmlResolver = null };
            try
            {
                xml.LoadXml(sb.ToString().Trim());

                XmlNode use2997DropFrame = xml.DocumentElement.SelectSingleNode("TrackList/Track/FcpProperty");
                if (use2997DropFrame != null && use2997DropFrame.Attributes["Use2997DropFrame"] != null && use2997DropFrame.Attributes["Use2997DropFrame"].InnerText == "1")
                    Configuration.Settings.General.CurrentFrameRate = 29.97;

                foreach (XmlNode node in xml.SelectNodes("//StItem"))
                {
                    Paragraph p = new Paragraph();
                    p.StartTime = new TimeCode(long.Parse(node.Attributes["TC"].InnerText));

                    //p.StartFrame = int.Parse(node.Attributes["TC"].InnerText);
                    //p.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
                    try
                    {
                        string text = string.Empty;
                        XmlNodeList list = node.SelectNodes("StTextList/StText");

                        if (list.Count == 3 && RegexTimeCodes.IsMatch(list[2].InnerText))
                            p.StartTime.TotalMilliseconds = TimeCode.ParseHHMMSSFFToMilliseconds(list[2].InnerText);

                        if (list.Count > 1)
                        {
                            text = (list[0].InnerText + Environment.NewLine + list[1].InnerText).Trim();
                        }
                        else if (list.Count == 1)
                        {
                            text = list[0].InnerText.Trim();
                        }

                        p.Text = text;
                        subtitle.Paragraphs.Add(p);
                    }
                    catch
                    {
                        _errorCount++;
                    }
                }
                subtitle.Renumber();
            }
            catch
            {
                _errorCount = 1;
                return;
            }

            int i = 0;
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                i++;
                var next = subtitle.GetParagraphOrDefault(i);
                if (next != null)
                    p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds;
            }
            subtitle.RemoveEmptyLines();
        }
开发者ID:ARASHz4,项目名称:subtitleedit,代码行数:71,代码来源:IssXml.cs

示例11: LoadSubtitle


//.........这里部分代码省略.........
                            start = attr.InnerText;
                        else if (attr.Name.EndsWith("end", StringComparison.Ordinal))
                            end = attr.InnerText;
                        else if (attr.Name.EndsWith("duration", StringComparison.Ordinal))
                            dur = attr.InnerText;
                    }
                    string text = pText.ToString();
                    text = text.Replace(Environment.NewLine + "</i>", "</i>" + Environment.NewLine);
                    text = text.Replace("<i></i>", string.Empty).Trim();
                    if (end != null)
                    {
                        if (end.Length != 11 || end.Substring(8, 1) != ":" || start == null || start.Length != 11 || start.Substring(8, 1) != ":")
                        {
                            couldBeFrames = false;
                        }

                        if (couldBeMillisecondsWithMissingLastDigit && (end.Length != 11 || start == null || start.Length != 11 || end.Substring(8, 1) != "." || start.Substring(8, 1) != "."))
                        {
                            couldBeMillisecondsWithMissingLastDigit = false;
                        }

                        double dBegin, dEnd;
                        if (!start.Contains(':') && Utilities.CountTagInText(start, '.') == 1 &&
                            !end.Contains(':') && Utilities.CountTagInText(end, '.') == 1 &&
                            double.TryParse(start, NumberStyles.Float, CultureInfo.InvariantCulture, out dBegin) && double.TryParse(end, NumberStyles.Float, CultureInfo.InvariantCulture, out dEnd))
                        {
                            subtitle.Paragraphs.Add(new Paragraph(text, dBegin * TimeCode.BaseUnit, dEnd * TimeCode.BaseUnit));
                        }
                        else
                        {
                            if (start.Length == 8 && start[2] == ':' && start[5] == ':' && end.Length == 8 && end[2] == ':' && end[5] == ':')
                            {
                                var p = new Paragraph();
                                var parts = start.Split(SplitCharColon);
                                p.StartTime = new TimeCode(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), 0);
                                parts = end.Split(SplitCharColon);
                                p.EndTime = new TimeCode(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), 0);
                                p.Text = text;
                                subtitle.Paragraphs.Add(p);
                            }
                            else
                            {
                                subtitle.Paragraphs.Add(new Paragraph(TimedText10.GetTimeCode(start, false), TimedText10.GetTimeCode(end, false), text));
                            }
                        }
                    }
                    else if (dur != null)
                    {
                        if (dur.Length != 11 || dur.Substring(8, 1) != ":" || start == null || start.Length != 11 || start.Substring(8, 1) != ":")
                        {
                            couldBeFrames = false;
                        }

                        if (couldBeMillisecondsWithMissingLastDigit && (dur.Length != 11 || start == null || start.Length != 11 || dur.Substring(8, 1) != "." || start.Substring(8, 1) != "."))
                        {
                            couldBeMillisecondsWithMissingLastDigit = false;
                        }

                        TimeCode duration = TimedText10.GetTimeCode(dur, false);
                        TimeCode startTime = TimedText10.GetTimeCode(start, false);
                        var endTime = new TimeCode(startTime.TotalMilliseconds + duration.TotalMilliseconds);
                        subtitle.Paragraphs.Add(new Paragraph(startTime, endTime, text));
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    _errorCount++;
                }
            }
            subtitle.RemoveEmptyLines();

            if (couldBeFrames)
            {
                bool all30OrBelow = true;
                foreach (Paragraph p in subtitle.Paragraphs)
                {
                    if (p.StartTime.Milliseconds > 30 || p.EndTime.Milliseconds > 30)
                        all30OrBelow = false;
                }
                if (all30OrBelow)
                {
                    foreach (Paragraph p in subtitle.Paragraphs)
                    {
                        p.StartTime.Milliseconds = SubtitleFormat.FramesToMillisecondsMax999(p.StartTime.Milliseconds);
                        p.EndTime.Milliseconds = SubtitleFormat.FramesToMillisecondsMax999(p.EndTime.Milliseconds);
                    }
                }
            }
            else if (couldBeMillisecondsWithMissingLastDigit &&  Configuration.Settings.SubtitleSettings.TimedText10TimeCodeFormatSource != "hh:mm:ss.ms-two-digits")
            {
                foreach (Paragraph p in subtitle.Paragraphs)
                {
                    p.StartTime.Milliseconds *= 10;
                    p.EndTime.Milliseconds *= 10;
                }
            }

            subtitle.Renumber();
        }
开发者ID:mgziminsky,项目名称:subtitleedit,代码行数:101,代码来源:TimedText.cs

示例12: LoadSubtitle

        /// <summary>
        /// The load subtitle.
        /// </summary>
        /// <param name="subtitle">
        /// The subtitle.
        /// </param>
        /// <param name="lines">
        /// The lines.
        /// </param>
        /// <param name="fileName">
        /// The file name.
        /// </param>
        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            // {T 00:03:14:27
            // Some text
            // }
            this._errorCount = 0;
            bool textOn = false;
            string text = string.Empty;
            TimeCode start = new TimeCode(0);
            TimeCode end = new TimeCode(0);
            foreach (string line in lines)
            {
                if (textOn)
                {
                    if (line.Trim() == "}")
                    {
                        Paragraph p = new Paragraph();
                        p.Text = text;
                        p.StartTime = new TimeCode(start.TotalMilliseconds);
                        p.EndTime = new TimeCode(end.TotalMilliseconds);

                        subtitle.Paragraphs.Add(p);

                        text = string.Empty;
                        start = new TimeCode(0);
                        end = new TimeCode(0);
                        textOn = false;
                    }
                    else
                    {
                        if (text.Length == 0)
                        {
                            text = line;
                        }
                        else
                        {
                            text += Environment.NewLine + line;
                        }
                    }
                }
                else
                {
                    if (regexTimeCodes.Match(line).Success)
                    {
                        try
                        {
                            textOn = true;
                            string[] arr = line.Substring(3).Trim().Split(':');
                            if (arr.Length == 4)
                            {
                                int hours = int.Parse(arr[0]);
                                int minutes = int.Parse(arr[1]);
                                int seconds = int.Parse(arr[2]);
                                int milliseconds = int.Parse(arr[3]);
                                if (arr[3].Length == 2)
                                {
                                    milliseconds *= 10;
                                }

                                start = new TimeCode(hours, minutes, seconds, milliseconds);
                            }
                        }
                        catch
                        {
                            textOn = false;
                            this._errorCount++;
                        }
                    }
                }
            }

            int index = 1;
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                Paragraph next = subtitle.GetParagraphOrDefault(index);
                if (next != null)
                {
                    p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                }

                index++;
            }

            subtitle.RemoveEmptyLines();

            subtitle.Renumber();
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:99,代码来源:DvdSubtitle.cs

示例13: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            Paragraph p = null;
            foreach (string line in lines)
            {
                string s = line.Trim();
                string[] arr = line.Split();
                var timeCode = arr[arr.Length - 1];
                if (regexTimeCodesAM.Match(timeCode).Success || regexTimeCodesPM.Match(timeCode).Success)
                {
                    try
                    {
                        arr = timeCode.Substring(0, 10).Split(':');
                        if (arr.Length == 4)
                        {
                            int hours = int.Parse(arr[0]);
                            int minutes = int.Parse(arr[1]);
                            int seconds = int.Parse(arr[2]);
                            int frames = int.Parse(arr[3]);
                            p = new Paragraph();
                            p.StartTime = new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames));
                            p.Text = s.Substring(0, s.IndexOf(timeCode)).Trim();
                            subtitle.Paragraphs.Add(p);
                        }
                    }
                    catch
                    {
                        _errorCount++;
                    }
                }
                else if (s.Length > 0)
                {
                    _errorCount++;
                }
            }

            int index = 1;
            foreach (Paragraph paragraph in subtitle.Paragraphs)
            {
                Paragraph next = subtitle.GetParagraphOrDefault(index);
                if (next != null)
                {
                    paragraph.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                }
                if (paragraph.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
                {
                    paragraph.EndTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(p.Text);
                }
                index++;
            }

            subtitle.RemoveEmptyLines();
            subtitle.Renumber(1);
        }
开发者ID:athikan,项目名称:subtitleedit,代码行数:55,代码来源:UnknownSubtitle46.cs

示例14: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            foreach (string line in lines)
            {
                string s = line.Trim();
                if (RegexTimeCodes.Match(s).Success)
                {
                    try
                    {
                        var arr = s.Substring(0, 10).Split(':');
                        if (arr.Length == 4)
                        {
                            var p = new Paragraph();
                            p.StartTime = DecodeTimeCodeFramesFourParts(arr);
                            p.Text = s.Remove(0, 10).Trim();
                            subtitle.Paragraphs.Add(p);
                        }
                    }
                    catch
                    {
                        _errorCount++;
                    }
                }
                else if (s.Length > 0)
                {
                    _errorCount++;
                }
            }

            int index = 1;
            foreach (Paragraph paragraph in subtitle.Paragraphs)
            {
                Paragraph next = subtitle.GetParagraphOrDefault(index);
                if (next != null)
                {
                    paragraph.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                }
                if (paragraph.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
                {
                    paragraph.EndTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(paragraph.Text);
                }
                index++;
            }

            subtitle.RemoveEmptyLines();
            subtitle.Renumber();
        }
开发者ID:ARASHz4,项目名称:subtitleedit,代码行数:48,代码来源:UnknownSubtitle47.cs

示例15: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            Paragraph p = null;
            foreach (string line in lines)
            {
                string s = line.Trim();
                if (RegexTimeCodes.Match(s).Success)
                {
                    if (p != null && !string.IsNullOrEmpty(p.Text))
                        subtitle.Paragraphs.Add(p);
                    p = new Paragraph();

                    try
                    {
                        string[] arr = s.Substring(0, 11).Split(':');
                        if (arr.Length == 4)
                        {
                            int hours = int.Parse(arr[0]);
                            int minutes = int.Parse(arr[1]);
                            int seconds = int.Parse(arr[2]);
                            int frames = int.Parse(arr[3]);
                            p.StartTime = new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames));
                            string text = s.Remove(0, 11).Trim();
                            p.Text = text;
                            if (text.Length > 1 && Utilities.IsInteger(text.Substring(0, 2)))
                                _errorCount++;
                        }
                    }
                    catch
                    {
                        _errorCount++;
                    }
                }
                else if (s.Length > 0)
                {
                    _errorCount++;
                }
            }
            if (p != null && !string.IsNullOrEmpty(p.Text))
                subtitle.Paragraphs.Add(p);

            int index = 1;
            foreach (Paragraph paragraph in subtitle.Paragraphs)
            {
                paragraph.Text = paragraph.Text.Replace("\\M", "♪");

                Paragraph next = subtitle.GetParagraphOrDefault(index);
                if (next != null)
                {
                    paragraph.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                }
                else
                {
                    paragraph.EndTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(paragraph.Text);
                }
                index++;
            }
            subtitle.RemoveEmptyLines();
        }
开发者ID:ItsJustSean,项目名称:subtitleedit,代码行数:60,代码来源:UnknownSubtitle53.cs


注:本文中的Subtitle.RemoveEmptyLines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。