private Boolean demuxChapters(SortedList<String, String[]> fileDetails, SortedList<String, Track[]> tracks) { LogBookController.Instance.addLogLine("Fetching MKV Chapters - Using MkvExtract", LogMessageCategories.Video); LogBookController.Instance.setInfoLabel(LanguageController.Instance.getLanguageString("demuxingMkvChapters")); XMLValidator xmlValidator = new XMLValidator(LocationManager.TempFolder + "chapters.xml"); int chapterFetchRetries = 0; while (!xmlValidator.Validate() && chapterFetchRetries++ < 5) { if (!xmlValidator.Validate() && File.Exists(LocationManager.TempFolder + "chapters.xml")) { LogBookController.Instance.addLogLine("Error in XML", LogMessageCategories.Video); } MiniProcess proc = new AttachmentProcess(); ProcessManager.Instance.Process = proc; proc.initProcess(); LogBookController.Instance.addLogLine("Attempt " + chapterFetchRetries + " to fetch chapters.", LogMessageCategories.Video); proc.setFilename(Path.Combine(mkvtoolnix.getInstallPath(), "mkvextract.exe")); string tempArg = "chapters \"" + fileDetails["fileName"][0] + "\""; proc.setArguments(tempArg); proc.startProcess(); if (proc.getAbandonStatus()) return false; string chapters = proc.getAdditionalOutput(); StreamWriter strChapters = new StreamWriter((LocationManager.TempFolder + "chapters.xml"), false); strChapters.Write(chapters); strChapters.Close(); } if (chapterFetchRetries >= 5) File.Delete(LocationManager.TempFolder + "chapters.xml"); return true; }
private Boolean demuxAttachments(SortedList<String, String[]> fileDetails, SortedList<String, Track[]> tracks) { if (fileDetails["skipattachments"][0] == "True") return true; LogBookController.Instance.addLogLine("Fetching MKV Attachments - Using MkvInfo", LogMessageCategories.Video); MiniProcess proc = new AttachmentProcess(); ProcessManager.Instance.Process = proc; LogBookController.Instance.setInfoLabel(LanguageController.Instance.getLanguageString("demuxingMkvAttachments")); proc.initProcess(); proc.setFilename(Path.Combine(mkvtoolnix.getInstallPath(), "mkvinfo.exe")); proc.setArguments("\"" + fileDetails["fileName"][0] + "\""); proc.startProcess(); string outputLog = proc.getAdditionalOutput(); string[] split = Regex.Split(outputLog, "\\+ File name: "); string temp; Track[] attachments = new Track[split.Length - 1]; char[] sep1 = { ':' }; char[] sep2 = { '\r' }; try { int start = outputLog.IndexOfAny(sep1, outputLog.IndexOf("Display width")) + 2; int end = outputLog.IndexOfAny(sep2, outputLog.IndexOf("Display width")); temp = outputLog.Substring(start, end - start); int width = int.Parse(temp); start = outputLog.IndexOfAny(sep1, outputLog.IndexOf("Display height")) + 2; end = outputLog.IndexOfAny(sep2, outputLog.IndexOf("Display height")); temp = outputLog.Substring(start, end - start); int height = int.Parse(temp); LogBookController.Instance.addLogLine("Number of attachments: " + (split.Length - 1).ToString(), LogMessageCategories.Video); if ((split.Length - 1) == 0) return true; for (int i = 1; i < split.Length; i++) attachments[i - 1] = new Attachment(LocationManager.TempFolder + split[i].Substring(0, split[i].IndexOf("\r\n")), split[i].Substring(0, split[i].IndexOf("\r\n"))); proc = new DefaultProcess("Demuxing Attachments", fileDetails["name"][0] + "AttachmentFetching"); proc.initProcess(); proc.setFilename(Path.Combine(mkvtoolnix.getInstallPath(), "mkvextract.exe")); string tempArg = "attachments \"" + fileDetails["fileName"][0] + "\""; for (int i = 1; i <= attachments.Length; i++) tempArg += " " + i.ToString() + ":\"" + attachments[i - 1].demuxPath + "\""; proc.setArguments(tempArg); int exitCode = proc.startProcess(); tracks.Add("attachments", attachments); return ProcessManager.hasProcessExitedCorrectly(proc, exitCode); } catch { LogBookController.Instance.addLogLine("Error demuxing attachments!", LogMessageCategories.Error); return false; } }