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(); } }
static void Main(string[] args) { new Select().SetSubtitleFolder(); SubtitleProcesser processer = new SubtitleProcesser(); Types.SubtitleFormat ReadFormat = new Select().GetSubtitleReadFormat(); processer.ReadFormat = ReadFormat; Console.WriteLine($"Format: {ReadFormat.ToString()} is selected"); if (ReadFormat == Types.SubtitleFormat.ASS) { new Select().ConfigureAssReader(); } List <Subtitle> list = processer.GetSubtitlesByReadFormat(); var Writer = new StorageAccess.WriteFile(); Console.WriteLine($"{list.Count} subtitles has been read"); if (list.Count > 0) { List <Types.SubtitleFormat> exportFormats = new Select().GetEncodeFormat(); foreach (Types.SubtitleFormat format in exportFormats) { if (format == Types.SubtitleFormat.SRT) { SRTEncoder encoder = new SRTEncoder(); foreach (Subtitle subtitle in list) { encoder.Load((List <Dialog>)subtitle.dialogs); Writer.WriteSrt(subtitle.file, encoder.GetSubtitle()); } } else if (format == Types.SubtitleFormat.VTT) { VTTEncoder encoder = new VTTEncoder(); foreach (Subtitle subtitle in list) { encoder.Load((List <Dialog>)subtitle.dialogs); Writer.WriteVtt(subtitle.file, encoder.GetSubtitle()); } } else if (format == Types.SubtitleFormat.SMI) { SMIEncoder encoder = new SMIEncoder(); foreach (Subtitle subtitle in list) { string title = Path.GetFileName(subtitle.file); encoder.Load((List <Dialog>)subtitle.dialogs); Writer.WriteSmi(subtitle.file, encoder.GetSubtitle(title)); } } } } else { Console.WriteLine("No subtitles found..."); Console.Read(); } /*foreach (Subtitle subtitle in list) * { * Console.WriteLine(subtitle.file); * foreach (Dialog dialog in subtitle.dialogs) * { * StringBuilder sb = new StringBuilder(); * sb.Append(new Timing(dialog.startTime).GetSrtTime()).Append(" => "); * sb.Append(new Timing(dialog.endTime).GetSrtTime()); * sb.AppendLine().AppendLine(dialog.text); * * Console.WriteLine(sb.ToString()); * } * * Console.Read(); * }*/ Console.WriteLine("Done!"); if (Config.Debug) { Console.ReadKey(); } }