public Subtitle GetSubtitleByFile(string file, Types.SubtitleFormat format) { List <Dialog> dialogs = new List <Dialog>(); SubtitleReader reader = null; switch (format) { case Types.SubtitleFormat.ASS: reader = new AssSubtitleReader(); break; case Types.SubtitleFormat.SRT: reader = new SrtSubtitleReader(); break; case Types.SubtitleFormat.VTT: reader = new VttSubtitleReader(); break; } if (reader != null) { string[] contentLines = new StorageAccess.ReadFile().GetLines(file); reader.Load(contentLines); dialogs.AddRange(reader.GetDialogs()); } return(new Subtitle(file, dialogs)); }
public static List <Types.SubtitleFormat> GetExportFormats(Types.SubtitleFormat configured) { List <Types.SubtitleFormat> formats = new List <Types.SubtitleFormat>(); if (configured != Types.SubtitleFormat.NOT_SET) { formats.Add(configured); } else { formats.Add(Types.SubtitleFormat.SRT); formats.Add(Types.SubtitleFormat.VTT); formats.Add(Types.SubtitleFormat.SMI); } return(formats); }
public Types.SubtitleFormat GetSubtitleReadFormat() { Types.SubtitleFormat format = Types.SubtitleFormat.NOT_SET; while (format == Types.SubtitleFormat.NOT_SET) { PrintFormatSelection(); try { Console.Write("Select: "); var input = Console.ReadLine().ToString(); if (input.Equals("c") || input.Equals("C")) { return(format); } var selection = Convert.ToInt32(input); if (selection == 0) { format = Types.SubtitleFormat.ASS; } else if (selection == 1) { format = Types.SubtitleFormat.SRT; } else if (selection == 2) { format = Types.SubtitleFormat.VTT; } } catch { } Console.Clear(); } return(format); }
static void Main(string[] args) { SubtitleProcesser processer = new SubtitleProcesser(); List <RunOption> optionList = new OptionLoader().GetOptions(args); if (optionList.Any(x => x.Switch == Types.OptionTypes.DEBUG)) { bool isDebugging = (bool)optionList.FirstOrDefault(x => x.Switch == Types.OptionTypes.DEBUG).Option; if (isDebugging) { Console.Write("Enabling Debugging"); Config.Debug = true; } } string input_subtitle = null; Types.SubtitleFormat ReadFormat = Types.SubtitleFormat.NOT_SET; if (optionList.Any(x => x.Switch == Types.OptionTypes.INPUT_FILE)) { input_subtitle = (string)optionList.FirstOrDefault(x => x.Switch == Types.OptionTypes.INPUT_FILE).Option; if (optionList.Any(x => x.Switch == Types.OptionTypes.INPUT_FORMAT)) { ReadFormat = Helper.GetSubtitleFormat((string)optionList.FirstOrDefault(x => x.Switch == Types.OptionTypes.INPUT_FORMAT).Option); } else if (optionList.Any(x => x.Switch == Types.OptionTypes.INPUT_FILE)) { ReadFormat = Helper.GetSubtitleFormat((string)optionList.FirstOrDefault(x => x.Switch == Types.OptionTypes.INPUT_FILE).Option); } else { Console.Write("Please provide a input file or a file format"); Environment.Exit(1); } } else { Console.Write("Please provide a input file"); Environment.Exit(1); } // FOR ASS if (optionList.Any(x => x.Switch == Types.OptionTypes.FORCE_SIGNS_AND_SONGS)) { Config.AddSigns = (bool)optionList.FirstOrDefault(x => x.Switch == Types.OptionTypes.FORCE_SIGNS_AND_SONGS).Option; } string output_dir = null; Types.SubtitleFormat OutFormat = Types.SubtitleFormat.NOT_SET; if (optionList.Any(x => x.Switch == Types.OptionTypes.OUTPUT_FORMAT)) { OutFormat = Helper.GetSubtitleFormat((string)optionList.FirstOrDefault(x => x.Switch == Types.OptionTypes.OUTPUT_FORMAT).Option); } if (optionList.Any(x => x.Switch == Types.OptionTypes.OUTPUT_DIR)) { output_dir = (string)optionList.FirstOrDefault(x => x.Switch == Types.OptionTypes.OUTPUT_DIR).Option; } List <Subtitle> list = new List <Subtitle>(); if (input_subtitle != null && ReadFormat != Types.SubtitleFormat.NOT_SET) { list.Add(processer.GetSubtitleByFile(input_subtitle, ReadFormat)); } else { list.AddRange(processer.GetSubtitlesByReadFormat()); } if (list.Count > 0) { var Writer = new StorageAccess.WriteFile(); List <Types.SubtitleFormat> exportFormats = Helper.GetExportFormats(OutFormat); foreach (Subtitle subtitle in list) { string outFile = (output_dir != null) ? Helper.GetOutputFile(output_dir, subtitle.file) : subtitle.file; if (Types.SubtitleFormat.SRT != ReadFormat && exportFormats.Any(x => x == Types.SubtitleFormat.SRT)) { SRTEncoder encoder = new SRTEncoder(); encoder.Load((List <Dialog>)subtitle.dialogs); Writer.WriteSrt(outFile, encoder.GetSubtitle()); } if (Types.SubtitleFormat.VTT != ReadFormat && exportFormats.Any(x => x == Types.SubtitleFormat.VTT)) { VTTEncoder encoder = new VTTEncoder(); encoder.Load((List <Dialog>)subtitle.dialogs); Writer.WriteVtt(outFile, encoder.GetSubtitle()); } if (Types.SubtitleFormat.SMI != ReadFormat && exportFormats.Any(x => x == Types.SubtitleFormat.SMI)) { SMIEncoder encoder = new SMIEncoder(); string title = Path.GetFileNameWithoutExtension(subtitle.file); encoder.Load((List <Dialog>)subtitle.dialogs); Writer.WriteSmi(outFile, encoder.GetSubtitle(title)); } } } else { Console.WriteLine("No subtitles found..."); if (Config.Debug) { Console.ReadKey(); } Environment.Exit(1); } if (Config.Debug) { Console.ReadKey(); } }