Help - Search - Members - Calendar
Full Version: par2 making batch
Hydrogenaudio Forums > Misc. > Off-Topic
jordi.c
I would like to make par2 files for every folder of the music files.

I can do this manual by going into every single folder and select the Music files (FLAC). This way takes me ages and a RSI arm wink.gif .

Is it possible to make automatically for every folder the amount of music tracks the same amount of par2 files with a batch?

Br.
Jordi
Synthetic Soul
I don't know what you mean by "same amount of PAR2 files". Do you mean that you want to create separate PAR2 files per FLAC file? Or, do you want to create one set of PAR2 files for all the FLAC files in one folder?

NB: In order to comprehend my questions you must realise that, when creating PAR2 data, multiple PAR2 files are usually created.

Therefore, I am asking, rather poorly: do you want to create a PAR2 set for each file individually (x sets per folder), or for all the FLAC files in a folder (1 set per folder)?

Either way can be done. If you want one set per folder then you may need to employ GLOB.EXE as well as PAR2.EXE - to create the list of files.
jordi.c
QUOTE(Synthetic Soul @ Jan 9 2008, 21:50) *

I don't know what you mean by "same amount of PAR2 files". Do you mean that you want to create separate PAR2 files per FLAC file? Or, do you want to create one set of PAR2 files for all the FLAC files in one folder?

NB: In order to comprehend my questions you must realise that, when creating PAR2 data, multiple PAR2 files are usually created.

Therefore, I am asking, rather poorly: do you want to create a PAR2 set for each file individually (x sets per folder), or for all the FLAC files in a folder (1 set per folder)?

Either way can be done. If you want one set per folder then you may need to employ GLOB.EXE as well as PAR2.EXE - to create the list of files.


I would like to make par2 files for only the music files. The blocks amount should be the same amount as the music files. E.g. 12 tracks in a folder = 12 blocks in a folder.

The actual amount of par2 files I don't care of course (i use 384000 block size most common for usenet).
Synthetic Soul
Here is a simple script. It requires PAR2.EXE and GLOB.EXE. It is possible that it requires the version of GLOB that comes with REACT, but it may not.

CODE
@ECHO OFF

SET ext=flac
SET pathToGlob=GLOB.EXE
SET pathToPar2=PAR2.EXE

PUSHD %1
FOR /D /r %%G IN (*.*) DO CALL :ProcessFolder "%%G"
POPD

PAUSE
GOTO :EOF

:ProcessFolder
PUSHD %1
SET fileCount=0
FOR %%B IN (*.%ext%) DO CALL :IncreaseCounter
IF %fileCount% EQU 0 GOTO :EOF
%pathToGlob% -c -v %pathToPar2% c -c%fileCount% -s384000 "parity.par2" *.%ext%
POPD
GOTO :EOF

:IncreaseCounter
SET /A fileCount=%fileCount% + 1
GOTO :EOF

Drop the root folder onto the batch file icon and it will create a PAR2 set called "parity" in any subfolder containing FLACs. It will use a block size of 384000, and recovery block count equal to that of the number of FLAC files in the folder.

I also have a version that uses the parent folder name for the name of the PAR2 set. It's a lot more code for this simple addition - and I would suggest testing with the code above to begin, but if you are interested here is the code:

CODE
@ECHO OFF

SET ext=flac
SET pathToGlob=GLOB.EXE
SET pathToPar2=PAR2.EXE

PUSHD %1
FOR /D /r %%G IN (*.*) DO CALL :ProcessFolder "%%G"
POPD

PAUSE
GOTO :EOF

:ProcessFolder
CALL :MakePath "%~1" "#-1#" parentFolder
PUSHD %1
SET fileCount=0
FOR %%B IN (*.%ext%) DO CALL :IncreaseCounter
IF %fileCount% EQU 0 GOTO :EOF
%pathToGlob% -c -v %pathToPar2% c -c%fileCount% -s384000 "%parentFolder%.par2" *.%ext%
POPD
GOTO :EOF

:IncreaseCounter
SET /A fileCount=%fileCount% + 1
GOTO :EOF

:MakePath
FOR /F "tokens=1-7 delims=\" %%G IN ("%~1") DO CALL :SplitPath "%~1" %2 %3 "%%G" "%%H" "%%I" "%%J" "%%K" "%%L" "%%M"
GOTO:EOF

:SplitPath
SET p0=%~1
Set fullPath=%~2
SHIFT
IF [%3] NEQ [""] SET p1=%~3& SET /A max=1
IF [%4] NEQ [""] SET p2=%~4& SET /A max=2
IF [%5] NEQ [""] SET p3=%~5& SET /A max=3
IF [%6] NEQ [""] SET p4=%~6& SET /A max=4
IF [%7] NEQ [""] SET p5=%~7& SET /A max=5
IF [%8] NEQ [""] SET p6=%~8& SET /A max=6
IF [%9] NEQ [""] SET p7=%~9& SET /A max=7

FOR /L %%G IN (1,1,7) DO CALL :SetReverseVar %%G

FOR /L %%G IN (-7,1,7) DO CALL :ReplaceTokens %%G

SET %2=%fullPath%
GOTO:EOF

:SetReverseVar
IF [%max%] LEQ [0] GOTO:EOF
CALL SET p-%1=%%p%max%%%
SET /A max-=1
GOTO:EOF

:ReplaceTokens
CALL SET token=%%p%1%%
CALL SET fullPath=%%fullPath:#%1#=%token%%%
GOTO:EOF

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.