Exemplo n.º 1
0
        /// <summary>
        /// Get the current Subtitle and the sub before (-1) and after (+1)
        /// </summary>
        /// <returns>Tuple : Item1 is before, Item2 is current, Item3 is after</returns>
        public Tuple <SubtitleLine, SubtitleLine, SubtitleLine> GetActual()
        {
            try
            {
                SubtitleLine l1 = _subTitles.Single(l => l.Numero == _index);
                SubtitleLine before;
                if (_index == 1)
                {
                    before = new SubtitleLine();
                }
                else
                {
                    before = _subTitles.Single(l => l.Numero == _index - 1);
                }

                SubtitleLine after;
                if (_index == _subTitles.Count)
                {
                    after = new SubtitleLine();
                }
                else
                {
                    after = _subTitles.Single(l => l.Numero == _index + 1);
                }

                return(new Tuple <SubtitleLine, SubtitleLine, SubtitleLine>(before, l1, after));
            }
            catch (Exception)
            {
                return(new Tuple <SubtitleLine, SubtitleLine, SubtitleLine>(new SubtitleLine(), new SubtitleLine(), new SubtitleLine()));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Read the file and load every subtitle line
        /// </summary>
        /// <param name="filePath">path of the loaded file</param>
        public void ReadFile(string filePath)
        {
            _subTitles.Clear();
            string[] lignes = File.ReadAllLines(filePath, Encoding.UTF8);
            for (int i = 0; i < lignes.Length; i++)
            {
                int numLigne = 0;
                if (int.TryParse(lignes[i], out numLigne))
                {
                    SubtitleLine l = new SubtitleLine();
                    l.Numero = numLigne;
                    i++;
                    string   ligne = lignes[i].Replace(" ", string.Empty);
                    string[] temps = ligne.Split(new char[3] {
                        '-', '-', '>'
                    }, StringSplitOptions.RemoveEmptyEntries);
                    l.StartTime = TimeSpan.Parse(temps[0]);
                    l.EndTime   = TimeSpan.Parse(temps[1]);
                    i++;
                    while (!int.TryParse(lignes[i], out numLigne))
                    {
                        l.Text.Add(lignes[i]);
                        i++;
                        if (i == lignes.Length)
                        {
                            break;
                        }
                    }

                    _subTitles.Add(l);
                    i--;
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Calculate the time difference between the StartTime and the EndTime
 /// of the SubtitleLine and compare it to the time difference.
 /// It's an error if the calculated time difference is superior at timeDifferenceInSeconds
 /// </summary>
 /// <param name="ligne">SubtitleLine</param>
 /// <param name="timeDifferenceInSeconds">Time difference in seconds</param>
 /// <returns>Error is Color.Tomato, otherwise it's Color.Green</returns>
 public static Color ColorErrorBetweenStartAndEndTime(SubtitleLine ligne, int timeDifferenceInSeconds)
 {
     if (IsErrorBetweenStartAndEndTime(ligne, timeDifferenceInSeconds))
     {
         return(Color.Tomato);
     }
     else
     {
         return(Color.Green);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Calculate the time difference between the StartTime and the EndTime
        /// of the SubtitleLine and compare it to the time difference.
        /// It's an error if the calculated time difference is superior at timeDifferenceInSeconds
        /// </summary>
        /// <param name="ligne">SubtitleLine</param>
        /// <param name="timeDifferenceInSeconds">Time difference in seconds</param>
        /// <returns>True if the Time Difference is inferior at timeDifferenceInSeconds</returns>
        public static bool IsErrorBetweenStartAndEndTime(SubtitleLine ligne, int timeDifferenceInSeconds)
        {
            TimeSpan ts  = new TimeSpan(0, 0, timeDifferenceInSeconds);
            TimeSpan ts2 = ligne.EndTime.Subtract(ligne.StartTime);

            if (ts.CompareTo(ts2) > 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }