private bool CheckArguments(Parsed <CommandLineOptions> values) { var result = true; _input = values.Value.Input; _output = values.Value.Output; _track = values.Value.Track; _tesseractData = !string.IsNullOrEmpty(values.Value.TesseractData) ? values.Value.TesseractData : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tessdata"); var outputDirectory = Path.GetDirectoryName(_output); if (!File.Exists(values.Value.Input)) { _logger.LogError($"Input file '{_input}' doesn't exist."); result = false; } if (!_track.HasValue && _input.ToLowerInvariant().EndsWith(".mkv")) { _logger.LogError("Track must be set when input in an mkv file."); result = false; } if (!Directory.Exists(outputDirectory)) { _logger.LogError($"Output directory '{outputDirectory}' doesn't exist."); result = false; } if (Directory.Exists(_tesseractData)) { var tesseractData = new TesseractData(_logger); _tesseractLanguage = tesseractData.GetTesseractLanguage(_tesseractData, values.Value.TesseractLanguage); if (string.IsNullOrEmpty(_tesseractLanguage)) { result = false; } } else { _logger.LogError($"Tesseract data directory '{_tesseractData}' doesn't exist."); result = false; } return(result); }
private (bool result, List <TrackOption> trackOptions) GetTrackOptions(Parsed <CommandLineOptions> values) { var result = true; var trackOptions = new List <TrackOption>(); var input = values.Value.Input; var output = values.Value.Output; var trackLanguage = values.Value.TrackLanguage; var track = values.Value.Track; _tesseractData = !string.IsNullOrEmpty(values.Value.TesseractData) ? values.Value.TesseractData : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tessdata"); if (!File.Exists(values.Value.Input)) { _logger.LogError($"Input file '{input}' doesn't exist."); result = false; } if (MkvUtilities.IsMkvFile(input)) { if (string.IsNullOrEmpty(trackLanguage) && !track.HasValue) { _logger.LogError("Track must be set when input is an mkv file."); result = false; } else if (!string.IsNullOrEmpty(trackLanguage)) { var runnerOptionLanguages = MkvUtilities.GetTracksByLanguage(input, trackLanguage, output); foreach (var item in runnerOptionLanguages) { trackOptions.Add(new TrackOption() { Input = input, Output = item.Output, Track = item.Track }); } } else { trackOptions.Add(new TrackOption() { Input = input, Output = output, Track = track }); } } else { var outputFilename = MkvUtilities.GetBaseDefaultOutputFilename(input, output) + ".srt"; trackOptions.Add(new TrackOption() { Input = input, Output = outputFilename, Track = null }); } if (Directory.Exists(_tesseractData)) { var tesseractData = new TesseractData(_logger); _tesseractLanguage = tesseractData.GetTesseractLanguage(_tesseractData, values.Value.TesseractLanguage); if (string.IsNullOrEmpty(_tesseractLanguage)) { result = false; } } else { _logger.LogError($"Tesseract data directory '{_tesseractData}' doesn't exist."); result = false; } return(result, trackOptions : trackOptions); }