/// <summary>Converts a string representation of a Feature into a Feature equivalent.</summary>
        /// <param name="s">A string containing a line of characters from the StdOut of eac3to</param>
        /// <returns></returns>
        public static Feature Parse(string s)
        {
            /*
            // Blu-Ray
            1) 00001.mpls, 00011.m2ts, 1:53:06
               - h264/AVC, 1080p24 /1.001 (16:9)
               - TrueHD, English, multi-channel, 48khz
               - TrueHD, French, multi-channel, 48khz
               - AC3, Spanish, multi-channel, 48khz
               - AC3, Thai, multi-channel, 48khz
               - AC3, Portuguese, multi-channel, 48khz
               - AC3, English, stereo, 48khz

            2) 00216.mpls, 0:50:19
               [99+100+101+102+103+104+105+106+114].m2ts
               - h264/AVC, 1080i60 /1.001 (16:9)
               - AC3, English, stereo, 48khz
            // HD-DVD
            1) Alternate_feature_01.EVO+Alternate_feature_02.EVO, 1:43:48
               "director"
               - VC-1, 1080p (16:9)
               - TrueHD, English, 5.1, 48khz

            2) Theatrical_feature_01.EVO+Theatrical_feature_02.EVO, 1:40:26
               "feature"
               - VC-1, 1080p (16:9)
               - TrueHD, English, 5.1, 48khz
               - E-AC3, French, 5.1, 48khz
               - E-AC3, Spanish, 5.1, 48khz

            3) default.EVO, 0:00:12
               "pickFeature"
               - VC-1, 1080p (16:9)
            */

            if (string.IsNullOrEmpty(s))
                throw new ArgumentNullException("s", "The string 's' cannot be null or empty.");

            Feature feature = new Feature();

            feature.Number = int.Parse(s.Substring(0, s.IndexOf(")")));
            feature.Name = s.Substring(s.IndexOf(")") + 1, s.IndexOf(",") - s.IndexOf(")") - 1).Trim();
            feature.Description = s.Substring(s.IndexOf(")") + 1).Trim();
            feature.Duration = TimeSpan.Parse(s.Substring(s.LastIndexOf(',') + 1).Trim());

            if (s.ToUpper().Contains(".M2TS,")) // Blu-ray
                foreach (string file in s.Substring(s.IndexOf(",") + 1, s.LastIndexOf(',') - s.IndexOf(",") - 1).Split("+".ToCharArray()))
                    feature.Files.Add(new File(file.Trim(), feature.Files.Count + 1));
            else if (s.ToUpper().Contains(".EVO,")) // HD-DVD
                foreach (string file in s.Substring(s.IndexOf(")") + 1, s.IndexOf(',') - s.IndexOf(")") - 1).Split("+".ToCharArray()))
                    feature.Files.Add(new File(file.Trim(), feature.Files.Count + 1));

            return feature;
        }
        void ProcessLine(string data)
        {
            // Analyzing|Processing|Progress
            // analyze: 100%
            if (Regex.IsMatch(data, @"^\b(analyze|process|progress)\b: [0-9]{1,3}%$", RegexOptions.Compiled))
            {
                if (backgroundWorker.IsBusy)
                    backgroundWorker.ReportProgress(int.Parse(Regex.Match(data, "[0-9]{1,3}").Value),
                        string.Format("{0} ({1}%)", data.Substring(0, data.IndexOf(":")), int.Parse(Regex.Match(data, "[0-9]{1,3}").Value)));

                return;
            }

            // Feature line
            // 2) 00216.mpls, 0:50:19
            else if (Regex.IsMatch(data, @"^[0-99]+\).+$", RegexOptions.Compiled))
            {
                try
                {
                    features.Add(Feature.Parse(data));
                }
                catch (Exception ex)
                {
                    WriteToLog(string.Format("{0}, {{1}}", ex.Message, data));
                }

                return;
            }

            // File input, Feature line
            // MKV, 1 video track, 1 audio track, 1 subtitle track, 1:47:18, 24p /1.001
            else if (Regex.IsMatch(data, @"^[A-Za-z0-9]{3,}, .*$", RegexOptions.Compiled))
            {
                if (InputSourceTextBox.Tag.ToString() == "File")
                {
                    try
                    {
                        Feature f = new Feature();
                        f.Name = System.IO.Path.GetFileNameWithoutExtension(InputSourceTextBox.Text);
                        f.Number = features.Count + 1;
                        f.Description = data;
                        f.Files.Add(new File(System.IO.Path.GetFileName(InputSourceTextBox.Text), 1));

                        if (data.Contains(":"))
                            f.Duration = TimeSpan.Parse(data.Substring(data.IndexOf(":") - 2, (data.LastIndexOf(":") + 3) - (data.IndexOf(":") - 2)).Trim());

                        features.Add(f);
                    }
                    catch (Exception ex)
                    {
                        WriteToLog(string.Format("{0}, {{1}}", ex.Message, data));
                    }
                }

                return;
            }

            // Feature name
            // "Feature Name"
            else if (Regex.IsMatch(data, "^\".+\"$", RegexOptions.Compiled))
            {
                if (InputSourceTextBox.Tag.ToString() == "File")
                {
                    features[features.Count - 1].Streams[features[features.Count - 1].Streams.Count - 1].Name = Extensions.CapitalizeAll(data.Trim("\" .".ToCharArray()));
                }
                else
                {
                    features[features.Count - 1].Name = Extensions.CapitalizeAll(data.Trim("\" .".ToCharArray()));
                }

                return;
            }

            // Stream line on feature listing
            // - h264/AVC, 1080p24 /1.001 (16:9)
            else if (Regex.IsMatch(data, @"^-.+$", RegexOptions.Compiled))
            {
                features[features.Count - 1].ToolTip.Add(data.Trim());
                return;
            }

            // Core information for audio stream
            // (core: DTS, 5.1 channels, 16 bits, 1509kbps, 48khz)
            else if (Regex.IsMatch(data, @"^\(core: .*\)$", RegexOptions.Compiled))
            {
                //TODO: Add core info to stream
                //features[features.Count - 1].Streams[features[features.Count - 1].Streams.Count - 1].ToolTip.Add(data);
                return;
            }

            // Stream embedded audio
            // (embedded: AC3, 5.1 channels, 640kbps, 48khz, dialnorm: -27dB)
            else if (Regex.IsMatch(data, @"^\(embedded: .+\)$", RegexOptions.Compiled))
            {
                //TODO: Add embedded info to stream
                //((Feature)FeatureDataGridView.SelectedRows[0].DataBoundItem).Streams.Count[Streams.Count - 1].ToolTip.Add(data);
                return;
            }

            // Playlist file listing
            // [99+100+101+102+103+104+105+106+114].m2ts (blueray playlist *.mpls)
            else if (Regex.IsMatch(data, @"^\[.+\].m2ts$", RegexOptions.Compiled))
            {
                foreach (string file in Regex.Match(data, @"\[.+\]").Value.Trim("[]".ToCharArray()).Split("+".ToCharArray()))
                    features[features.Count - 1].Files.Add(new File(file + ".m2ts", features[features.Count - 1].Files.Count + 1));

                return;
            }

            // Stream listing feature header
            // M2TS, 1 video track, 6 audio tracks, 9 subtitle tracks, 1:53:06
            // EVO, 2 video tracks, 4 audio tracks, 8 subtitle tracks, 2:20:02
            else if (Regex.IsMatch(data, @"^\b(M2TS|EVO|TS|VOB|MKV|MKA)\b, .+$", RegexOptions.Compiled))
            {
                WriteToLog(data);
                return;
            }

            // Stream line
            // 8: AC3, English, 2.0 channels, 192kbps, 48khz, dialnorm: -27dB
            else if (Regex.IsMatch(data, @"^[0-99]+:.+$", RegexOptions.Compiled))
            {
                if (InputSourceTextBox.Tag.ToString() == "File")
                {
                    try
                    {
                        features[features.Count - 1].Streams.Add(eac3to.Stream.Parse(data));
                    }
                    catch (Exception ex)
                    {
                        WriteToLog(ex.Message);
                        WriteToLog(ex.Source);
                        WriteToLog(ex.StackTrace);
                    }
                }
                else ((Feature)FeatureDataGridView.SelectedRows[0].DataBoundItem).Streams.Add(Stream.Parse(data));

                return;
            }

            // Information line
            // [a03] Creating file "audio.ac3"...
            else if (Regex.IsMatch(data, @"^\[.+\] .+\.{3}$", RegexOptions.Compiled))
            {
                WriteToLog(data);
                return;
            }

            // Creating file
            // Creating file "C:\1_1_chapter.txt"...
            else if (Regex.IsMatch(data, "^Creating file \".+\"\\.{3}$", RegexOptions.Compiled))
            {
                WriteToLog(data);
                return;
            }

            // Done
            // Done.
            else if (data.Equals("Done."))
            {
                WriteToLog(data);
                return;
            }

            #region Errors
            // Source file not found
            // Source file "x:\" not found.
            else if (Regex.IsMatch(data, "^Source file \".*\" not found.$", RegexOptions.Compiled))
            {
                //MessageBox.Show(data, "Source", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                WriteToLog(data);
                return;
            }

            // Format of Source file not detected
            // The format of the source file could not be detected.
            else if (data.Equals("The format of the source file could not be detected."))
            {
                //MessageBox.Show(data, "Source File Format", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                WriteToLog(data);
                return;
            }

            // Audio conversion not supported
            // This audio conversion is not supported.
            else if (data.Equals("This audio conversion is not supported."))
            {
                //MessageBox.Show(data, "Audio Conversion", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                WriteToLog(data);
                return;
            }
            #endregion

            // Unknown line
            else
            {
                WriteToLog(string.Format("{0}", data));
            }
        }
Example #3
0
        /// <summary>Converts a string representation of a Feature into a Feature equivalent.</summary>
        /// <param name="s">A string containing a line of characters from the StdOut of eac3to</param>
        /// <returns></returns>
        public static Feature Parse(string s)
        {
            /*
             * // Blu-Ray
             * 1) 00001.mpls, 00011.m2ts, 1:53:06
             * - h264/AVC, 1080p24 /1.001 (16:9)
             * - TrueHD, English, multi-channel, 48khz
             * - TrueHD, French, multi-channel, 48khz
             * - AC3, Spanish, multi-channel, 48khz
             * - AC3, Thai, multi-channel, 48khz
             * - AC3, Portuguese, multi-channel, 48khz
             * - AC3, English, stereo, 48khz
             *
             * 2) 00216.mpls, 0:50:19
             * [99+100+101+102+103+104+105+106+114].m2ts
             * - h264/AVC, 1080i60 /1.001 (16:9)
             * - AC3, English, stereo, 48khz
             * // HD-DVD
             * 1) Alternate_feature_01.EVO+Alternate_feature_02.EVO, 1:43:48
             * "director"
             * - VC-1, 1080p (16:9)
             * - TrueHD, English, 5.1, 48khz
             *
             * 2) Theatrical_feature_01.EVO+Theatrical_feature_02.EVO, 1:40:26
             * "feature"
             * - VC-1, 1080p (16:9)
             * - TrueHD, English, 5.1, 48khz
             * - E-AC3, French, 5.1, 48khz
             * - E-AC3, Spanish, 5.1, 48khz
             *
             * 3) default.EVO, 0:00:12
             * "pickFeature"
             * - VC-1, 1080p (16:9)
             *
             */

            if (string.IsNullOrEmpty(s))
            {
                throw new ArgumentNullException("s", "The string 's' cannot be null or empty.");
            }

            Feature feature = new Feature();

            feature.Number      = int.Parse(s.Substring(0, s.IndexOf(")")));
            feature.Name        = s.Substring(s.IndexOf(")") + 1, s.IndexOf(",") - s.IndexOf(")") - 1).Trim();
            feature.Description = s.Substring(s.IndexOf(")") + 1).Trim();
            feature.Duration    = TimeSpan.Parse(s.Substring(s.LastIndexOf(',') + 1).Trim());

            if (s.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Contains(".M2TS,")) // Blu-ray
            {
                foreach (string file in s.Substring(s.IndexOf(",") + 1, s.LastIndexOf(',') - s.IndexOf(",") - 1).Split("+".ToCharArray()))
                {
                    feature.Files.Add(new File(file.Trim(), feature.Files.Count + 1));
                }
            }
            else if (s.ToUpper(System.Globalization.CultureInfo.InvariantCulture).Contains(".EVO,")) // HD-DVD
            {
                foreach (string file in s.Substring(s.IndexOf(")") + 1, s.IndexOf(',') - s.IndexOf(")") - 1).Split("+".ToCharArray()))
                {
                    feature.Files.Add(new File(file.Trim(), feature.Files.Count + 1));
                }
            }

            return(feature);
        }