\r
using System.IO;\r
using System.Text.RegularExpressions;\r
+using System;\r
+using System.Globalization;\r
\r
namespace Handbrake.Parsing\r
{\r
public delegate void ScanProgressEventHandler(object Sender, int CurrentTitle, int TitleCount);\r
\r
/// <summary>\r
+ /// A delegate to handle encode progress updates // EXPERIMENTAL\r
+ /// </summary>\r
+ /// <param name="Sender">The object which raised the event</param>\r
+ /// <param name="CurrentTask">The current task being processed from the queue</param>\r
+ /// <param name="TaskCount">The total number of tasks in queue</param>\r
+ /// <param name="PercentComplete">The percentage this task is complete</param>\r
+ /// <param name="CurrentFps">The current encoding fps</param>\r
+ /// <param name="AverageFps">The average encoding fps for this task</param>\r
+ /// <param name="TimeRemaining">The estimated time remaining for this task to complete</param>\r
+ public delegate void EncodeProgressEventHandler(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining);\r
+\r
+ \r
+ /// <summary>\r
/// A simple wrapper around a StreamReader to keep track of the entire output from a cli process\r
/// </summary>\r
internal class Parser : StreamReader\r
{\r
get\r
{\r
- return this.m_buffer;\r
+ return m_buffer;\r
}\r
}\r
\r
/// </summary>\r
public event ScanProgressEventHandler OnScanProgress;\r
\r
+ #region Experimetnal Code\r
+ /// <summary>\r
+ /// Raised upon the catching of a "Scanning title # of #..." in the stream\r
+ /// </summary>\r
+ public event EncodeProgressEventHandler OnEncodeProgress;\r
+ #endregion\r
\r
/// <summary>\r
/// Default constructor for this object\r
/// </summary>\r
/// <param name="baseStream">The stream to parse from</param>\r
- public Parser(Stream baseStream)\r
- : base(baseStream)\r
+ public Parser(Stream baseStream) : base(baseStream)\r
{\r
- this.m_buffer = string.Empty;\r
+ m_buffer = string.Empty;\r
}\r
\r
public override string ReadLine()\r
{\r
string tmp = base.ReadLine();\r
\r
- this.m_buffer += tmp;\r
+ m_buffer += tmp;\r
Match m = Regex.Match(tmp, "^Scanning title ([0-9]*) of ([0-9]*)");\r
if (OnReadLine != null)\r
OnReadLine(this, tmp);\r
{\r
string tmp = base.ReadToEnd();\r
\r
- this.m_buffer += tmp;\r
+ m_buffer += tmp;\r
if (OnReadToEnd != null)\r
OnReadToEnd(this, tmp);\r
\r
return tmp;\r
}\r
+\r
+ /// <summary>\r
+ /// Pase the CLI status output (from standard output)\r
+ /// </summary>\r
+ public void readEncodeStatus()\r
+ {\r
+ CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");\r
+ string tmp = base.ReadLine();\r
+\r
+ Match m = Regex.Match(tmp, @"^Encoding: task ([0-9]*) of ([0-9]*), ([0-9]*\.[0-9]*) %( \(([0-9]*\.[0-9]*) fps, avg ([0-9]*\.[0-9]*) fps, ETA ([0-9]{2})h([0-9]{2})m([0-9]{2})s\))?");\r
+ if (m.Success && OnEncodeProgress != null)\r
+ {\r
+ int currentTask = int.Parse(m.Groups[1].Value);\r
+ int totalTasks = int.Parse(m.Groups[2].Value);\r
+ float percent = float.Parse(m.Groups[3].Value, culture);\r
+ float currentFps = m.Groups[5].Value == string.Empty ? 0.0F : float.Parse(m.Groups[5].Value, culture);\r
+ float avgFps = m.Groups[6].Value == string.Empty ? 0.0F : float.Parse(m.Groups[6].Value, culture);\r
+ TimeSpan remaining = TimeSpan.Zero;\r
+ if (m.Groups[7].Value != string.Empty)\r
+ {\r
+ remaining = TimeSpan.Parse(m.Groups[7].Value + ":" + m.Groups[8].Value + ":" + m.Groups[9].Value);\r
+ }\r
+ OnEncodeProgress(this, currentTask, totalTasks, percent, currentFps, avgFps, remaining);\r
+ }\r
+ }\r
}\r
}\r