Exemple #1
0
        public static List <LineInfo> ParseSubtitle(Settings settings, string filename, Dictionary <String, String> properties)
        {
            string mimeType = UtilsCommon.GetMimetypeByFilename(filename);

            // find right parser
            ISubtitleParser parser = null;

            switch (mimeType)
            {
            case "text/x-ass":
            case "text/x-ssa":
                parser = new SubtitleParserASS();
                break;

            case "application/x-subrip":
                parser = new SubtitleParserSRT();
                break;

            case "video/x-matroska":
                return(ParseSubtitleInVideoFile(settings, filename, properties));

            case "":
                throw new Exception("File type/mime type could not be recognized for file \"" + filename + "\"!");

            default:
                throw new Exception("Unsupportet format (" + mimeType + ") for subtitle \"" + filename + "\"!");
            }

            // read encoding string from properties
            String encodingString = "utf-8";

            if (properties.ContainsKey("enc"))
            {
                encodingString = properties["enc"];
            }

            // read all lines
            using (var fileStream = new FileStream(filename, FileMode.Open)) {
                return(parser.parse(settings, fileStream, Encoding.GetEncoding(encodingString)));
            }
        }