private List <PcsData> LoadMkv(string filename, int trackNumber, string output) { List <PcsData> result = null; using (var matroska = new MatroskaFile(filename)) { if (matroska.IsValid) { var pgsTracks = MkvUtilities.GetPgsSubtitleTracks(matroska); var track = (from t in pgsTracks where t.TrackNumber == trackNumber select t).FirstOrDefault(); if (track != null) { result = LoadSubtitles(matroska, track); } else { _logger.LogInformation($"Track {trackNumber} is not a PGS track."); ShowPgsTracks(filename, pgsTracks); } } else { _logger.LogInformation($"Invalid matroska file '{filename}'"); } } 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); }