예제 #1
0
        public void AddToQueue(MainForm inputMainForm)
        {
            Logger.Trace(System.Reflection.MethodBase.GetCurrentMethod().Name);

            mainForm = inputMainForm;

            if (MainForm.mainData.videoFileList.Count > 0)
            {
                ExtractVideoFileListToWorkOn();
                foreach (string item in videoFileList)
                {
                    QueueData.Job job = GenerateJob(item);
                    MainForm.queueData.jobList.Add(job);
                    // if the queue is currently running, add the jobs on the fly
                    if (MainForm.queueData.running)
                    {
                        MainForm.queueData.totalJobsToExec += 1;
                    }
                }
            }
        }
예제 #2
0
        private QueueData.Job GenerateJob(string file)
        {
            Logger.Trace(System.Reflection.MethodBase.GetCurrentMethod().Name);

            QueueData.Job job = new QueueData.Job();
            job.id                       = MainForm.queueData.GenerateNewUniqueId();
            job.fileFullPath             = file;
            job.fileFolder               = Path.GetDirectoryName(file);
            job.fileName                 = Path.GetFileName(file);
            job.fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
            job.percentage               = 0;
            job.jobStatus                = Properties.Resources.PendingJobLabel;
            job.jobExecuted              = false;
            job.command                  = MainForm.modelsData.modelList[MainForm.modelsData.lastModelUsed].command;

            job.command = job.command.Replace("||mkvmergePath||", MainForm.optionsData.mkvMergeLocation);

            // generate the outputfile with a unique name
            int    i = 0;
            string outputFileFullPath = "";

            //if for some reason the outputFileFormat is empty use the standard way
            if (String.IsNullOrEmpty(MainForm.optionsData.outputFileFormat))
            {
                outputFileFullPath = job.fileFolder + "\\" + job.fileNameWithoutExtension + ".mkv";
                while (File.Exists(outputFileFullPath))
                {
                    i++;
                    outputFileFullPath = job.fileFolder + "\\" + job.fileNameWithoutExtension + " (" + i + ")" + ".mkv";
                }
            }
            else // else use the user outputFileFormat pattern
            {
                outputFileFullPath = job.fileFolder + "\\" + MainForm.optionsData.outputFileFormat + ".mkv";
                outputFileFullPath = outputFileFullPath.Replace("||originalInputFile||", job.fileNameWithoutExtension);

                while (File.Exists(@"\\?\" + outputFileFullPath))
                {
                    i++;
                    outputFileFullPath = job.fileFolder + "\\" + MainForm.optionsData.outputFileFormat + " (" + i + ")" + ".mkv";
                    outputFileFullPath = outputFileFullPath.Replace("||originalInputFile||", job.fileNameWithoutExtension);
                }
            }


            job.command = job.command.Replace("||outputFileFullPath||", outputFileFullPath);
            job.command = job.command.Replace("||inputFileFolder||", job.fileFolder);
            job.command = job.command.Replace("||inputFileName||", job.fileName);
            job.command = job.command.Replace("||inputFileNameWithoutExtension||", job.fileNameWithoutExtension);

            // check if attachments are found and add it. the file needs to be in a folder named as the working file
            if (job.command.Contains("||attachments||"))
            {
                string attachmentsDirectory = job.fileFolder + "\\" + job.fileNameWithoutExtension;
                string attachmentsString    = "";

                if (Directory.Exists(attachmentsDirectory))
                {
                    string[] allFiles = Directory.GetFiles(attachmentsDirectory, "*.*", SearchOption.TopDirectoryOnly);
                    if (allFiles.Length != 0)
                    {
                        foreach (string item in allFiles)
                        {
                            // Check file dimension. Use only file with dimension > 0
                            FileInfo fi = new FileInfo(item);
                            if (fi.Length > 0)
                            {
                                attachmentsString += "--attach-file ^\"" + item + "^\" ";
                            }
                        }
                        job.command = job.command.Replace("||attachments||", attachmentsString);
                    }
                }
                else
                {
                    job.command = job.command.Replace("||attachments|| ", "");
                }
            }

            //if ||chapters|| is in model search the fileName_chapters.xml file and add to the cmdLine
            if (job.command.Contains("||chapters||"))
            {
                string capthersFile = job.fileFolder + "\\" + job.fileNameWithoutExtension + "_chapters.xml";
                if (File.Exists(capthersFile))
                {
                    string capthersString = " --chapters ^\"" + capthersFile + "^\" ";
                    job.command = job.command.Replace("||chapters||", capthersString);
                }
                else
                {
                    job.command = job.command.Replace("||chapters|| ", "");
                }
            }
            job.outputFileName = outputFileFullPath;
            return(job);
        }