Creating multiple par2 sets via batch file

So someone wrote in to me about my par2-to-folder batch process post that I did back in November. They came asking for a batch solution to a different par2 related problem. Basically, they had ripped their entire CD collection to FLAC and now wanted to create par2 sets for each respective album folder. Fair enough. Doing that sort of job manually would drive any half intelligent person crazy.

I did some research and found that those great guys at parchive (makers of QuickPar, my favorite par GUI of choice) have made the par2 command version available to download. Before we begin the lesson I'm directing you to their website to download the par2cmdline client so you can utilize the appropriate calls from Windows command. Unless you plan on fiddling with the source code, grab yourself the Win32 binary that's already compiled.

Download. Unzip. Read the READ_ME (it's there for a reason and will tell you how to manipulate the option flags so you can create the specific par2 blocks you want). If you want to use my batch code without changing anything, move par2.exe into C:\WINDOWS\ . Ok, that was the hardest part. Now let's get a visual idea of what my batch process will do.

Here's a temp directory with some albums sorted into folders. Each folder has nfo, sfv, m3u, and mp3 files, but it doesn't matter what sort of files I have in them because I'm just going to make par2 volumes based on their entire contents:



Here's what happens when I run make_par2.bat. Go Reed-Solomon matrix!:



And the results:



Your WYSIWYG interface can't do that, can it? Here's the batch contents:

FOR /R %%g IN (.) DO C:\WINDOWS\par2.exe c -r10 -s384000 "%%g\%%~ng.par2" "%%g\*"
del /q *.par2

That first line does everything important. I'll try to break it down into manageable parts.

FOR /R %%g IN (.)

That says FOR every file in the current directory (.) of the batch, remember the file as %%g so we can use it later on. /R indicates we want to recurse subdirectories, which is really important because we want to create pars for the files in the album folders and not really the root folder.

DO C:\WINDOWS\par2.exe c -r10 -s384000 "%%g\%%~ng.par2" "%%g\*"

This code calls the par2cmdline executable (which can be found at C:\WINDOWS\par2.exe) to make our respective par2 files. If you read the READ_ME like I said you should, you'll know that c = create, -r10 = 10% redundancy, and -s384000 = block sizes of 384,000 (Usenet standard). You can change the numbers to suit the standards of wherever you're posting at.

Remember how I said we want to remember a file or folder name in the FOR call as %%g? "%%g\%%~ng.par2" assigns the path and chosen name to the par2 volume. This allows me to say the recovery set should be called The_Audition-Champion-(Advance)-2008-FNT.par2 and it should go in the The_Audition-Champion-(Advance)-2008-FNT folder. If I had typed something like "recovery\test.par2" all my par2 files would go into a directory called "recovery" with the name "test.par2".

Finally "%%g\*" lets the create function know what we want to construct our par2 archive from--all the files in %%g's directory. The "\*" is what allows us be unconcerned about the file type (mp3s, flac, nfo, txt, etc) since * says make par2 out of everything.

That's the first line in a nutshell. And the second line?

del /q *.par2

All this does is delete the par2 files in same directory as make_par2.bat. Usually we don't want to create repair volumes there. For example, if I had a jpg and text file in addition to what was already in C:\TEMP, the batch file would make pars for these files as well. We'll delete them since we only care about the album folder par2s.

So that's it! Hopefully it was more helpful than confusing.

3 voiced:

Gozzy said...

thanks, very nice post!

this is more about batch scripting than creating par2 files because you can do anything with that loop.

FOR /R %%g IN (.) DO echo "%%g\*"

however i think you did not describe the loop correctly:

"FOR /R %%g IN (.)

That says FOR every file in the current directory (.) of the batch"

%%g actually represents the sub folders from where you run this right?

i wonder how you do get the filenames, maybe a loop in a loop, something like

FOR /R %%g IN (.) DO FOR /F %%f(ile) IN %%g DO echo "%%f"

however above does not work, do you know howto make it work?

again, very nice post

Gozzy,

Amsterdam - Holland

Ramrod said...

""%%g\%%~ng.par2" assigns the path and chosen name to the par2 volume. This allows me to say the recovery set should be called The_Audition-Champion-(Advance)-2008-FNT.par2 and it should go in the The_Audition-Champion-(Advance)-2008-FNT folder."

Is it possible to program it to check for the sfv filename and use that as the par2 filenames too, instead of what you have done, use the directory name?

Emit said...

Thanks so much for this!

However, I would also like it based on filename of the rars instead of foldername. Is there a way for it to also check for Sample directory and if there is one to make 30% redundancy based on the filename of the sample?

Thanks!

 

Meet the Author

Hi, I am Julie.
Sometimes Jules Juke.
This is where I ramble, reflect, and refocus.