Exemplo n.º 1
0
        private CuesMap FillCuesMap(ISubtitleParser parser, Stream stream, string encoding)
        {
            if (string.IsNullOrEmpty(encoding))
            {
                encoding = parser.DefaultEncoding;
            }

            var cuesMap = new CuesMap();

            using (var reader = new StreamReader(stream, Encoding.GetEncoding(encoding)))
            {
                foreach (var cue in parser.Parse(reader))
                {
                    cuesMap.Put(cue);
                }
            }

            return(cuesMap);
        }
Exemplo n.º 2
0
        public Subtitles ParseSubtitles(UnvalidatedSubtitles unvalidatedSubtitles)
        {
            var subtitles   = new List <Subtitle>();
            int currentLine = 1;

            foreach (var subtitle in unvalidatedSubtitles.Value)
            {
                try
                {
                    subtitles.Add(
                        subtitleParser.Parse(subtitle));
                }
                catch (Exception)
                {
                    throw new SubtitlesParsingException(currentLine);
                }

                currentLine++;
            }

            return(new Subtitles(subtitles));
        }