Sample of Python script

To use Python script, you need to install Python in your PC. The official download site is here. There are some useful documents and articles on the Internet. You may edit a sample script for your usage.

Python script is saved on some text files in `tool` folder under MultiPar's installed directory. If you put a script file on another folder or under `Program Files` directory, you must set the path of `par2j64.exe` or `MultiPar.exe` on your PC. By default, I write relative path from the `tool` folder. You can refer the directory on MultiPar's Option window: "System settings" tab, "Folder location" section, "Open MultiPar's install folder" button.

### Index

Create individual PAR2 set in each selected folder |
Create individual PAR2 set in each selected folder with GUI |
Create multiple PAR2 sets for many files in a folder |

Create multiple PAR2 sets for files or folders with Queuing GUI |
Verify multiple PAR2 sets in a selected folder with Queuing GUI |

Check difference of PAR and directory with GUI |
Rename included source files in PAR2 sets with GUI |
Read a selected JSON file and show contents |

Automate tasks after MultiPar GUI 's Creation |
Automate tasks after MultiPar GUI 's Verification / Repair |

### Create individual PAR2 set in each selected folder

Command | "path of script file" "path of folder1" "path of folder2" "path of folder3"...
Input | specify some folders
Action | This sample creates individual PAR2 set in each selected folder. For example, when you supply 7 folders, total 7 PAR2 set are made.
Script file | `each_folder.py`

This sample tries to create efficient PAR2 files.

### Create individual PAR2 set in each selected folder with GUI

Command | "path of script file" "path of folder1" "path of folder2" "path of folder3"...
Input | specify some folders
Action | This sample creates individual PAR2 set in each selected folder. For example, when you supply 7 folders, total 7 PAR2 set are made. It shows GUI for setting. It's possible to filter source files by their size.
Script file | `large_files.py`
Caution | You must check MultiPar Option: "Always use folder name for base filename" in "Creation options" section on "Client behavior" tab.

Instead of searching all files in each specified folder, it will filter files by their size. In the sample, it selects files of 1 MB over. You may change the limit size. To send name of source files, it uses file-list.

### Create multiple PAR2 sets for many files in a folder

Command | "path of script file" "path of folder1" "path of folder2" "path of folder3"...
Input | specify some folders
Action | This sample creates multiple PAR2 sets for many files in each selected folder. For example, when you supply 3 folders, it creates independent multiple PAR2 sets in every folder. In the sample, it will create a PAR2 set for 1000 source files. It's possible to change the limit value. When there are 3500 files in a folder, it will create 4 PAR2 sets in the folder.
Script file | `group_files.py`

To distinguish PAR2 files, it uses stable filename with serial numbering. They are like; `#1.par2`, `#2.par2`, `#3.par2`... When there are sub directories in a folder, it will search inner files. To send name of source files, it uses file-list. The process may be very slow for many files.

### Create multiple PAR2 sets for files or folders with Queuing GUI

Command | "path of script file" "path of file1 or folder1" "path of file2 or folder2" "path of file3 or folder3"...
Input | specify some files and/or folders (You may select them manually on GUI.)

Action

This sample creates multiple PAR2 sets for every selected files or folders. It creates one PAR2 set for each selected file or folder independently. PAR2 set for a file will be made in the same directory with the source file's name. PAR2 set for a folder will be made in the folder with the source folder's name. For example, when 3 files and 2 folders are selected, 5 items are shown on a list. Then, it will create 5 PAR2 sets continuously. It's possible to stop queue on GUI.

Script file | `queue_create.py`
Caution | While creation, existing PAR2 files are ignored. When there are old PAR2 files already, it doesn't erase them. (However it may over-write same name files.) If you want to re-create all PAR2 files newly, you must delete them at first manually.

You must set command-line options of par2j for creation. You should refer `Command_par2j.txt` in `help` folder. Because all creating PAR2 sets will use the same options, test with a few files to see result at first. When you want to confirm result by MultiPar, select a PAR2 set and push "Open with MultiPar" button.

While creation, it shows details on Command Prompt window. You can control the progress by pushing a key on the Command Prompt. You may pause the process by pushing P-key. You may resume the process by pushing R-key. You may cancel the process by pushing C-key.

You may create short-cut file of this script file. Put the short-cut on `desktop` or `SendTo` folder of Windows OS. Then, you can drag & drop files and/or folders on the short-cut. Or, select files on right-click "SendTo" menu. If you select one folder, it search inner items of the folder. If you select multiple items or one file, they are selected directly.

### Verify multiple PAR2 sets in a selected folder with Queuing GUI

Command | "path of script file" "path of folder"
Input | specify a folder (You may select it manually on GUI.)
Action | This sample verifies multiple PAR2 sets in a selected folder. For example, when there are 7 PAR2 sets in a folder, they are shown on a list. It will verify each PAR2 set continuously. It's possible to stop queue on GUI.
Script file | `queue_verify.py`
Caution | You must select MultiPar Option: "Re-use verification result" to be "For 3 days" or longer, and you should check "Don't search subfolders" in "Verification and Repair options" section on "Client behavior" tab.

In this sample, it tries verification only. If you want to repair a damaged set automatically, use `repair` command instead of `verify` of par2j. When you want to confirm result by MultiPar, select a PAR2 set and push "Open with MultiPar" button. You may repair on the MultiPar GUI.

While verification, it shows details on Command Prompt window. You can control the progress by pushing a key on the Command Prompt. You may pause the process by pushing P-key. You may resume the process by pushing R-key. You may cancel the process by pushing C-key. Even when you stop the verification task, it may save result partially.

When you push "Folder" button, it searches PAR2 sets in the selected folder. By default, It doesn't search files recursively, because it may be slow. If you want to search all sub-directories, you need to edit the script. You may change behavior of starting verification automatically or not by editing the script.

### Check difference of PAR and directory with GUI

Command | "path of script file" "path of folder1" "path of folder2" "path of folder3"...
Input | specify some folders
Action | This is a simple tool to show difference of PAR and directory contents.
Script file | `diff_folder.py`
Caution | Because it checks difference of files' existence and size only, it cannot detect broken files. Use MultiPar to see precise status of source files.

This sample uses `list` command of par2j. While it lists source files in the PAR2 set, it doesn't verify them. After comparison with current directory-tree, it paints blue color for additional files, red color for missing files, and yellow color for files of different size.

### Rename included source files in PAR2 sets with GUI

Command | "path of script file" "path of file"
Input | specify a PAR2 file
Action | This is a simple tool to edit names of source files in PAR2 files. Because it works in a single file, you don't need to set path of another application.
Script file | `par2_rename.py`
Caution | The modified PAR2 files by this tool are different from formal PAR2 files for renamed filenames. When someone generates new PAR2 files for renamed filenames by QuickPar/MultiPar, the PAR2 files are incompatible with these modified PAR2 files.

If you don't see debug output, you may rename the script file's extension to `.pyw`. Then, Command Prompt won't open.

How to use

1. Select a PAR2 file by pushing [ File ] button. PAR2 files of same base name will be listed.
2. Select a PAR2 file on the left list and push [ Read ] button. It's good to select the smallest PAR2 file for fast search. Only when PAR2 files are damaged, select a complete PAR2 file.
3. Type a new filename on a edit box. Select editing name on right list and push [ Rename ] button. You may edit multiple filenames contiuously.
4. After you finish to edit filenames, push [ Save ] button. PAR2 files will be saved with prefix "`new_`" in the same folder.

### Read a selected JSON file and show contents

Command | "path of script file" "path of file"
Input | specify a JSON file
Action | By setting `/w` option, par2j saves verification result on a JSON file. This sample uses the JSON file.
Script file | `read_json.py`
Caution | In the JSON file, par2j writes `/` as directory separator.

### Automate tasks after MultiPar GUI 's Creation

MultiPar GUI can start script after creation. The script file must be `auto_c.py` in the user's `save` folder. A user may write any script in this file. The script gets two parameters from GUI as below;
`%1 = Path of a recovery file
%2 = Path of base directory of source files`

I put a sample in "`tool\batch`" folder. `auto_c.py` shows two parameters only.

### Automate tasks after MultiPar GUI 's Verification / Repair

MultiPar GUI can start script after verification or repair. The script file must be `auto_v.py` or `auto_vl.py` in the user's `save` folder. A user may write any script in this file. The script gets three parameters from GUI as below;
`%1 = Path of a recovery file
%2 = Path of base directory of source files
%3 = Exit code of the used client (refer the command-line manual)`

I put two samples in "`tool\batch`" folder. `auto_v.py` shows three parameters only. `auto_vl.py` shows lists of recovery files and source files, too.