Example #1
0
        /// <summary>
        /// Dumps all media information about file into the log using either FFProbe or FFMPEG, does NOT analyze, parse or store the information
        /// </summary>
        /// <param name="fileName">Filename to dump information about</param>
        public static void DumpFileInformation(string fileName, JobStatus jobStatus, Log jobLog)
        {

            jobLog.WriteEntry("Dumping complete information about the file " + fileName, Log.LogEntryType.Debug);

            // Check if FFProbe exists, if not then fallback to FFMpeg
            string applicationPath = FFPROBE_APP_PATH;
            if (!File.Exists(Path.Combine(GlobalDefs.AppPath, FFPROBE_APP_PATH)))
            {
                jobLog.WriteEntry("FFProbe not found, switching to FFMpeg", Log.LogEntryType.Warning);
                applicationPath = FFMPEG_APP_PATH;
            }

            // -probesize 100M -analyzeduration 300M are important to identify broken audio streams in some files
            string parameters = " -probesize 100M -analyzeduration 300M -i " + Util.FilePaths.FixSpaces(fileName); // FFMPEG create the format for run the command

            Base mediaInfo = new Base(parameters, applicationPath, jobStatus, jobLog);
            mediaInfo.Run(); // Dump it
        }
Example #2
0
        public bool Run()
        {
            string translatedCommand = "";

            if (commandPath == "")
            {
                _jobLog.WriteEntry(this, "No custom commands found", Log.LogEntryType.Information);
                return true; // not a critical failure
            }

            // Get the path if it is an absolute path, if it's relative we start in the MCEBuddy directory
            if (!Path.IsPathRooted(commandPath))
                commandPath = Path.Combine(GlobalDefs.AppPath, commandPath); // Relative path starts with MCEBuddy path

            if ((hangPeriod < 0) || (!File.Exists(commandPath)))
            {
                if (hangPeriod < 0)
                    _jobLog.WriteEntry(this, _prefix + "HangPeriod NOT specified!", Log.LogEntryType.Error);
                else
                    _jobLog.WriteEntry(this, _prefix + "Path does NOT exist!", Log.LogEntryType.Error);

                _jobLog.WriteEntry(this, "Invalid custom command parameters" + " \n" + _prefix + "Path = " + commandPath + " \n" + _prefix + "Parameters = " + commandParameters + " \n" + _prefix + "HangPeriod = " + hangPeriod.ToString(System.Globalization.CultureInfo.InvariantCulture) + " \n" + _prefix + "Critical = " + customCommandCritical.ToString() + " \n" + _prefix + "UISession = " + customCommandUISession.ToString() + " \n" + _prefix + "ShowWindow = " + customCommandShowWindow.ToString() + " \n" + _prefix + "ExitCodeCheck = " + customCommandExitCodeCheck.ToString(), Log.LogEntryType.Error);
                
                if (customCommandCritical)
                    _jobStatus.ErrorMsg = "Invalid custom command parameters"; // Set an error message on if we are failing the conversion
                
                return !customCommandCritical; // return the opposite of the critical (if it's true then return false)
            }

            // Translate the user commands
            if (!String.IsNullOrWhiteSpace(commandParameters)) // Check if there was a custom command parameter
            {
                translatedCommand = UserCustomParams.CustomParamsReplace(commandParameters, _workingPath, _destinationPath, _convertedFile, _sourceFile, _remuxFile, _edlFile, _srtFile, _profile, _taskName, _metaData, _jobLog);
                if (String.IsNullOrWhiteSpace(translatedCommand))
                {
                    _jobLog.WriteEntry(this, "Invalid custom command. Error", (customCommandCritical ? Log.LogEntryType.Error : Log.LogEntryType.Warning));
                    if (customCommandCritical)
                        _jobStatus.ErrorMsg = Localise.GetPhrase("Invalid custom command"); // Set an error message on if we are failing the conversion
                    return !customCommandCritical; // return the opposite of the critical (if it's true then return false)
                }
            }

            try
            {
                baseCommand = new Base(customCommandShowWindow, translatedCommand, commandPath, customCommandUISession, _jobStatus, _jobLog); // send the absolute command path and by default success is true until process is terminated and show Window
            }
            catch (FileNotFoundException)
            {
                _jobLog.WriteEntry(this, "Invalid custom command path" + " " + _prefix + "Path = " + commandPath, (customCommandCritical ? Log.LogEntryType.Error : Log.LogEntryType.Warning));
                if (customCommandCritical)
                    _jobStatus.ErrorMsg = "Invalid custom command path"; // Set an error message on if we are failing the conversion
                return !customCommandCritical; // return the opposite of the critical (if it's true then return false)
            }

            // Set the hang detection period
            baseCommand.HangPeriod = hangPeriod;

            _jobLog.WriteEntry(this, "About to run custom command with parameters:" + " \n" + _prefix + "Path = " + commandPath + " \n" + _prefix + "Parameters = " + commandParameters + " \n" + _prefix + "HangPeriod = " + hangPeriod.ToString(System.Globalization.CultureInfo.InvariantCulture) + " \n" + _prefix + "Critical = " + customCommandCritical.ToString() + " \n" + _prefix + "UISession = " + customCommandUISession.ToString() + " \n" + _prefix + "ShowWindow = " + customCommandShowWindow.ToString() + " \n" + _prefix + "ExitCodeCheck = " + customCommandExitCodeCheck.ToString(), Log.LogEntryType.Debug);

            // Run the custom command
            baseCommand.Run();

            // Check for hang/termination
            if (!baseCommand.Success)
            {
                _jobLog.WriteEntry(this, "Custom command hung, process was terminated", (customCommandCritical ? Log.LogEntryType.Error : Log.LogEntryType.Warning));
                
                if (customCommandCritical)
                    _jobStatus.ErrorMsg = "Custom command hung, process was terminated";
                else
                    _jobStatus.ErrorMsg = ""; // Clear any errors

                return !customCommandCritical; // return the opposite, see above
            }

            // Check if exit code not equal to0 indicating failure, if required
            if (customCommandExitCodeCheck && (baseCommand.ExitCode != 0))
            {
                _jobStatus.ErrorMsg = "Custom command failed with exit code " + baseCommand.ExitCode.ToString();
                _jobLog.WriteEntry(this, "Custom command failed with Exit Code " + baseCommand.ExitCode.ToString(), (customCommandCritical ? Log.LogEntryType.Error : Log.LogEntryType.Warning));
                return false; // failed
            }

            return true;
        }