FixMKVGaps has a module to run scripts in order to automate some of its functions.
To access this module, type F12 which opens the scripts page.
On the page that opens you can write a script in a syntax very close to the Pascal language, since the module is based on the Pascalscript utility of RemObjects. See for example this site on Github if you want to deepen this question.The sample scripts that follow below may be an inspiration to adapt them to your needs. But beware, scripting is a real programming job that will not be easy for those who have no concept in the field.
The interest of scripts in my software is that they can use procedures to control the software. The list of these procedures is obtained by typing F1 which opens the help window. Unlike other windows in the application, this window can remain open all the time, and can be moved on the screen independently of the main window. You can even put it on a second screen if you have a workstation that has it.
These procedures appear here under two tabs (main, actions) . For example, select OpenFile (CTRL + O) under the Actions tab. Several informations are then displayed:
- The name of the procedure, for example OpenFile .
- It is followed by the keyboard shortcut CTRL + O which allows to call it when using the software. This shortcut is not used to write scripts but to manually control the application.
- The hint that is displayed when the mouse is hovering over a component that operates this procedure.It summarizes the action that the procedure performs.
- The syntax of the procedure, especially if it uses variables, here: procedure OpenFile ( const aWidestring: widestring); This syntax shows, in the example, that the procedure must be given a parameter which is a widestring. This will of course be the full name of the file to open, since you understand at this point that OpenFile is used to open a .mkv file.
- The syntax of the switch in command line mode. This is not used for scripts, but to launch the application in command line mode.
- Possibly a zone that may include comments. See for example the SaveFolder action for an example.
Therefore the use in the script follows:
Note that the script is case-insensitive: you can write both OpenFile and openfile. In addition each instruction is completed by a semicolon, which will not surprise the programmers under Pascal.
If you click on the Execute button, then the program will load the requested video (here “Kill the Kills”) and start scanning it right away. You probably do not see it because the script window hides the main window. Therefore, immediately type F12 again to close the script window.
The interest of this example is limited, but it becomes a little more interesting if we chain several actions. For example FixMKVGaps can be asked to open several files and repair them immediately immediately if they contain errors.
This example shows how to put one statement per line. In addition, here the interest of the script is obvious, because we will open and correct two files in the same script, chaining all operations.
If you click on the Execute button the application loads the requested video file in openfile, it starts the analysis immediately, and when it is finished, if there are gaps, it automatically chases the repair and produces a repaired file (using the folder specified in the Settings ). Then he continues the same process with the second file.
There too, to see it, you have to type F12 in order to hide the page of the scripts.
In fact, instead of typing F12 you can use an application procedure that has the same effect to close the scripts page. It’s called script , and is listed under the main tab in the Help ( F1 ) page. It is also a good practice to start all scripts by calling from the beginning to close the scripts page and be able to follow what is happening in the interface of the application. We can always retypeF12 , once everything is finished if we want to see, in the area of the bottom of the page of the scripts, the messages emitted by the compiler of the script, and during the execution.
The script procedure, like a number of others, which switch between a True or False state, has two syntaxes: on the one hand we can use it alone, without parameters, so it reverses the existing state: here if the page of script is displayed, it masks it, but if it was not, it would display it. On the other hand, we can use it in the form of setscript (True) or setscript (False) which imposes the true or false state, independently of the one that was in progress.
We then asked that the repair commits directly after the analysis, adding the command to chained (True). This is a command equivalent to checking the Check Repair check box in Settings . This saves Fix commands, since the only openfile command will also start the repair.
If we click here on Execute , then first the window of the script closes (since it was open, the script procedure the mask). Then the first requested file is loaded, and when its analysis is complete, it repairs itself immediately. Then the second file opens, is analyzed and repaired. For the record, we gave a script command at the end, to return to the scripts page, which makes it possible to check if the compilation and the execution succeeded.
Our scripting language can use conditions like if … then … else …, loops like while … end; or also for i: = 1 to do begin … end; There are also special functions to browse files in a folder, including the three functions findfirst, findnext, findclose. Example 4 shows how to write a script that can parse and repair all .mkv files in a folder.
First we define the SourceFolder source folder where are the .mkv files to be analyzed and repaired if necessary, then the destination DestFolder folder where the recreated files will be housed. Note how constants are defined with the const keyword.
Then we define a variable, SourceFile which will contain the name of the file being processed. This name will change as we loop through all .mkv files in the source folder. That’s why you need a variable.
Also note that statements like const and var are made before the begin that begins the script statements, which are all begin and end .
We find the script procedure to hide the scripts page. Then the command chained (True) which allows to directly chain the repair after the analysis; followed by SameFolder (False) which indicates that we do not want to create the repaired files in the same folder as the original, but in a folder that we specify a little further by SaveFolder (DestFolder) which refers to a constant created above, in this case the folder g: \ fixed . We also added a function called forceirectories to create the designated folder if it does not exist, as well as all its subfolders.This is a useful precaution to avoid mistakes.
We then call findfirst with as parameters the source folder to explore, and the mask of the searched files, here * .mkv . As long as the filename returned by findfirst and further by findnext is not empty, we open the returned file in SourceFile , which automatically launches the scan, and also the repair since we have linked to True.
When all the work is finished, FixMKVgaps will reactivate the window of the scripts, which allows you to read the result, hoping that it is *** Compilation succeeded *** then *** Succesfully Executed *** . If there are compilation errors, check the text of the script where something should go wrong. If the execution fails, FixMKVGaps itself has encountered an error, or mkvmerge has encountered one. In general, he will tell you what to check.
Note in this example 4 that the FixMKVGaps window that contains the text of the script has been enlarged in height (as can be done in most Windows windows), and that it allows to have here the complete script. Feel free to widen this window in height or width to better edit the script.