Пример #1
0
        public Subtitle Parse(string str)
        {
            var result = new Dictionary<int, SubtitleLine>();
            var blocks = str.Split(new[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int index = 0;
            foreach (var block in blocks)
            {
                var array = block.Split(new string[] {"\r","\n"}, StringSplitOptions.RemoveEmptyEntries);
                if(array.Length<3) continue;
                var srt = new SubtitleLine();
                var num = array[0];
                srt.Number = ++index;

                var tarray = array[1].Split(new string[] { " --> " }, StringSplitOptions.RemoveEmptyEntries);
                srt.StartTime = Convert.ToDateTime("2000-01-01 " + tarray[0].Replace(',', '.').Replace(" ",""));
                srt.EndTime = Convert.ToDateTime("2000-01-01 " + tarray[1].Replace(',', '.').Replace(" ", ""));

                srt.Text = "";
                for (var i = 2; i < array.Length;i++ )
                    srt.Text += array[i]+"\r\n";
                if (srt.Text != "")
                {
                    srt.Text= srt.Text.Remove(srt.Text.Length - 2, 2);
                }
                result.Add(index,srt);
            }
            Subtitle st = new Subtitle(){Bodies=result};
            //ReCalcSequence(st);
            return st;
        }
        private string Line2String(SubtitleLine line)
        {
            var           array = line.OriginalText.Split(',');
            StringBuilder sb    = new StringBuilder();

            sb.Append(array[0]);
            sb.Append(",");
            sb.Append(line.StartTime.ToString("H:mm:ss.ff"));
            sb.Append(",");
            sb.Append(line.EndTime.ToString("H:mm:ss.ff"));
            sb.Append(",");
            sb.Append(array[3]);
            sb.Append(",");
            sb.Append(array[4]);
            sb.Append(",");
            sb.Append(array[5]);
            sb.Append(",");
            sb.Append(array[6]);
            sb.Append(",");
            sb.Append(array[7]);
            sb.Append(",");
            sb.Append(array[8]);
            sb.Append(",");
            sb.Append(line.Text);
            return(sb.ToString());
        }
Пример #3
0
        private SubtitleLine ParseLine(string block, int number)
        {
            var array = block.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            if (array.Length < 3)
            {
                return(null);
            }
            var srt = new SubtitleLine();
            var num = array[0];

            srt.Number = number;

            var tarray = array[1].Split(new string[] { " --> " }, StringSplitOptions.RemoveEmptyEntries);

            srt.StartTime = Convert.ToDateTime("2000-01-01 " + tarray[0].Replace(',', '.').Replace(" ", ""));
            srt.EndTime   = Convert.ToDateTime("2000-01-01 " + tarray[1].Replace(',', '.').Replace(" ", ""));


            srt.Text = "";
            for (var i = 2; i < array.Length; i++)
            {
                srt.Text += array[i] + " ";
            }
            if (srt.Text != "")
            {
                srt.Text = srt.Text.Trim();
            }
            return(srt);
        }
Пример #4
0
        public Subtitle Parse(string str)
        {
            var result = new List <SubtitleLine>();
            var blocks = str.Split(new[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var block in blocks)
            {
                var array = block.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                var srt   = new SubtitleLine();
                var num   = array[0];
                srt.Number = Convert.ToInt32(num);

                var tarray = array[1].Split(new string[] { " --> " }, StringSplitOptions.RemoveEmptyEntries);
                srt.StartTime = Convert.ToDateTime("2000-01-01 " + tarray[0].Replace(',', '.'));
                srt.EndTime   = Convert.ToDateTime("2000-01-01 " + tarray[1].Replace(',', '.'));


                srt.Text = "";
                for (var i = 2; i < array.Length; i++)
                {
                    srt.Text += array[i] + "\r\n";
                }
                srt.Text = srt.Text.Remove(srt.Text.Length - 2, 2);
                result.Add(srt);
            }
            Subtitle st = new Subtitle()
            {
                Bodies = result
            };

            return(st);
        }
        private SubtitleLine ParseLine(string line)
        {
            SubtitleLine subtitleLine = new SubtitleLine();
            var          array        = line.Split(',');

            subtitleLine.StartTime    = Convert.ToDateTime("2000-01-01 " + array[1]);
            subtitleLine.EndTime      = Convert.ToDateTime("2000-01-01 " + array[2]);
            subtitleLine.OriginalText = line;
            subtitleLine.Text         = array[9];
            if (array.Length > 10)
            {
                for (int i = 10; i < array.Length; i++)
                {
                    subtitleLine.Text += "," + array[i];
                }
            }
            return(subtitleLine);
        }
Пример #6
0
        public Subtitle Parse(string str)
        {
            var result = new Dictionary <int, SubtitleLine>();
            var blocks = str.Split(new[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int index  = 0;

            foreach (var block in blocks)
            {
                var array = block.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                if (array.Length < 3)
                {
                    continue;
                }
                var srt = new SubtitleLine();
                var num = array[0];
                srt.Number = ++index;

                var tarray = array[1].Split(new string[] { " --> " }, StringSplitOptions.RemoveEmptyEntries);
                srt.StartTime = Convert.ToDateTime("2000-01-01 " + tarray[0].Replace(',', '.').Replace(" ", ""));
                srt.EndTime   = Convert.ToDateTime("2000-01-01 " + tarray[1].Replace(',', '.').Replace(" ", ""));


                srt.Text = "";
                for (var i = 2; i < array.Length; i++)
                {
                    srt.Text += array[i] + "\r\n";
                }
                if (srt.Text != "")
                {
                    srt.Text = srt.Text.Remove(srt.Text.Length - 2, 2);
                }
                result.Add(index, srt);
            }
            Subtitle st = new Subtitle()
            {
                Bodies = result
            };

            //ReCalcSequence(st);
            return(st);
        }
Пример #7
0
 private string Line2String(SubtitleLine line)
 {
     var array = line.OriginalText.Split(',');
     StringBuilder sb=new StringBuilder();
     sb.Append(array[0]);
     sb.Append(",");
     sb.Append(line.StartTime.ToString("H:mm:ss.ff"));
     sb.Append(",");
     sb.Append(line.EndTime.ToString("H:mm:ss.ff"));
     sb.Append(",");
     sb.Append(array[3]);
     sb.Append(",");
     sb.Append(array[4]);
     sb.Append(",");
     sb.Append(array[5]);
     sb.Append(",");
     sb.Append(array[6]);
     sb.Append(",");
     sb.Append(array[7]);
     sb.Append(",");
     sb.Append(array[8]);
     sb.Append(",");
     sb.Append(line.Text);
     return sb.ToString();
 }
Пример #8
0
 private SubtitleLine ParseLine(string line)
 {
     SubtitleLine subtitleLine=new SubtitleLine();
     var array = line.Split(',');
     subtitleLine.StartTime = Convert.ToDateTime("2000-01-01 " + array[1]);
     subtitleLine.EndTime = Convert.ToDateTime("2000-01-01 " + array[2]);
     subtitleLine.OriginalText = line;
     subtitleLine.Text = array[9];
     if (array.Length > 10)
     {
         for (int i = 10; i < array.Length; i++)
         {
             subtitleLine.Text += "," + array[i];
         }
     }
     return subtitleLine;
 }
Пример #9
0
 private Subtitle BuildSubtitleFromGrid()
 {
     Subtitle nsubtitle=new Subtitle();
     nsubtitle.Header = subtitle.Header;
     nsubtitle.Footer = nsubtitle.Footer;
     nsubtitle.Bodies = new Dictionary<int, SubtitleLine>();
     foreach (DataGridViewRow row in dgvSubtitleSentence.Rows)
     {
         SubtitleLine line=new SubtitleLine();
         var number = Convert.ToInt32( row.Cells[0].Value.ToString());
         var orgLine = subtitle.Bodies[number];//.SingleOrDefault(i => i.Number == number);
         line.Number = number;
         line.StartTime = orgLine.StartTime;
         line.EndTime = orgLine.EndTime;
         line.Text = row.Cells[2].Value.ToString();
         nsubtitle.Bodies.Add(number,line);
     }
     return nsubtitle;
 }