public static void RipMovie(string PathToHandBrakeCLI, string HandBrakeQuality, string PathToVirtualCloneDrive, string DVDDriveLetter, string DVDID, string ISOFile, string OutputDirectory, string MovieServerDirectory, string PluginName, string PluginType, bool Log, StreamWriter swWriteLog) { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Path to HandBrake: " + PathToHandBrakeCLI); ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Path to Virtual Clone Drive: " + PathToVirtualCloneDrive); ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - DVD drive letter: " + DVDDriveLetter); ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - DVDID: " + DVDID); ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - ISOFile: " + ISOFile); ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Output directory: " + OutputDirectory); string DVDTitle = ""; string TitleNum = ""; string FileTitle = ""; string chapterStart = ""; string chapterEnd = ""; string vcdDrive = ""; //Reset Variables to original String OutputDirectory2 = OutputDirectory; String DVDID2 = DVDID; if (ISOFile != "") { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Processing temporary ISO file"); //UNMOUNT PREVIOUS ISO try { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Unmounting previous ISO file"); Process UVCD = new Process(); UVCD.StartInfo.FileName = PathToVirtualCloneDrive; UVCD.StartInfo.Arguments = "/u"; UVCD.StartInfo.CreateNoWindow = true; UVCD.StartInfo.UseShellExecute = false; UVCD.Start(); UVCD.WaitForExit(); } catch (Exception e) { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Error on OnMessage #2: " + e.ToString()); } //Load ISO try { //Launch Virtual CloneDrive if (ISOFile != "") { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Mounting current ISO file"); string ISOName = Path.GetFullPath(ISOFile); Process VCD = new Process(); VCD.StartInfo.FileName = PathToVirtualCloneDrive; VCD.StartInfo.Arguments = "\"" + ISOName + "\""; VCD.StartInfo.CreateNoWindow = true; VCD.StartInfo.UseShellExecute = false; VCD.Start(); VCD.WaitForExit(); //SEE IF VIRTUAL DRIVE EXISTS bool vDriveExists = false; while (vDriveExists == false) { ManagementClass mgmt = new ManagementClass("Win32_CDROMDrive"); ManagementObjectCollection objCol = mgmt.GetInstances(); foreach (ManagementObject obj in objCol) { string DriveID = obj.Properties["Id"].Value.ToString(); string DriveCaption = obj.Properties["Caption"].Value.ToString(); ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - CD-Rom info: " + DriveID + " " + DriveCaption); string[] virtualDriveIDs = { "elby", "clonedrive" }; foreach (string v in virtualDriveIDs) { if (DriveCaption.ToLower().Contains(v)) { vcdDrive = DriveID.Substring(0, 1); ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Virtual drive found: " + vcdDrive); vDriveExists = true; break; } } } } //WAIT FOR VIRTUAL CLONE DRIVE TO BECOME AVAILABLE while (!Directory.Exists(vcdDrive + ":\\VIDEO_TS")) { //WAIT FOR ISO TO LOAD AND BECOME AVAILABLE } } } catch (Exception e) { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Error on OnMessage #3: " + e.ToString()); } try { if (OutputDirectory2 == "") { OutputDirectory2 = Path.GetDirectoryName(ISOFile); } } catch (Exception e) { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Error on OnMessage #4: " + e.ToString()); } } //GET RUN TIMES FROM ALL TITLES AND CHAPTERS AND AVERAGE TO DETERMINE TARGET DVD thisDVD = new DVD(); List<Title> titlelist = new List<Title>(); Title LongestTitle = new Title(); try { //READ DVD AND WRITE TEXT FILE TO BE PARSED if (ISOFile != "") { DVDDriveLetter = vcdDrive; } GetDVDInfo(DVDDriveLetter + ":\\VIDEO_TS", PathToHandBrakeCLI, DVDDriveLetter, PluginName, PluginType, Log, swWriteLog); //GET TITLE LIST try { string DataDir = ToolBox.MeedioUtils.GetPluginDataDir(PluginName, PluginType); string dvdInfoPath = Path.Combine(DataDir, "dvdinfo.txt"); ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[Handbrake] - Parsing DVD..."); using (StreamReader srDVD = new StreamReader(dvdInfoPath, Encoding.GetEncoding("iso-8859-1"))) { thisDVD = DVD.Parse(srDVD); titlelist = thisDVD.Titles; ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[Handbrake] - Number of titles on DVD: " + titlelist.Count.ToString()); foreach (Title t in titlelist) { Title tempTitle = t; if (tempTitle.Duration > LongestTitle.Duration) LongestTitle = t; } } } catch (Exception e) { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Error parsing title info: " + e.ToString()); } } catch (Exception e) { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Error getting longest run time: " + e.ToString()); } //GET DVD TITLE DVDTitle = ToolBox.DVDWebUtils.DVDTitle(DVDID, Log, swWriteLog); if (DVDTitle.Contains(":")) { int Pos = DVDTitle.IndexOf(":"); String S2 = DVDTitle.Remove(Pos); DVDTitle = S2.Trim(); } ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - DVD title: " + DVDTitle); //Create Handbrake CLI try { chapterStart = "1"; chapterEnd = LongestTitle.Chapters.Count.ToString(); TitleNum = LongestTitle.TitleNumber.ToString(); FileTitle = ToolBox.StringFunctions.replaceIllegalCharacters(DVDTitle, " "); ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - File name: " + FileTitle); string root = PathToHandBrakeCLI.Remove(3); string pathwithoutRoot = PathToHandBrakeCLI.Substring(3, PathToHandBrakeCLI.Length - 3); string HBCLI = root + "\"" + pathwithoutRoot + "\" -i \"" + DVDDriveLetter + ":\\VIDEO_TS\" -t " + TitleNum + " -c " + chapterStart + "-" + chapterEnd + " -o \"" + OutputDirectory2 + "\\" + FileTitle + ".mkv\" -e x264 -E ac3 -p -q 0" + HandBrakeQuality + " -2 -T -x ref=3:mixed-refs:bframes=6:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=7:analyse=all:8x8dct:trellis=1:no-fast-pskip -D 1 -v "; ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Command line: " + HBCLI); if (!File.Exists(OutputDirectory2 + "\\" + FileTitle + ".mkv")) { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Output: " + OutputDirectory2 + "\\" + FileTitle + ".mkv"); //Launch Handbrake ProcessStartInfo HBinfo = new ProcessStartInfo("cmd", "/C " + HBCLI); Process hb = new Process(); hb.StartInfo = HBinfo; hb.StartInfo.CreateNoWindow = false; hb.StartInfo.UseShellExecute = false; hb.Start(); hb.WaitForExit(); } } catch (Exception e) { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Error on OnMessage #6: " + e.ToString()); } //UNMOUNT ISO try { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Unmounting ISO file"); Process UVCD = new Process(); UVCD.StartInfo.FileName = PathToVirtualCloneDrive; UVCD.StartInfo.Arguments = "/u"; UVCD.StartInfo.CreateNoWindow = true; UVCD.StartInfo.UseShellExecute = false; UVCD.Start(); UVCD.WaitForExit(); } catch (Exception e) { ToolBox.MeedioUtils.LogEntry(Log, swWriteLog, "[HandBrake] - Error on OnMessage: " + e.ToString()); } }
public static Title Parse(StringReader output) { Title thisTitle = new Title(); Match m = Regex.Match(output.ReadLine(), @"^\+ title ([0-9]*):"); // Match track number for this title if (m.Success) thisTitle.m_titleNumber = int.Parse(m.Groups[1].Value.Trim().ToString()); String testData = output.ReadLine(); // Get duration for this title m = Regex.Match(output.ReadLine(), @"^ \+ duration: ([0-9]{2}:[0-9]{2}:[0-9]{2})"); if (m.Success) thisTitle.m_duration = TimeSpan.Parse(m.Groups[1].Value); // Get resolution, aspect ratio and FPS for this title m = Regex.Match(output.ReadLine(), @"^ \+ size: ([0-9]*)x([0-9]*), aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps"); if (m.Success) { thisTitle.m_resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value)); thisTitle.m_aspectRatio = float.Parse(m.Groups[3].Value, Culture); } // Get autocrop region for this title m = Regex.Match(output.ReadLine(), @"^ \+ autocrop: ([0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)"); if (m.Success) thisTitle.m_autoCrop = new int[4] { int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value), int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value) }; thisTitle.m_chapters.AddRange(Chapter.ParseList(output)); thisTitle.m_audioTracks.AddRange(AudioTrack.ParseList(output)); thisTitle.m_subtitles.AddRange(Subtitle.ParseList(output)); return thisTitle; }