Ejemplo n.º 1
0
        /// <summary>
        /// Deprecated. There is no use for an xml file that holds fileList information.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection to serialize into XML.</param>
        /// <param name="processor">The Processor object to get the file objects from.</param>
        public void makeXML(FileObjectCollection fileList, Analyze processor)
        {
            XmlSerializer xmlWrite = new XmlSerializer(typeof(FileObjectCollection));

            string fileListName = fileList.name + ".xml";

            FileStream xmlfile = File.Create(Path.Combine(outputPath, fileListName));

            xmlWrite.Serialize(xmlfile, fileList);

            xmlfile.Close();
        }
Ejemplo n.º 2
0
/// <summary>
/// Creates an SuidLister object and returns it for the calling program.
/// The SuidLister object that is created here can be reused.
/// </summary>
/// <param name="fileList">The FileObjectCollection processed by InfoDump.</param>
/// <returns>The SuidLister with the list of all SUIDs present.</returns>
        public static SuidLister getSuid(FileObjectCollection fileList)
        {
            SuidLister suidLister = new SuidLister();

            foreach (FileObject file in fileList.fileList)
            {
                //to change - actual suid;
                //string suids = "suid";
                // done

                suidLister.addSuid(file);
            }

            //returns suidLister object
            return(suidLister);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates an SuidLister object and returns it for the calling program.
        /// The SuidLister object that is created here can be reused.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection processed by InfoDump.</param>
        /// <returns>The SuidLister with the list of all SUIDs present.</returns>
        public static SuidLister getSuid(FileObjectCollection fileList)
        {
            SuidLister suidLister = new SuidLister();

              foreach (FileObject file in fileList.fileList)
              {

              //to change - actual suid;
              //string suids = "suid";
              // done

            suidLister.addSuid(file);

              }

            //returns suidLister object
              return suidLister;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Deprecated. Creates a script that executes mkvmerge commands to merge analyzed files
        /// </summary>
        /// <param name="fileList">The processed FileObjectCollection.</param>
        /// <param name="processor">The Analyze object</param>
        /// <param name="outputPathArg">Optional. Pass a different output path for the script.</param>
        public void makeFile(FileObjectCollection fileList, Analyze processor, string outputPathArg = null)
        {
            if (outputPathArg != null)
              {
            outputPath = outputPathArg;
              }
              else
            if (Config.Configure.sourceOutputFolder)
              outputPath = Path.Combine(fileList.folderPath, Config.Configure.exportfilename);
            else
              outputPath = Path.Combine(outputPath, Config.Configure.exportfilename);

              StringBuilder makeFileContent = new StringBuilder();

              if (Config.Configure.diagnoseMkvinfoDump | Config.Configure.diagnoseChapterinfoDump)
            Directory.CreateDirectory(dumpPath);

              foreach (FileObject file in fileList.fileList)
              {

            List<string> timeCodeList = new List<string>();
            List<string> delArgumentList = new List<string>();
            List<string> mergeArgumentList = new List<string>();
            List<string> chapterInfo = new List<string>();

            /*
             * Diagnostic purposes only
             * */
            if (Config.Configure.diagnoseMkvinfoDump)
              using (StreamWriter writer = new StreamWriter(Path.Combine(dumpPath, file.filenameNoExtension + "_mkvinfo.txt")))
              {
            writer.Write(file.mkvInfo);
              }

            /*
             * Main process
             * */
            if (file.mergeArgument.Count > 1)
            {

              foreach (MergeArgument merge in file.mergeArgument)
              {

            if (merge.isExternalSuid)
              mergeArgumentList.Add("\"" + merge.fullPath + "\"");
            else
            {
              if (file.splitCount > 1)
                mergeArgumentList.Add("\"" + merge.fileName + "\"");
              else
                mergeArgumentList.Add("\"" + merge.originalFullPath + "\"");

            }

              }

              foreach (TimeCode time in file.timeCode)
              {
            timeCodeList.Add(time.timeCode);
              }

              foreach (DelArgument del in file.delArgument)
              {
            delArgumentList.Add("\"" + del.fileName + "\"");
              }

              foreach (ChapterAtom chapter in file.chapterAtom)
              {
            chapterInfo.Add(chapter.chapterInfo);
              }

              string[] timeCode = timeCodeList.ToArray();
              string[] delArgument = delArgumentList.ToArray();
              string[] mergeArgument = mergeArgumentList.ToArray();
              string[] chaptersInfo = chapterInfo.ToArray();

              string tempFileName = "\"" + Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + ".mkv\"";
              string newFileName = "\"output\\" + Config.Configure.newfileprefix + file.filenameNoExtension + Config.Configure.newfilesuffix + ".mkv\"";
              string originalFileName = "\"" + file.fullpath + "\"";

              if (file.shouldJoin)
              {

            doMakeFile = true;
            makeFileContent.AppendLine("::" + file.filename);

            if (file.splitCount > 1)
            {
              makeFileContent.AppendLine("mkvmerge --no-chapters --split timecodes:" + String.Join(",", timeCode) + " -o " + tempFileName + " " + originalFileName);
            }

            makeFileContent.AppendLine("mkvmerge --no-chapters -o " + newFileName + " " + String.Join(" +", mergeArgument) + "\r\n");
            makeFileContent.AppendLine("DEL /Q " + String.Join(" ", delArgument) + "\r\n");

              }

              if (Config.Configure.diagnoseChapterinfoDump)
            using (StreamWriter writer = new StreamWriter(Path.Combine(dumpPath, file.filenameNoExtension + "_chaptersinfo.txt")))
            {
              writer.WriteLine(String.Join("\n", chaptersInfo));
            }

            }

              }

              if (doMakeFile)
              {
            using (StreamWriter writer = new StreamWriter(outputPath))
            {
              writer.WriteLine("@echo off\r\ncls\r\n\r\npushd \"%~dp0\"\r\nif not exist output mkdir output\r\n");
              writer.Write(makeFileContent);
            }
            Analyze.outputGroups.Add(outputPath);
              }
              else
              {

              }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Deprecated. There is no use for an xml file that holds fileList information.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection to serialize into XML.</param>
        /// <param name="processor">The Processor object to get the file objects from.</param>
        public void makeXML(FileObjectCollection fileList, Analyze processor)
        {
            XmlSerializer xmlWrite = new XmlSerializer(typeof(FileObjectCollection));

              string fileListName = fileList.name + ".xml";

              FileStream xmlfile = File.Create(Path.Combine(outputPath, fileListName));

              xmlWrite.Serialize(xmlfile, fileList);

              xmlfile.Close();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Processes files to create File Objects for the main tasks of this program.
        /// Every tasks are denoted on each comment lines inside the method.
        /// </summary>
        /// <param name="list">The list that contains the fullpaths of the actual files.</param>
        /// <param name="listname">Name for the FileObjectCollection to be created.</param>
        public void AnalyzeList(List <string> list, string listname = "Various Files")
        {
            FileObjectCollection fileList   = new FileObjectCollection();
            TrackLister          tracklist  = new TrackLister();
            MakeFile             makeFile   = new MakeFile();
            ChapterGenerator     chapterGet = new ChapterGenerator();

            //ProgressState progressState = new ProgressState();

            //fileList.folderPath = path; //Deprecated
            fileList.name = listname; //Deprecated

            progressState.listName = fileList.name;

            analyzeProgress       = 1;
            analyzeProcessPercent = 0;

            foreach (string s in list)
            {
                FileObject file = new FileObject(s);

                analyzeProcessPercent         = analyzeProgress.ToPercentage(list.Count);
                progressState.progressPercent = analyzeProcessPercent;
                progressState.fileName        = file.filename;
                Analyze.backgroundWorker.ReportProgress(progressArg, progressState);

                //Routine after splitting
                //Checks if current backgroundWorker operation is cancelled
                //Stops this program if true
                if (Analyze.backgroundWorker.CancellationPending)
                {
                    return;
                }

                try
                {
                    file = InfoDumper.infoDump(file);
                    if (Program.hasFFmpeg)
                    {
                        file = InfoDumper.ffInfoDump(file);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error:\r\n\r\n" + ex.Message, "Error");
                }

                progressState.progressDetail = "Dumping MKV info...";

                Analyze.backgroundWorker.ReportProgress(progressArg, progressState);

                file = chapterGet.chapterDump(file);
                if (!String.IsNullOrEmpty(file.ffInfo))
                {
                    file = chapterGet.mediaDump(file);
                }

                if (!Config.Configure.includeMkvInfoOnFiles)
                {
                    file.mkvInfo = null;
                }

                if (!Config.Configure.includeMediaInfoOnFiles)
                {
                    file.ffInfo = null;
                }

                fileList.addFile(file);

                //For Diagnoses purposes only
                if (Config.Configure.diagnose >= 30)
                {
                    Console.WriteLine("Chapter Atom count: {0}\n", file.chapterAtom.Count, file.mkvInfo);

                    foreach (ChapterAtom chapter in file.chapterAtom)
                    {
                        {
                            Console.WriteLine("File name: {0}\nChapter Number: {2}\nTime Start: {3}\nTime End: {4}\nSuid: {5}\n",
                                              file.filename,
                                              chapter.chapterInfo,
                                              chapter.chapterNum,
                                              chapter.timeStart,
                                              chapter.timeEnd,
                                              chapter.suid);
                        }
                    }
                }

                progressState.progressDetail = "Getting chapters' info...";

                Analyze.backgroundWorker.ReportProgress(progressArg, progressState);


                analyzeProgress++;
            }


            SuidLister suidList = getSuid(fileList);

            progressState.progressDetail = "Creating SUID list...";
            Analyze.backgroundWorker.ReportProgress(progressArg, progressState);

            fileList = tracklist.arrangeTrack(fileList, suidList, this);

            progressState.progressDetail = "Arranging new tracklist for every file...";
            Analyze.backgroundWorker.ReportProgress(progressArg, progressState);

            //For Diagnostic purposes only
            if (Config.Configure.diagnose >= 30)
            {
                foreach (Suid suid in suidList.suidList)
                {
                    {
                        Console.WriteLine("SUID filename: " + suid.fileName);
                        Console.WriteLine("SUID: " + suid.suid);
                        Console.WriteLine("\n");
                    }
                }

                Console.WriteLine("fileList.fileList.Count: " + fileList.fileList.Count + "\n");

                foreach (FileObject file in fileList.fileList)
                {
                    //Console.WriteLine("Merge Argument count: {0}\n", file.mergeArgument.Count);

                    foreach (MergeArgument merge in file.mergeArgument)
                    {
                        Console.WriteLine("Merge Argument:\nFile name: {0}\nTime Code: {1}\nFile Argument: {2}\nChapter Number: {3}\n",
                                          file.filename,
                                          merge.timeCode,
                                          merge.fileName,
                                          merge.chapterNum);
                    }

                    foreach (TimeCode time in file.timeCode)
                    {
                        Console.WriteLine("Time Code Argument: {0}\n", time.timeCode);
                    }

                    foreach (DelArgument del in file.delArgument)
                    {
                        Console.WriteLine("Del Argument: {0}\n", del.fileName);
                    }
                }
            }

            fileLists.Add(fileList);

            if (Config.Configure.doMakeXml)
            {
                makeFile.makeFile(fileList, this);

                progressState.progressDetail = "Dumping XML file...";
                Analyze.backgroundWorker.ReportProgress(progressArg, progressState);
            }

            if (Config.Configure.doMakeScript)
            {
                makeFile.makeXML(fileList, this);

                progressState.progressDetail = "Creating Merge Script...";
                Analyze.backgroundWorker.ReportProgress(progressArg, progressState);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Processes files to create File Objects for the main tasks of this program.
        /// Every tasks are denoted on each comment lines inside the method.
        /// </summary>
        /// <param name="list">The list that contains the fullpaths of the actual files.</param>
        /// <param name="listname">Name for the FileObjectCollection to be created.</param>
        public void AnalyzeList(List<string> list, string listname = "Various Files")
        {
            FileObjectCollection fileList = new FileObjectCollection();
              TrackLister tracklist = new TrackLister();
              MakeFile makeFile = new MakeFile();
              ChapterGenerator chapterGet = new ChapterGenerator();
              //ProgressState progressState = new ProgressState();

              //fileList.folderPath = path; //Deprecated
              fileList.name = listname; //Deprecated

              progressState.listName = fileList.name;

              analyzeProgress = 1;
              analyzeProcessPercent = 0;

              foreach (string s in list)
              {

            FileObject file = new FileObject(s);

            analyzeProcessPercent = analyzeProgress.ToPercentage(list.Count);
            progressState.progressPercent = analyzeProcessPercent;
            progressState.fileName = file.filename;
            Analyze.backgroundWorker.ReportProgress(progressArg, progressState);

              //Routine after splitting
              //Checks if current backgroundWorker operation is cancelled
              //Stops this program if true
            if (Analyze.backgroundWorker.CancellationPending)
            {
              return;
            }

            try
            {
              file = InfoDumper.infoDump(file);
              if (Program.hasFFmpeg) file = InfoDumper.ffInfoDump(file);
            }
            catch (Exception ex)
            {
              MessageBox.Show("Error:\r\n\r\n" + ex.Message, "Error");
            }

            progressState.progressDetail = "Dumping MKV info...";

            Analyze.backgroundWorker.ReportProgress(progressArg, progressState);

            file = chapterGet.chapterDump(file);
            if (!String.IsNullOrEmpty(file.ffInfo)) file = chapterGet.mediaDump(file);

            if (!Config.Configure.includeMkvInfoOnFiles)
              file.mkvInfo = null;

            if (!Config.Configure.includeMediaInfoOnFiles)
              file.ffInfo = null;

            fileList.addFile(file);

              //For Diagnoses purposes only
            if (Config.Configure.diagnose >= 30)
            {
              Console.WriteLine("Chapter Atom count: {0}\n", file.chapterAtom.Count, file.mkvInfo);

              foreach (ChapterAtom chapter in file.chapterAtom)
              {
            {
              Console.WriteLine("File name: {0}\nChapter Number: {2}\nTime Start: {3}\nTime End: {4}\nSuid: {5}\n",
                file.filename,
                chapter.chapterInfo,
                chapter.chapterNum,
                chapter.timeStart,
                chapter.timeEnd,
                chapter.suid);

            }

              }

            }

            progressState.progressDetail = "Getting chapters' info...";

            Analyze.backgroundWorker.ReportProgress(progressArg, progressState);

            analyzeProgress++;
              }

              SuidLister suidList = getSuid(fileList);

              progressState.progressDetail = "Creating SUID list...";
              Analyze.backgroundWorker.ReportProgress(progressArg, progressState);

              fileList = tracklist.arrangeTrack(fileList, suidList, this);

              progressState.progressDetail = "Arranging new tracklist for every file...";
              Analyze.backgroundWorker.ReportProgress(progressArg, progressState);

            //For Diagnostic purposes only
              if (Config.Configure.diagnose >= 30)
              {
            foreach (Suid suid in suidList.suidList)
            {

              {
            Console.WriteLine("SUID filename: " + suid.fileName);
            Console.WriteLine("SUID: " + suid.suid);
            Console.WriteLine("\n");
              }
            }

            Console.WriteLine("fileList.fileList.Count: " + fileList.fileList.Count + "\n");

            foreach (FileObject file in fileList.fileList)
            {

              //Console.WriteLine("Merge Argument count: {0}\n", file.mergeArgument.Count);

              foreach (MergeArgument merge in file.mergeArgument)
              {

            Console.WriteLine("Merge Argument:\nFile name: {0}\nTime Code: {1}\nFile Argument: {2}\nChapter Number: {3}\n",
                file.filename,
                merge.timeCode,
                merge.fileName,
                merge.chapterNum);

              }

              foreach (TimeCode time in file.timeCode)
              {
            Console.WriteLine("Time Code Argument: {0}\n", time.timeCode);
              }

              foreach (DelArgument del in file.delArgument)
              {
            Console.WriteLine("Del Argument: {0}\n", del.fileName);
              }

            }
              }

              fileLists.Add(fileList);

              if (Config.Configure.doMakeXml)
              {
            makeFile.makeFile(fileList, this);

            progressState.progressDetail = "Dumping XML file...";
            Analyze.backgroundWorker.ReportProgress(progressArg, progressState);
              }

              if (Config.Configure.doMakeScript)
              {
            makeFile.makeXML(fileList, this);

            progressState.progressDetail = "Creating Merge Script...";
            Analyze.backgroundWorker.ReportProgress(progressArg, progressState);
              }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Main Convert process.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection to process.</param>
        public void Convert(FileObjectCollection fileList, int fileListPercent = 100)
        {
            InitializeConfiguration();

            ProgressState progressState = new ProgressState();

            progressState.listName = fileList.name;

            progress       = 1;
            processPercent = 0;

            if (!Config.Configure.sourceOutputFolder)
            {
                outputPath = Program.defaultPath;
                if (!Directory.Exists(Path.Combine(outputPath, "converted")))
                {
                    Directory.CreateDirectory(Path.Combine(outputPath, "converted"));
                }
            }

            //Main Loop
            foreach (FileObject file in fileList.fileList)
            {
                //Set Required Variables
                string ffmpegArgs        = "";
                string fileVfilter       = "";
                string fileVfilterArg    = "";
                string fileFFmpegOptions = ffmpegOptions;

                List <string> fileVfilters = new List <string>();

                List <string> fileFilterChains = new List <string>();

                foreach (string vfilteritem in vfilters)
                {
                    fileVfilters.Add(vfilteritem);
                }

                //Escape Filter Patterns
                string firstLevel  = @"([:\\'])";
                string secondLevel = @"([\[\],;\\'])";

                //Input/Output programmatic patterns
                string custInputPat  = @"\(inputfile\)";
                string custOutputPat = @"\(outputname\)";

                //Progress Reporting
                progressState.fileName = file.filename;

                processPercent = progress.ToPercentage(fileList.fileList.Count);
                progressState.progressPercent = processPercent;

                progressState.progressDetail = "Building conversion arguments...";
                this.backgroundWorker.ReportProgress(fileListPercent, progressState);

                if (Config.Configure.sourceOutputFolder)
                {
                    outputPath = file.directoryname;
                }

                if (!Directory.Exists(Path.Combine(outputPath, "converted")))
                {
                    Directory.CreateDirectory(Path.Combine(outputPath, "converted"));
                }

                //Output File Argument
                string outputFile = outputPath + "\\converted\\" + ConvConfig.newfileprefix + file.filenameNoExtension + ConvConfig.newfilesuffix;

                //Fix_subtitle_duration
                if (ConvConfig.fixsubduration)
                {
                    ffmpegArgs += @"-fix_sub_duration ";
                }

                //Subtitles
                //Subfilter
                if (ConvConfig.useSubFilter)
                {
                    //Escape any special characters
                    string fileitem = file.fullpath;
                    fileitem = Regex.Replace(fileitem, firstLevel, m =>
                    {
                        var escapedChars = m.Groups[1].Value;
                        return(@"\" + escapedChars);
                    });

                    fileitem = Regex.Replace(fileitem, secondLevel, n =>
                    {
                        var escapedChars = n.Groups[1].Value;
                        return(@"\" + escapedChars);
                    });

                    fileVfilter = @"subtitles=" + fileitem + @":si=" + ConvConfig.subindex.ToString();
                    fileVfilters.Add(fileVfilter);
                }



                //Video Filter
                //Custom Video Filter
                if (!String.IsNullOrWhiteSpace(ConvConfig.customvfilter))
                {
                    fileVfilterArg = ConvConfig.customvfilter;
                }
                else
                {
                    //filefilterchain.Add(String.Join(",", vfilters.ToArray()));

                    fileVfilterArg = String.Join(", ", fileVfilters.ToArray());
                }

                //Diagnostic purposes only
                //fileVfilterArg = "subtitles=D:\\backup\\anime_archive\\[Coalgirls]_Ookami-san,_to;_Shichinin_no_'Nakama-tachi'_(1280x720_Blu-ray_FLAC)\\[Coalgirls]_Ookami-san_to_Shichinin_no_Nakama-tachi_01_(1280x720_Blu-ray_FLAC)_[F9495BFE].mkv:si=0";

                if (!String.IsNullOrWhiteSpace(fileVfilterArg))
                {
                    fileVfilterArg     = " -vf \"" + fileVfilterArg + "\""; //Placeholder
                    fileFFmpegOptions += fileVfilterArg;
                }

                //Custom ffmpeg options
                if (!String.IsNullOrWhiteSpace(ConvConfig.customffmpegarg))
                {
                    string customData = ConvConfig.customffmpegarg;

                    //Replace (inputfile) and (outputname) with input and output variables accordingly.
                    customData = Regex.Replace(customData, custInputPat, m => { return(file.fullpath); });
                    customData = Regex.Replace(customData, custOutputPat, m => { return(outputFile); });

                    ffmpegArgs = customData;
                }
                else
                {
                    //Set final ffmpegArgs
                    ffmpegArgs += "-i \"" + file.fullpath + "\"" + fileFFmpegOptions + " \"" + outputFile + "." + ConvConfig.format + "\"";
                }

                currentCommand = ffmpegArgs;

                /*
                 * Routine before converting
                 * Checks if current backgroundWorker operation is cancelled
                 * Stops this program if true
                 *
                 * Process cancelling should be changed as this currently waits for previous conversion to complete;
                 * Conversion can take a lot of time for cancellation to wait.
                 *
                 * Native threading would be used.
                 *
                 * */
                if (this.backgroundWorker.CancellationPending)
                {
                    return;
                }

                if (ConvConfig.showCommands)
                {
                    Program.Message("Current command:\r\n\r\n" + currentCommand, "Diagnostics");
                }

                //Main process
                ProcessStartInfo convertProcess = new ProcessStartInfo();

                convertProcess.FileName  = Program.ffmpegExe;
                convertProcess.Arguments = ffmpegArgs;

                convertProcess.UseShellExecute = false;

                if (!Config.Configure.ConvertConfigure.showFFmpegWindow) //Added check for diagnostics
                {
                    convertProcess.CreateNoWindow        = true;
                    convertProcess.WindowStyle           = ProcessWindowStyle.Hidden;
                    convertProcess.RedirectStandardInput = true; //Preparation for an eminent interactive ffmpeg thread.
                }
                else
                {
                    convertProcess.CreateNoWindow = false;
                }
                convertProcess.WorkingDirectory = file.directoryname;

                progressState.progressDetail = "Converting...";
                this.backgroundWorker.ReportProgress(fileListPercent, progressState);

                using (Process process = Process.Start(convertProcess))
                {
                    process.WaitForExit();
                }


                //If External subs are set to true.
                if (ConvConfig.externalsubs)
                {
                    ffmpegArgs = "-i \"" + file.fullpath + "\" \"" + outputFile + "." + ConvConfig.externalsubsext + "\"";

                    currentCommand = ffmpegArgs;

                    if (ConvConfig.showCommands)
                    {
                        Program.Message("Current command:\r\n\r\n" + currentCommand, "Diagnostics");
                    }

                    convertProcess.Arguments = ffmpegArgs;

                    progressState.progressDetail = "Creating external subtitles...";
                    this.backgroundWorker.ReportProgress(fileListPercent, progressState);

                    using (Process process = Process.Start(convertProcess))
                    {
                        process.WaitForExit();
                    }
                }

                progress++;
                //End of Main process
            }

            if (!Analyze.outputGroups.Contains(outputPath))
            {
                Analyze.outputGroups.Add(outputPath + "\\converted");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Processes files to create File Objects for the main tasks of this program.
        /// Every tasks are denoted on each comment lines inside the method.
        /// </summary>
        /// <param name="list">The list that contains the fullpaths of the actual files.</param>
        /// <param name="listname">Name for the FileObjectCollection to be created.</param>
        /// <param name="processor">The Analyze object for progression report.</param>
        /// <param name="path">The path used as a working directory merge commands.</param>
        /// <param name="totalArguments">Optional. For progress report. The total number of lists to process.</param>
        public void processList(List<string> list, string listname, Analyze processor, string path = "C:\\", int totalArguments = 0)
        {
            FileObjectCollection fileList = new FileObjectCollection();
              TrackLister tracklist = new TrackLister();
              MakeFile makeFile = new MakeFile();
              ChapterGenerator chapterGet = new ChapterGenerator();
              ProgressState progressState = new ProgressState();

              fileList.folderPath = path;
              fileList.name = listname;

              progressState.listName = fileList.name;

              progress = 1;
              processPercent = 0;

              foreach (string s in list)
              {

            progressState.progressDetail = "Creating file entry...";

            Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

            FileObject file = new FileObject(s);

            processPercent = progress.ToPercentage(list.Count);
            progressState.progressPercent = processPercent;
            progressState.fileName = file.filename;
            Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

              //Routine after splitting
              //Checks if current backgroundWorker operation is cancelled
              //Stops this program if true
            if (Analyze.backgroundWorker.CancellationPending)
            {
              return;
            }

            if (file.extension == ".mkv")
            {
              try
              {
            file = InfoDumper.infoDump(file);
              }
              catch (Exception ex)
              {
            Program.Message("Error:\r\n\r\n" + ex.Message, "Error");
              }

              progressState.progressDetail = "Dumping MKV info...";

              Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

              file = chapterGet.chapterDump(file);

              if (!Config.Configure.includeMkvInfoOnFiles)
            file.mkvInfo = null;

              if (!Config.Configure.includeMediaInfoOnFiles)
            file.ffInfo = null;

              progressState.progressDetail = "Getting chapters' info...";

              Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

              fileList.hasMKV = true;
            }

            if (Program.hasFFmpeg)
            {

              progressState.progressDetail = "Dumping media info...";

              Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

              try
              {
            file = InfoDumper.ffInfoDump(file);
              }
              catch (Exception ex)
              {
            Program.Message("Error:\r\n\r\n" + ex.Message, "Error");
              }

              if (!String.IsNullOrEmpty(file.ffInfo)) file = chapterGet.mediaDump(file);

            }

            fileList.addFile(file);

            progress++;
              }

              if (fileList.hasMKV)
              {
            SuidLister suidList = CreateSuidLister(fileList);

            progressState.progressDetail = "Creating SUID list...";
            Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

            fileList = tracklist.arrangeTrack(fileList, suidList, processor);

            progressState.progressDetail = "Arranging new tracklist for every file...";
            Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

            //For Diagnostic purposes only
            if (Config.Configure.diagnose >= 30)
            {
              foreach (Suid suid in suidList.suidList)
              {

            {
              Console.WriteLine("SUID filename: " + suid.fileName);
              Console.WriteLine("SUID: " + suid.suid);
              Console.WriteLine("\n");
            }
              }

              Console.WriteLine("fileList.fileList.Count: " + fileList.fileList.Count + "\n");

              foreach (FileObject file in fileList.fileList)
              {

            //Console.WriteLine("Merge Argument count: {0}\n", file.mergeArgument.Count);

            foreach (MergeArgument merge in file.mergeArgument)
            {

              Console.WriteLine("Merge Argument:\nFile name: {0}\nTime Code: {1}\nFile Argument: {2}\nChapter Number: {3}\n",
                  file.filename,
                  merge.timeCode,
                  merge.fileName,
                  merge.chapterNum);

            }

            foreach (TimeCode time in file.timeCode)
            {
              Console.WriteLine("Time Code Argument: {0}\n", time.timeCode);
            }

            foreach (DelArgument del in file.delArgument)
            {
              Console.WriteLine("Del Argument: {0}\n", del.fileName);
            }

              }
            }

            if (Config.Configure.doMakeScript)
            {
              makeFile.makeFile(fileList, processor);

              progressState.progressDetail = "Creating Merge Script...";
              Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);
            }

              }

              if (Config.Configure.doMakeXml)
              {
            makeFile.makeXML(fileList, processor);

            progressState.progressDetail = "Dumping XML file...";
            Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);
              }

              processor.fileLists.Add(fileList);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Processes files to create File Objects for the main tasks of this program.
        /// Every tasks are denoted on each comment lines inside the method.
        /// </summary>
        /// <param name="list">The list that contains the fullpaths of the actual files.</param>
        /// <param name="listname">Name for the FileObjectCollection to be created.</param>
        /// <param name="processor">The Analyze object for progression report.</param>
        /// <param name="path">The path used as a working directory merge commands.</param>
        /// <param name="totalArguments">Optional. For progress report. The total number of lists to process.</param>
        public void processList(List <string> list, string listname, Analyze processor, string path = "C:\\", int totalArguments = 0)
        {
            FileObjectCollection fileList      = new FileObjectCollection();
            TrackLister          tracklist     = new TrackLister();
            MakeFile             makeFile      = new MakeFile();
            ChapterGenerator     chapterGet    = new ChapterGenerator();
            ProgressState        progressState = new ProgressState();

            fileList.folderPath = path;
            fileList.name       = listname;

            progressState.listName = fileList.name;

            progress       = 1;
            processPercent = 0;

            foreach (string s in list)
            {
                progressState.progressDetail = "Creating file entry...";

                Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                FileObject file = new FileObject(s);

                processPercent = progress.ToPercentage(list.Count);
                progressState.progressPercent = processPercent;
                progressState.fileName        = file.filename;
                Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                //Routine after splitting
                //Checks if current backgroundWorker operation is cancelled
                //Stops this program if true
                if (Analyze.backgroundWorker.CancellationPending)
                {
                    return;
                }

                if (file.extension == ".mkv")
                {
                    try
                    {
                        file = InfoDumper.infoDump(file);
                    }
                    catch (Exception ex)
                    {
                        Program.Message("Error:\r\n\r\n" + ex.Message, "Error");
                    }

                    progressState.progressDetail = "Dumping MKV info...";

                    Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                    file = chapterGet.chapterDump(file);

                    if (!Config.Configure.includeMkvInfoOnFiles)
                    {
                        file.mkvInfo = null;
                    }

                    if (!Config.Configure.includeMediaInfoOnFiles)
                    {
                        file.ffInfo = null;
                    }

                    progressState.progressDetail = "Getting chapters' info...";

                    Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                    fileList.hasMKV = true;
                }

                if (Program.hasFFmpeg)
                {
                    progressState.progressDetail = "Dumping media info...";

                    Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                    try
                    {
                        file = InfoDumper.ffInfoDump(file);
                    }
                    catch (Exception ex)
                    {
                        Program.Message("Error:\r\n\r\n" + ex.Message, "Error");
                    }

                    if (!String.IsNullOrEmpty(file.ffInfo))
                    {
                        file = chapterGet.mediaDump(file);
                    }
                }

                fileList.addFile(file);

                progress++;
            }

            if (fileList.hasMKV)
            {
                SuidLister suidList = CreateSuidLister(fileList);

                progressState.progressDetail = "Creating SUID list...";
                Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                fileList = tracklist.arrangeTrack(fileList, suidList, processor);

                progressState.progressDetail = "Arranging new tracklist for every file...";
                Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                //For Diagnostic purposes only
                if (Config.Configure.diagnose >= 30)
                {
                    foreach (Suid suid in suidList.suidList)
                    {
                        {
                            Console.WriteLine("SUID filename: " + suid.fileName);
                            Console.WriteLine("SUID: " + suid.suid);
                            Console.WriteLine("\n");
                        }
                    }

                    Console.WriteLine("fileList.fileList.Count: " + fileList.fileList.Count + "\n");

                    foreach (FileObject file in fileList.fileList)
                    {
                        //Console.WriteLine("Merge Argument count: {0}\n", file.mergeArgument.Count);

                        foreach (MergeArgument merge in file.mergeArgument)
                        {
                            Console.WriteLine("Merge Argument:\nFile name: {0}\nTime Code: {1}\nFile Argument: {2}\nChapter Number: {3}\n",
                                              file.filename,
                                              merge.timeCode,
                                              merge.fileName,
                                              merge.chapterNum);
                        }

                        foreach (TimeCode time in file.timeCode)
                        {
                            Console.WriteLine("Time Code Argument: {0}\n", time.timeCode);
                        }

                        foreach (DelArgument del in file.delArgument)
                        {
                            Console.WriteLine("Del Argument: {0}\n", del.fileName);
                        }
                    }
                }

                if (Config.Configure.doMakeScript)
                {
                    makeFile.makeFile(fileList, processor);

                    progressState.progressDetail = "Creating Merge Script...";
                    Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);
                }
            }

            if (Config.Configure.doMakeXml)
            {
                makeFile.makeXML(fileList, processor);

                progressState.progressDetail = "Dumping XML file...";
                Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);
            }

            processor.fileLists.Add(fileList);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Executes merge arguments after ListProcessor has done its job.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection processed by TrackLister.</param>
        /// <param name="processor">The Analyze object for progress reporting.</param>
        /// <param name="useCmd">Deprecated - sets whether to use cmd or not for merge execution.</param>
        /// <param name="fileListPercent">The percentage of File Lists processed. Used for progress reporting.</param>
        public void Merge(FileObjectCollection fileList, Analyze processor, bool useCmd = false, int fileListPercent = 100)
        {
            List <string> cmdCommand    = new List <string>();
            string        splitArgument = "";
            string        mergeArgument = "";
            string        outputPath    = "";

            ProgressState progressState = new ProgressState();

            progressState.listName = fileList.name;

            progress       = 1;
            processPercent = 0;

            /*
             * Legacy code - since the command was just repeated twice below!
             *
             * if (fileList.hasOrdered)
             * {
             * Directory.CreateDirectory(Path.Combine(fileList.folderPath, "output"));
             * }
             *
             * */

            if (!Config.Configure.sourceOutputFolder)
            {
                outputPath = Program.defaultPath;
                if (!Directory.Exists(Path.Combine(outputPath, "merged")))
                {
                    Directory.CreateDirectory(Path.Combine(outputPath, "merged"));
                }
            }

            foreach (FileObject file in fileList.fileList)
            {
                //Routine after merging
                //Checks if current backgroundWorker operation is cancelled
                //Stops this program if true
                if (this.backgroundWorker.CancellationPending)
                {
                    return;
                }

                if (Config.Configure.sourceOutputFolder)
                {
                    outputPath = file.directoryname;
                }

                if (!Directory.Exists(Path.Combine(outputPath, "merged")))
                {
                    Directory.CreateDirectory(Path.Combine(outputPath, "merged"));
                }

                List <string> timeCodeList      = new List <string>();
                List <string> delArgumentList   = new List <string>();
                List <string> mergeArgumentList = new List <string>();
                List <string> chapterInfo       = new List <string>();

                progressState.fileName = file.filename;

                processPercent = progress.ToPercentage(fileList.fileList.Count);
                progressState.progressPercent = processPercent;

                progressState.progressDetail = "";
                this.backgroundWorker.ReportProgress(fileListPercent, progressState);



                /*
                 * Main process
                 * */
                if (file.mergeArgument.Count > 1)
                {
                    foreach (MergeArgument merge in file.mergeArgument)
                    {
                        if (merge.isExternalSuid)
                        {
                            mergeArgumentList.Add("\"" + merge.fullPath + "\"");
                        }
                        else
                        {
                            if (file.splitCount > 1)
                            {
                                mergeArgumentList.Add("\"" + Path.Combine(outputPath, merge.fileName) + "\"");
                            }
                            else
                            {
                                mergeArgumentList.Add("\"" + merge.originalFullPath + "\"");
                            }
                        }
                    }

                    foreach (TimeCode time in file.timeCode)
                    {
                        timeCodeList.Add(time.timeCode);
                    }

                    foreach (DelArgument del in file.delArgument)
                    {
                        delArgumentList.Add("\"" + del.fullPath + "\"");
                    }

                    string[] timeCode     = timeCodeList.ToArray();
                    string[] delString    = delArgumentList.ToArray();
                    string[] mergeString  = mergeArgumentList.ToArray();
                    string[] chaptersInfo = chapterInfo.ToArray();

                    string tempFileName     = "\"" + Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + ".mkv\"";
                    string newFileName      = "\"merged\\" + Config.Configure.newfileprefix + file.filenameNoExtension + Config.Configure.newfilesuffix + ".mkv\"";
                    string originalFileName = "\"" + file.fullpath + "\"";

                    if (file.shouldJoin)
                    {
                        //processor.orderedGroups.Add(outputPath); //should be inside a check outside this loop, else it would add needless duplicates of outputPath


                        if (file.splitCount > 1)
                        {
                            splitArgument = "--no-chapters --split timecodes:" + String.Join(",", timeCode) + " -o " + tempFileName + " " + originalFileName;
                        }

                        mergeArgument = "--no-chapters -o " + newFileName + " " + String.Join(" +", mergeString);
                    }

                    progressState.progressDetail = "Building merge arguments...";
                    this.backgroundWorker.ReportProgress(fileListPercent, progressState);
                }

                //Routine after merge arguments
                //Checks if current backgroundWorker operation is cancelled
                //Stops this program if true
                if (this.backgroundWorker.CancellationPending)
                {
                    return;
                }

                if (file.shouldJoin)
                {
                    ProcessStartInfo mergeProcess = new ProcessStartInfo();

                    mergeProcess.FileName         = Program.mergeExe;
                    mergeProcess.UseShellExecute  = false;
                    mergeProcess.CreateNoWindow   = true;
                    mergeProcess.WorkingDirectory = file.directoryname;
                    mergeProcess.WindowStyle      = ProcessWindowStyle.Hidden;
                    //mergeProcess.RedirectStandardOutput = true;

                    if (file.splitCount > 1)
                    {
                        progressState.progressDetail = "Splitting file...";
                        this.backgroundWorker.ReportProgress(fileListPercent, progressState);

                        mergeProcess.Arguments = splitArgument;

                        using (Process process = Process.Start(mergeProcess))
                        {
                            process.WaitForExit();
                        }
                    }

                    //Routine after splitting
                    //Checks if current backgroundWorker operation is cancelled
                    //Stops this program if true
                    if (this.backgroundWorker.CancellationPending)
                    {
                        foreach (DelArgument del in file.delArgument)
                        {
                            File.Delete(del.fullPath);
                        }

                        return;
                    }

                    progressState.progressDetail = "Merging file...";
                    this.backgroundWorker.ReportProgress(fileListPercent, progressState);

                    mergeProcess.Arguments = mergeArgument;

                    using (Process process = Process.Start(mergeProcess))
                    {
                        process.WaitForExit();
                    }

                    progressState.progressDetail = "Deleting temporary files...";
                    this.backgroundWorker.ReportProgress(fileListPercent, progressState);

                    foreach (DelArgument del in file.delArgument)
                    {
                        File.Delete(del.fullPath);
                    }
                }

                progress++;
            }

            if (fileList.hasOrdered && !Analyze.outputGroups.Contains(outputPath))
            {
                Analyze.outputGroups.Add(outputPath + "\\merged");
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Main Convert process.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection to process.</param>
        public void Convert(FileObjectCollection fileList, int fileListPercent = 100)
        {
            InitializeConfiguration();

              ProgressState progressState = new ProgressState();
              progressState.listName = fileList.name;

              progress = 1;
              processPercent = 0;

              if (!Config.Configure.sourceOutputFolder)
              {
            outputPath = Program.defaultPath;
            if (!Directory.Exists(Path.Combine(outputPath, "converted")))
              Directory.CreateDirectory(Path.Combine(outputPath, "converted"));
              }

            //Main Loop
              foreach (FileObject file in fileList.fileList)
              {

              //Set Required Variables
            string ffmpegArgs = "";
            string fileVfilter = "";
            string fileVfilterArg = "";
            string fileFFmpegOptions = ffmpegOptions;

            List<string> fileVfilters = new List<string>();

            List<string> fileFilterChains = new List<string>();

            foreach (string vfilteritem in vfilters)
              fileVfilters.Add(vfilteritem);

              //Escape Filter Patterns
            string firstLevel = @"([:\\'])";
            string secondLevel = @"([\[\],;\\'])";

              //Input/Output programmatic patterns
            string custInputPat = @"\(inputfile\)";
            string custOutputPat = @"\(outputname\)";

              //Progress Reporting
            progressState.fileName = file.filename;

            processPercent = progress.ToPercentage(fileList.fileList.Count);
            progressState.progressPercent = processPercent;

            progressState.progressDetail = "Building conversion arguments...";
            this.backgroundWorker.ReportProgress(fileListPercent, progressState);

            if (Config.Configure.sourceOutputFolder)
            {
              outputPath = file.directoryname;
            }

            if (!Directory.Exists(Path.Combine(outputPath, "converted")))
              Directory.CreateDirectory(Path.Combine(outputPath, "converted"));

              //Output File Argument
            string outputFile = outputPath + "\\converted\\" + ConvConfig.newfileprefix + file.filenameNoExtension + ConvConfig.newfilesuffix;

              //Fix_subtitle_duration
            if (ConvConfig.fixsubduration)
              ffmpegArgs += @"-fix_sub_duration ";

              //Subtitles
            //Subfilter
            if (ConvConfig.useSubFilter)
            {
            //Escape any special characters
              string fileitem = file.fullpath;
              fileitem = Regex.Replace(fileitem, firstLevel, m =>
              {
            var escapedChars = m.Groups[1].Value;
            return @"\" + escapedChars;
              });

              fileitem = Regex.Replace(fileitem, secondLevel, n =>
              {
            var escapedChars = n.Groups[1].Value;
            return @"\" + escapedChars;
              });

              fileVfilter = @"subtitles=" + fileitem + @":si=" + ConvConfig.subindex.ToString();
              fileVfilters.Add(fileVfilter);
            }

              //Video Filter
              //Custom Video Filter
            if (!String.IsNullOrWhiteSpace(ConvConfig.customvfilter))
            {
              fileVfilterArg = ConvConfig.customvfilter;
            }
            else
            {
              //filefilterchain.Add(String.Join(",", vfilters.ToArray()));

              fileVfilterArg = String.Join(", ", fileVfilters.ToArray());
            }

            //Diagnostic purposes only
            //fileVfilterArg = "subtitles=D:\\backup\\anime_archive\\[Coalgirls]_Ookami-san,_to;_Shichinin_no_'Nakama-tachi'_(1280x720_Blu-ray_FLAC)\\[Coalgirls]_Ookami-san_to_Shichinin_no_Nakama-tachi_01_(1280x720_Blu-ray_FLAC)_[F9495BFE].mkv:si=0";

            if (!String.IsNullOrWhiteSpace(fileVfilterArg))
            {
              fileVfilterArg = " -vf \"" + fileVfilterArg + "\"";   //Placeholder
              fileFFmpegOptions += fileVfilterArg;
            }

              //Custom ffmpeg options
            if (!String.IsNullOrWhiteSpace(ConvConfig.customffmpegarg))
            {
              string customData = ConvConfig.customffmpegarg;

              //Replace (inputfile) and (outputname) with input and output variables accordingly.
              customData = Regex.Replace(customData, custInputPat, m => { return file.fullpath; });
              customData = Regex.Replace(customData, custOutputPat, m => { return outputFile; });

              ffmpegArgs = customData;
            }
            else
              //Set final ffmpegArgs
              ffmpegArgs += "-i \"" + file.fullpath + "\"" + fileFFmpegOptions + " \"" + outputFile + "." + ConvConfig.format + "\"";

            currentCommand = ffmpegArgs;

             /*
              * Routine before converting
              * Checks if current backgroundWorker operation is cancelled
              * Stops this program if true
              *
              * Process cancelling should be changed as this currently waits for previous conversion to complete;
              * Conversion can take a lot of time for cancellation to wait.
              *
              * Native threading would be used.
              *
              * */
            if (this.backgroundWorker.CancellationPending)
            {
              return;
            }

            if (ConvConfig.showCommands)
            {
              Program.Message("Current command:\r\n\r\n" + currentCommand, "Diagnostics");
            }

              //Main process
            ProcessStartInfo convertProcess = new ProcessStartInfo();

            convertProcess.FileName = Program.ffmpegExe;
            convertProcess.Arguments = ffmpegArgs;

            convertProcess.UseShellExecute = false;

            if (!Config.Configure.ConvertConfigure.showFFmpegWindow) //Added check for diagnostics
            {
              convertProcess.CreateNoWindow = true;
              convertProcess.WindowStyle = ProcessWindowStyle.Hidden;
              convertProcess.RedirectStandardInput = true;  //Preparation for an eminent interactive ffmpeg thread.
            }
            else
            {
              convertProcess.CreateNoWindow = false;
            }
            convertProcess.WorkingDirectory = file.directoryname;

            progressState.progressDetail = "Converting...";
            this.backgroundWorker.ReportProgress(fileListPercent, progressState);

            using (Process process = Process.Start(convertProcess))
            {
              process.WaitForExit();
            }

            //If External subs are set to true.
            if (ConvConfig.externalsubs)
            {
              ffmpegArgs = "-i \"" + file.fullpath + "\" \"" + outputFile + "." + ConvConfig.externalsubsext + "\"";

              currentCommand = ffmpegArgs;

              if (ConvConfig.showCommands)
              {
            Program.Message("Current command:\r\n\r\n" + currentCommand, "Diagnostics");
              }

              convertProcess.Arguments = ffmpegArgs;

              progressState.progressDetail = "Creating external subtitles...";
              this.backgroundWorker.ReportProgress(fileListPercent, progressState);

              using (Process process = Process.Start(convertProcess))
              {
            process.WaitForExit();
              }

            }

            progress++;
              //End of Main process
              }

              if (!Analyze.outputGroups.Contains(outputPath))
              {
            Analyze.outputGroups.Add(outputPath + "\\converted");
              }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Rearranges chapter tracks to include the inserted external file determined by SUID.
        /// Also determines MergeArguments order.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection processed by ChapterGenerator.</param>
        /// <param name="suid">The SuidLister that contains all SUIDs.</param>
        /// <param name="processor">The Analyze object for progression report.</param>
        /// <returns>The FileObjectCollection with FileObjects that has rearranged chapter tracks.</returns>
        public FileObjectCollection arrangeTrack(FileObjectCollection fileList, SuidLister suid, Analyze processor)
        {
            //string mergeargument = "";

              foreach (FileObject file in fileList.fileList)
              {

            int count = 0;
            string tempFileName = "";
            string tempFullPath = "";

              //First loop to determine which chapters have external suid attached
            foreach (ChapterAtom chaptera in file.chapterAtom)
            {
              foreach (Suid suidi in suid.suidList)
              {

            if (suidi.suid == chaptera.suid)
            {
              chaptera.suidFileName = suidi.fileName;
              chaptera.suidFullPath = suidi.fullPath;

              //Console.WriteLine("SUID match.");
            }

              }

              //mergeargument = mergeargument + chaptera.timeStart + chaptera.timeEnd + chaptera.suidFileName;
            }

              //Second loop that uses index to properly determine which chapter needs to be added as a MergeArgument
            for (int i = 0; i < file.chapterAtom.Count; i++)
            {

              var current = file.chapterAtom[i];

              var previous = current;
              var next = current;

              if (i > 0)
              {
            previous = file.chapterAtom.ElementAt(i - 1);
              }

              if (i < (file.chapterAtom.Count - 1))
              {
            next = file.chapterAtom.ElementAt(i + 1);
              }

              /*
               * Diagnostic purposes only
               *
               * Console.WriteLine("Arrange Track");
               * Console.WriteLine("Current: " + current.suidFileName);
               * Console.WriteLine("Previous: " + previous.suidFileName);
               * Console.WriteLine("Next: " + next.suidFileName);
               * Console.WriteLine("\n");
               * */

              //The following routine should correctly determine when to split the the chapters optimally to insert the external SUID file
              if (current.suidFileName != null)
              {
            file.addMergeArg(current.suidFullPath, current.chapterNum, true);
            if (!file.shouldJoin)
              file.shouldJoin = true;
            if (!fileList.hasOrdered)
              fileList.hasOrdered = true;
            if (!processor.hasOrdered)
              processor.hasOrdered = true;
              }
              else
              {

            string timeCode = "";

              //TimeEnd Split Mode
            if (Config.Configure.splitModeTimeEnd && (next.suidFileName != null || i == file.chapterAtom.Count - 1))
            {
              count++;

              file.splitCount = count;

              timeCode = current.timeEnd;

            //to change, should dynamically change digit format to "ddd"
            // done
              tempFileName = Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + "-" + count.ToString("D3") + ".mkv";
              tempFullPath = Path.Combine(fileList.folderPath, Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix) + "-" + count.ToString("D3") + ".mkv";

              file.addMergeArg(tempFullPath, current.chapterNum, false, timeCode, tempFileName, file.fullpath);
              if (i != file.chapterAtom.Count - 1)
                file.addTimeCode(timeCode);
              file.addDelArg(tempFullPath, tempFileName);
            }
              //TimeStart Split Mode
            else if (Config.Configure.splitModeTimeStart && (previous.suidFileName != null || i == 0))
            {
              count++;

              file.splitCount = count;

              timeCode = current.timeStart;

              tempFileName = Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + "-" + count.ToString("D3") + ".mkv";
              tempFullPath = Path.Combine(fileList.folderPath, Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix) + "-" + count.ToString("D3") + ".mkv";

              file.addMergeArg(tempFullPath, current.chapterNum, false, timeCode, tempFileName, file.fullpath);
              if (i > 0)
                file.addTimeCode(timeCode);
              file.addDelArg(tempFullPath, tempFileName);

            }

              }

            }

              }

              return fileList;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Deprecated. Creates a script that executes mkvmerge commands to merge analyzed files
        /// </summary>
        /// <param name="fileList">The processed FileObjectCollection.</param>
        /// <param name="processor">The Analyze object</param>
        /// <param name="outputPathArg">Optional. Pass a different output path for the script.</param>
        public void makeFile(FileObjectCollection fileList, Analyze processor, string outputPathArg = null)
        {
            if (outputPathArg != null)
            {
                outputPath = outputPathArg;
            }
            else
            if (Config.Configure.sourceOutputFolder)
            {
                outputPath = Path.Combine(fileList.folderPath, Config.Configure.exportfilename);
            }
            else
            {
                outputPath = Path.Combine(outputPath, Config.Configure.exportfilename);
            }


            StringBuilder makeFileContent = new StringBuilder();

            if (Config.Configure.diagnoseMkvinfoDump | Config.Configure.diagnoseChapterinfoDump)
            {
                Directory.CreateDirectory(dumpPath);
            }

            foreach (FileObject file in fileList.fileList)
            {
                List <string> timeCodeList      = new List <string>();
                List <string> delArgumentList   = new List <string>();
                List <string> mergeArgumentList = new List <string>();
                List <string> chapterInfo       = new List <string>();

                /*
                 * Diagnostic purposes only
                 * */
                if (Config.Configure.diagnoseMkvinfoDump)
                {
                    using (StreamWriter writer = new StreamWriter(Path.Combine(dumpPath, file.filenameNoExtension + "_mkvinfo.txt")))
                    {
                        writer.Write(file.mkvInfo);
                    }
                }

                /*
                 * Main process
                 * */
                if (file.mergeArgument.Count > 1)
                {
                    foreach (MergeArgument merge in file.mergeArgument)
                    {
                        if (merge.isExternalSuid)
                        {
                            mergeArgumentList.Add("\"" + merge.fullPath + "\"");
                        }
                        else
                        {
                            if (file.splitCount > 1)
                            {
                                mergeArgumentList.Add("\"" + merge.fileName + "\"");
                            }
                            else
                            {
                                mergeArgumentList.Add("\"" + merge.originalFullPath + "\"");
                            }
                        }
                    }

                    foreach (TimeCode time in file.timeCode)
                    {
                        timeCodeList.Add(time.timeCode);
                    }

                    foreach (DelArgument del in file.delArgument)
                    {
                        delArgumentList.Add("\"" + del.fileName + "\"");
                    }

                    foreach (ChapterAtom chapter in file.chapterAtom)
                    {
                        chapterInfo.Add(chapter.chapterInfo);
                    }

                    string[] timeCode      = timeCodeList.ToArray();
                    string[] delArgument   = delArgumentList.ToArray();
                    string[] mergeArgument = mergeArgumentList.ToArray();
                    string[] chaptersInfo  = chapterInfo.ToArray();

                    string tempFileName     = "\"" + Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + ".mkv\"";
                    string newFileName      = "\"output\\" + Config.Configure.newfileprefix + file.filenameNoExtension + Config.Configure.newfilesuffix + ".mkv\"";
                    string originalFileName = "\"" + file.fullpath + "\"";

                    if (file.shouldJoin)
                    {
                        doMakeFile = true;
                        makeFileContent.AppendLine("::" + file.filename);

                        if (file.splitCount > 1)
                        {
                            makeFileContent.AppendLine("mkvmerge --no-chapters --split timecodes:" + String.Join(",", timeCode) + " -o " + tempFileName + " " + originalFileName);
                        }

                        makeFileContent.AppendLine("mkvmerge --no-chapters -o " + newFileName + " " + String.Join(" +", mergeArgument) + "\r\n");
                        makeFileContent.AppendLine("DEL /Q " + String.Join(" ", delArgument) + "\r\n");
                    }

                    if (Config.Configure.diagnoseChapterinfoDump)
                    {
                        using (StreamWriter writer = new StreamWriter(Path.Combine(dumpPath, file.filenameNoExtension + "_chaptersinfo.txt")))
                        {
                            writer.WriteLine(String.Join("\n", chaptersInfo));
                        }
                    }
                }
            }

            if (doMakeFile)
            {
                using (StreamWriter writer = new StreamWriter(outputPath))
                {
                    writer.WriteLine("@echo off\r\ncls\r\n\r\npushd \"%~dp0\"\r\nif not exist output mkdir output\r\n");
                    writer.Write(makeFileContent);
                }
                Analyze.outputGroups.Add(outputPath);
            }
            else
            {
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Executes merge arguments after ListProcessor has done its job.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection processed by TrackLister.</param>
        /// <param name="processor">The Analyze object for progress reporting.</param>
        /// <param name="useCmd">Deprecated - sets whether to use cmd or not for merge execution.</param>
        /// <param name="fileListPercent">The percentage of File Lists processed. Used for progress reporting.</param>
        public void Merge(FileObjectCollection fileList, Analyze processor, bool useCmd = false, int fileListPercent = 100)
        {
            List<string> cmdCommand = new List<string>();
              string splitArgument = "";
              string mergeArgument = "";
              string outputPath = "";

              ProgressState progressState = new ProgressState();
              progressState.listName = fileList.name;

              progress = 1;
              processPercent = 0;

              /*
               * Legacy code - since the command was just repeated twice below!
               *
              if (fileList.hasOrdered)
              {
            Directory.CreateDirectory(Path.Combine(fileList.folderPath, "output"));
              }
               *
               * */

              if (!Config.Configure.sourceOutputFolder)
              {
            outputPath = Program.defaultPath;
            if (!Directory.Exists(Path.Combine(outputPath, "merged")))
              Directory.CreateDirectory(Path.Combine(outputPath, "merged"));
              }

              foreach (FileObject file in fileList.fileList)
              {

              //Routine after merging
              //Checks if current backgroundWorker operation is cancelled
              //Stops this program if true
            if (this.backgroundWorker.CancellationPending)
            {
              return;
            }

            if (Config.Configure.sourceOutputFolder)
            {
              outputPath = file.directoryname;
            }

            if (!Directory.Exists(Path.Combine(outputPath, "merged")))
              Directory.CreateDirectory(Path.Combine(outputPath, "merged"));

            List<string> timeCodeList = new List<string>();
            List<string> delArgumentList = new List<string>();
            List<string> mergeArgumentList = new List<string>();
            List<string> chapterInfo = new List<string>();

            progressState.fileName = file.filename;

            processPercent = progress.ToPercentage(fileList.fileList.Count);
            progressState.progressPercent = processPercent;

            progressState.progressDetail = "";
            this.backgroundWorker.ReportProgress(fileListPercent, progressState);

            /*
              * Main process
              * */
            if (file.mergeArgument.Count > 1)
            {

              foreach (MergeArgument merge in file.mergeArgument)
              {

            if (merge.isExternalSuid)
              mergeArgumentList.Add("\"" + merge.fullPath + "\"");
            else
            {
              if (file.splitCount > 1)
              {
                mergeArgumentList.Add("\"" + Path.Combine(outputPath, merge.fileName) + "\"");
              }
              else
                mergeArgumentList.Add("\"" + merge.originalFullPath + "\"");

            }

              }

              foreach (TimeCode time in file.timeCode)
              {
            timeCodeList.Add(time.timeCode);
              }

              foreach (DelArgument del in file.delArgument)
              {
            delArgumentList.Add("\"" + del.fullPath + "\"");
              }

              string[] timeCode = timeCodeList.ToArray();
              string[] delString = delArgumentList.ToArray();
              string[] mergeString = mergeArgumentList.ToArray();
              string[] chaptersInfo = chapterInfo.ToArray();

              string tempFileName = "\"" + Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + ".mkv\"";
              string newFileName = "\"merged\\" + Config.Configure.newfileprefix + file.filenameNoExtension + Config.Configure.newfilesuffix + ".mkv\"";
              string originalFileName = "\"" + file.fullpath + "\"";

              if (file.shouldJoin)
              {

            //processor.orderedGroups.Add(outputPath); //should be inside a check outside this loop, else it would add needless duplicates of outputPath

            if (file.splitCount > 1)
            {
              splitArgument = "--no-chapters --split timecodes:" + String.Join(",", timeCode) + " -o " + tempFileName + " " + originalFileName;

            }

            mergeArgument = "--no-chapters -o " + newFileName + " " + String.Join(" +", mergeString);

              }

              progressState.progressDetail = "Building merge arguments...";
              this.backgroundWorker.ReportProgress(fileListPercent, progressState);

            }

              //Routine after merge arguments
              //Checks if current backgroundWorker operation is cancelled
              //Stops this program if true
            if (this.backgroundWorker.CancellationPending)
            {
              return;
            }

            if (file.shouldJoin)
            {
              ProcessStartInfo mergeProcess = new ProcessStartInfo();

              mergeProcess.FileName = Program.mergeExe;
              mergeProcess.UseShellExecute = false;
              mergeProcess.CreateNoWindow = true;
              mergeProcess.WorkingDirectory = file.directoryname;
              mergeProcess.WindowStyle = ProcessWindowStyle.Hidden;
              //mergeProcess.RedirectStandardOutput = true;

              if (file.splitCount > 1)
              {
            progressState.progressDetail = "Splitting file...";
            this.backgroundWorker.ReportProgress(fileListPercent, progressState);

            mergeProcess.Arguments = splitArgument;

            using (Process process = Process.Start(mergeProcess))
            {
              process.WaitForExit();
            }

              }

            //Routine after splitting
            //Checks if current backgroundWorker operation is cancelled
            //Stops this program if true
              if (this.backgroundWorker.CancellationPending)
              {
            foreach (DelArgument del in file.delArgument)
              File.Delete(del.fullPath);

            return;
              }

              progressState.progressDetail = "Merging file...";
              this.backgroundWorker.ReportProgress(fileListPercent, progressState);

              mergeProcess.Arguments = mergeArgument;

              using (Process process = Process.Start(mergeProcess))
              {
            process.WaitForExit();
              }

              progressState.progressDetail = "Deleting temporary files...";
              this.backgroundWorker.ReportProgress(fileListPercent, progressState);

              foreach (DelArgument del in file.delArgument)
            File.Delete(del.fullPath);

            }

            progress++;

              }

              if (fileList.hasOrdered && !Analyze.outputGroups.Contains(outputPath))
              {
            Analyze.outputGroups.Add(outputPath + "\\merged");
              }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Rearranges chapter tracks to include the inserted external file determined by SUID.
        /// Also determines MergeArguments order.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection processed by ChapterGenerator.</param>
        /// <param name="suid">The SuidLister that contains all SUIDs.</param>
        /// <param name="processor">The Analyze object for progression report.</param>
        /// <returns>The FileObjectCollection with FileObjects that has rearranged chapter tracks.</returns>
        public FileObjectCollection arrangeTrack(FileObjectCollection fileList, SuidLister suid, Analyze processor)
        {
            //string mergeargument = "";

            foreach (FileObject file in fileList.fileList)
            {
                int    count        = 0;
                string tempFileName = "";
                string tempFullPath = "";


                //First loop to determine which chapters have external suid attached
                foreach (ChapterAtom chaptera in file.chapterAtom)
                {
                    foreach (Suid suidi in suid.suidList)
                    {
                        if (suidi.suid == chaptera.suid)
                        {
                            chaptera.suidFileName = suidi.fileName;
                            chaptera.suidFullPath = suidi.fullPath;

                            //Console.WriteLine("SUID match.");
                        }
                    }

                    //mergeargument = mergeargument + chaptera.timeStart + chaptera.timeEnd + chaptera.suidFileName;
                }


                //Second loop that uses index to properly determine which chapter needs to be added as a MergeArgument
                for (int i = 0; i < file.chapterAtom.Count; i++)
                {
                    var current = file.chapterAtom[i];

                    var previous = current;
                    var next     = current;

                    if (i > 0)
                    {
                        previous = file.chapterAtom.ElementAt(i - 1);
                    }

                    if (i < (file.chapterAtom.Count - 1))
                    {
                        next = file.chapterAtom.ElementAt(i + 1);
                    }

                    /*
                     * Diagnostic purposes only
                     *
                     * Console.WriteLine("Arrange Track");
                     * Console.WriteLine("Current: " + current.suidFileName);
                     * Console.WriteLine("Previous: " + previous.suidFileName);
                     * Console.WriteLine("Next: " + next.suidFileName);
                     * Console.WriteLine("\n");
                     * */

                    //The following routine should correctly determine when to split the the chapters optimally to insert the external SUID file
                    if (current.suidFileName != null)
                    {
                        file.addMergeArg(current.suidFullPath, current.chapterNum, true);
                        if (!file.shouldJoin)
                        {
                            file.shouldJoin = true;
                        }
                        if (!fileList.hasOrdered)
                        {
                            fileList.hasOrdered = true;
                        }
                        if (!processor.hasOrdered)
                        {
                            processor.hasOrdered = true;
                        }
                    }
                    else
                    {
                        string timeCode = "";

                        //TimeEnd Split Mode
                        if (Config.Configure.splitModeTimeEnd && (next.suidFileName != null || i == file.chapterAtom.Count - 1))
                        {
                            count++;

                            file.splitCount = count;

                            timeCode = current.timeEnd;

                            //to change, should dynamically change digit format to "ddd"
                            // done
                            tempFileName = Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + "-" + count.ToString("D3") + ".mkv";
                            tempFullPath = Path.Combine(fileList.folderPath, Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix) + "-" + count.ToString("D3") + ".mkv";

                            file.addMergeArg(tempFullPath, current.chapterNum, false, timeCode, tempFileName, file.fullpath);
                            if (i != file.chapterAtom.Count - 1)
                            {
                                file.addTimeCode(timeCode);
                            }
                            file.addDelArg(tempFullPath, tempFileName);
                        }
                        //TimeStart Split Mode
                        else if (Config.Configure.splitModeTimeStart && (previous.suidFileName != null || i == 0))
                        {
                            count++;

                            file.splitCount = count;

                            timeCode = current.timeStart;

                            tempFileName = Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + "-" + count.ToString("D3") + ".mkv";
                            tempFullPath = Path.Combine(fileList.folderPath, Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix) + "-" + count.ToString("D3") + ".mkv";

                            file.addMergeArg(tempFullPath, current.chapterNum, false, timeCode, tempFileName, file.fullpath);
                            if (i > 0)
                            {
                                file.addTimeCode(timeCode);
                            }
                            file.addDelArg(tempFullPath, tempFileName);
                        }
                    }
                }
            }

            return(fileList);
        }