REACT:Amending Cuesheet File References: Difference between revisions

From Hydrogenaudio Knowledgebase
(Added GSAR section)
No edit summary
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
When using [[REACT]] to rip to individual tracks you can request all cuesheets to be created, by specifying the following in REACT.ini:
When using [[REACT]] to rip to individual tracks you can request all cuesheets to be created (or just one with Akkurat's Mod 2.0.akku.b03), by specifying the following in REACT.ini:


'''When using Akkurat's Mod 2.0.akku.b03 or higher version'''
<pre>CreateCuesheet=mg</pre>
This will create the following file in the working directory:
* '''"@albumfile@.[mg].cue"''' (Multiple WAVE files with gaps (non-compliant))
'''otherwise use this setting'''
<pre>CreateAllCuesheets=1</pre>
<pre>CreateAllCuesheets=1</pre>


Line 20: Line 29:
The additional config code below uses the GNU tool [http://gnuwin32.sourceforge.net/packages/gsar.htm GSAR] to parse the cuesheet created by [[EAC]], and create a new cuesheet referencing the correctly-named files.  This is achieved in the following way:
The additional config code below uses the GNU tool [http://gnuwin32.sourceforge.net/packages/gsar.htm GSAR] to parse the cuesheet created by [[EAC]], and create a new cuesheet referencing the correctly-named files.  This is achieved in the following way:


# When the first track is processed the cuesheet will be copied to a new cuesheet file named "$cdartist$ - $album$.cue".
# When the first track is processed the cuesheet will be copied to a new cuesheet file named "$cdartist$ - $album$.cue". A batch command, setting the correct codepage, is written to a temporary batch file called "update-cuesheet.bat".
# Every time a track is processed a GSAR command, to replace that track's filename, is written to a temporary batch file called "update-cuesheet.bat".
# Every time a track is processed, a GSAR command, to replace that track's filename, is written to the temporary batch file.
# When the last track is processed this batch file is executed, executing a GSAR command for each track.
# When the last track is processed, a GSAR command is executed to escape percent signs (%) in the temporary batch file.
# The temporary batch file is executed, executing a GSAR command for each track.
# The file "update-cuesheet.bat" is deleted.
# The file "update-cuesheet.bat" is deleted.


Line 30: Line 40:
The following lines need to be added to the code which is run for the format you are using for each track:
The following lines need to be added to the code which is run for the format you are using for each track:


<pre>SET trackCueFile="$cdartist$ - $album$.cue"
<pre>
IF NOT EXIST %trackCueFile% COPY "@albumfile@.[mg].cue" %trackCueFile%
SET trackCueFile="$cdartist$ - $album$.cue"
IF NOT EXIST %trackCueFile% (
    COPY "@albumfile@.[mg].cue" %trackCueFile%
    ECHO CHCP 1252 ^| PROMPT>>update-cuesheet.bat
)
ECHO @tools@\GSAR.EXE "-s@basename@.wav" "-r%TrackName%.wv" -o %trackCueFile%>>update-cuesheet.bat</pre>
ECHO @tools@\GSAR.EXE "-s@basename@.wav" "-r%TrackName%.wv" -o %trackCueFile%>>update-cuesheet.bat</pre>


Line 45: Line 59:
         @ECHO OFF
         @ECHO OFF
         SET trackCueFile="$cdartist$ - $album$.cue"
         SET trackCueFile="$cdartist$ - $album$.cue"
         IF NOT EXIST %trackCueFile% COPY "@albumfile@.[mg].cue" %trackCueFile%
         IF NOT EXIST %trackCueFile% (
            COPY "@albumfile@.[mg].cue" %trackCueFile%
            ECHO CHCP 1252 ^| PROMPT>>update-cuesheet.bat
        )
         ECHO @tools@\GSAR.EXE "-s@basename@.wav" "-r%TrackName%.wv" -o %trackCueFile%>>update-cuesheet.bat
         ECHO @tools@\GSAR.EXE "-s@basename@.wav" "-r%TrackName%.wv" -o %trackCueFile%>>update-cuesheet.bat
         IF %have_cover%==1 IF NOT EXIST folder.jpg COPY "@cover@" folder.jpg
         IF %have_cover%==1 IF NOT EXIST folder.jpg COPY "@cover@" folder.jpg
Line 57: Line 74:
<pre>ECHO @tools@\GSAR.EXE "-s@basename@.wav""" WAVE" "-r%TrackName%.mp3""" MP3" -o %trackCueFile%>>update-cuesheet.bat</pre>
<pre>ECHO @tools@\GSAR.EXE "-s@basename@.wav""" WAVE" "-r%TrackName%.mp3""" MP3" -o %trackCueFile%>>update-cuesheet.bat</pre>


Also, note that the example uses the "multiple WAVE files with gaps (non-compliant)" cuesheet as its source.  This is the cuesheet that most users would require; however you can replace "@albumfile@.[mg].cue" with "@albumfile@.[m].cue" or "@albumfile@.[mc].cue" if you wish.
Also, note that the example uses the "multiple WAVE files with gaps (non-compliant)" cuesheet as its source.  This is the cuesheet that most users would require; however you can replace "@albumfile@.[mg].cue" with "@albumfile@.[m].cue" or "@albumfile@.[mc].cue" if you wish. '''NOTE!''' When using Akkurat's Mod 2.0.akku.b03 or higher version, if you change the '''[mg]''' used in the example to another cuesheet, you must change the '''CreateCuesheet=''' option to match your replacement.




Line 65: Line 82:


<pre>
<pre>
@tools@\GSAR.EXE -s%% -r%%%% -o update-cuesheet.bat
CALL update-cuesheet.bat
CALL update-cuesheet.bat
DEL update-cuesheet.bat
DEL update-cuesheet.bat
Line 76: Line 94:
         IF %add_rg%==1 @tools@\wvgain.exe -a *.wv
         IF %add_rg%==1 @tools@\wvgain.exe -a *.wv
         REM COPY /Y "@eaclog@" "EAClog.txt"
         REM COPY /Y "@eaclog@" "EAClog.txt"
        @tools@\GSAR.EXE -s%% -r%%%% -o update-cuesheet.bat
         CALL update-cuesheet.bat
         CALL update-cuesheet.bat
         DEL update-cuesheet.bat
         DEL update-cuesheet.bat
Line 82: Line 101:
</pre>
</pre>


These two lines are universal, and can be added to any format's section with no need for change.
These three lines are universal, and can be added to any format's section with no need for change.
 


'''Requirements'''


===Requirements===
You will need to download the Windows version of [http://gnuwin32.sourceforge.net/packages/gsar.htm GSAR], and put the executable in your [[REACT]] tools directory.
You will need to download the Windows version of [http://gnuwin32.sourceforge.net/packages/gsar.htm GSAR], and put the executable in your [[REACT]] tools directory.
===Using GSAR For Other Requirements===
If you will be using GSAR for other string replacement in your config, you may need to ensure that two characters are escaped before creating your GSAR command line.
If you are dealing solely with filenames, as in the section above, you do not need to worry: these are both illegal filename characters and therefore cannot possibly raise an issue.
'''If you are not dealing solely in filenames''', you will need to ensure that any double quotes (") and colons (:) are escaped.  Double quotes may be escaped by replacing one instance with three (" -> """) or by replacing it with the correct character code (" -> :034 (decimal) or " -> :x22 (hex)).  Colons should be escaped by prefixing with another colon. (: -> ::)
E.g.: If your string is as follows:
A Test: using "both" characters
... any of the lines below may be used in its place:
A Test:: using """both""" characters
A Test:: using :034both:034 characters
A Test:: using :x22both:x22 characters
Below is some example code to escape an existing batch file variable, "myVar", before passing it to GSAR:
<pre>
SET myVar=%myVar::=::%
SET myVar=%myVar:"=:x22%
@tools@\GSAR.EXE "-sSome Existing Text" "-r%myVar%" -o myfile.txt
</pre>
====Using GSAR to Escape Percent Signs Written to Batch Files====
When using a percent sign in your config it must be escaped like so: %%.  This ensures that it is not mistaken for the beginning of a batch file variable (e.g.: %myVar%).
If your config needs to create and execute a batch file on the fly, as the example in [[REACT:Amending_Cuesheet_File_References#Using_GSAR|Using GSAR]] does, you will need to re-escape any percent signs, as the act of writing the batch file will unescape any written.
You can use [http://gnuwin32.sourceforge.net/packages/gsar.htm GSAR], before executing your batch file, to ensure that all percent signs written to the file are properly escaped.
GSAR.EXE -s%% -r%%%% -o update-cuesheet.bat
This command will escape all percent signs (% -> %%) in the file "update-cuesheet.bat". The -o switch tells GSAR to overwrite the file, rather than write the amended text to a new file.




Line 148: Line 211:
</pre>
</pre>


These two lines are universal, and can be added to any format's section with no need for change.  Note though, that the example uses the "multiple WAVE files with gaps (non-compliant)" cuesheet as its source.  This is the cuesheet that most users would require; however you can replace "@albumfile@.[mg].cue" with "@albumfile@.[m].cue" or "@albumfile@.[mc].cue" if you wish.
These two lines are universal, and can be added to any format's section with no need for change.  Note though, that the example uses the "multiple WAVE files with gaps (non-compliant)" cuesheet as its source.  This is the cuesheet that most users would require; however you can replace "@albumfile@.[mg].cue" with "@albumfile@.[m].cue" or "@albumfile@.[mc].cue" if you wish. '''NOTE!''' When using Akkurat's Mod 2.0.akku.b03 or higher version, if you change the '''[mg]''' used in the example to another cuesheet, you must change the '''CreateCuesheet=''' option to match your replacement.


'''Requirements'''


===Requirements===
You will need to download the Windows version of [http://gnuwin32.sourceforge.net/packages/sed.htm SED], including its dependencies ("libintl3.dll" and "libiconv2.dll"), and put all three files in your [[REACT]] tools directory.
You will need to download the Windows version of [http://gnuwin32.sourceforge.net/packages/sed.htm SED], including its dependencies ("libintl3.dll" and "libiconv2.dll"), and put all three files in your [[REACT]] tools directory.


Line 159: Line 222:




[[Category:REACT|Amending Cuesheet File References]]
[[Category:REACT Guides|Amending Cuesheet File References]]

Latest revision as of 19:37, 29 July 2010

When using REACT to rip to individual tracks you can request all cuesheets to be created (or just one with Akkurat's Mod 2.0.akku.b03), by specifying the following in REACT.ini:

When using Akkurat's Mod 2.0.akku.b03 or higher version

CreateCuesheet=mg

This will create the following file in the working directory:

  • "@albumfile@.[mg].cue" (Multiple WAVE files with gaps (non-compliant))


otherwise use this setting

CreateAllCuesheets=1

This will create the following files in the working directory:

  • "@albumfile@.[s].cue" (Single WAVE file)
  • "@albumfile@.[mg].cue" (Multiple WAVE files with gaps (non-compliant))
  • "@albumfile@.[m].cue" (Multiple WAVE files with gaps left out)
  • "@albumfile@.[mc].cue" (Multiple WAVE files with corrected gaps)


The multi-file cuesheets will reference the tracks using the filename format set in EAC, which should be "$cdartist$ - $album$ - $track$ - $title$" for standard albums, and specifying a ".wav" extension. However, this is unlikely to be the format that your track files are actually in, which means that the cuesheet will need to be amended in order to be useful.

Below, you will find example code for two solutions, using two different tools. You are recommended to use GSAR for this purpose, as certain special characters, e.g.: the ampersand, if used in your filenames, may cause problems when using SED.


Using GSAR

The additional config code below uses the GNU tool GSAR to parse the cuesheet created by EAC, and create a new cuesheet referencing the correctly-named files. This is achieved in the following way:

  1. When the first track is processed the cuesheet will be copied to a new cuesheet file named "$cdartist$ - $album$.cue". A batch command, setting the correct codepage, is written to a temporary batch file called "update-cuesheet.bat".
  2. Every time a track is processed, a GSAR command, to replace that track's filename, is written to the temporary batch file.
  3. When the last track is processed, a GSAR command is executed to escape percent signs (%) in the temporary batch file.
  4. The temporary batch file is executed, executing a GSAR command for each track.
  5. The file "update-cuesheet.bat" is deleted.


Creating the GSAR commands for each track

The following lines need to be added to the code which is run for the format you are using for each track:

SET trackCueFile="$cdartist$ - $album$.cue"
IF NOT EXIST %trackCueFile% (
    COPY "@albumfile@.[mg].cue" %trackCueFile%
    ECHO CHCP 1252 ^| PROMPT>>update-cuesheet.bat
)
ECHO @tools@\GSAR.EXE "-s@basename@.wav" "-r%TrackName%.wv" -o %trackCueFile%>>update-cuesheet.bat

Here it is in the WavPack section:

IF NOT @Wavpack@==1 GOTO end_wavpack_tracks
    IF NOT EXIST %TrackDir_Wavpack% MKDIR %TrackDir_Wavpack%
    PUSHD %TrackDir_Wavpack%
        IF @various@==1 SET VA_tag=-w "album artist=@VA@"
        ECHO ON
        @tools@\wavpack.exe @Opt_Wavpack@ %VA_tag% -w artist="@artist@" -w album="@album@" -w track="@track@/@numtracks@" -w title="@title@" -w year="@year@" -w genre="@genre@" -w comment="@comment@" -w encodedby="%USERNAME%" -w encodersettings="Wavpack @Ver_Wavpack@ @Opt_Wavpack@" "@source@" "%TrackName%.wv"
        @ECHO OFF
        SET trackCueFile="$cdartist$ - $album$.cue"
        IF NOT EXIST %trackCueFile% (
            COPY "@albumfile@.[mg].cue" %trackCueFile%
            ECHO CHCP 1252 ^| PROMPT>>update-cuesheet.bat
        )
        ECHO @tools@\GSAR.EXE "-s@basename@.wav" "-r%TrackName%.wv" -o %trackCueFile%>>update-cuesheet.bat
        IF %have_cover%==1 IF NOT EXIST folder.jpg COPY "@cover@" folder.jpg
        TITLE @track@/@numtracks@ - "@album@"
    POPD
:end_wavpack_tracks

Note that the extension ("wv") will need to be changed depending on the format that you are using. Additionally, if you are using MP3, you will need to use the following line instead, which correctly changes the file type to MP3 from WAVE:

ECHO @tools@\GSAR.EXE "-s@basename@.wav""" WAVE" "-r%TrackName%.mp3""" MP3" -o %trackCueFile%>>update-cuesheet.bat

Also, note that the example uses the "multiple WAVE files with gaps (non-compliant)" cuesheet as its source. This is the cuesheet that most users would require; however you can replace "@albumfile@.[mg].cue" with "@albumfile@.[m].cue" or "@albumfile@.[mc].cue" if you wish. NOTE! When using Akkurat's Mod 2.0.akku.b03 or higher version, if you change the [mg] used in the example to another cuesheet, you must change the CreateCuesheet= option to match your replacement.


Executing the batch file

The following lines need to be added to the code which is run for the format you are using at the end of the config:

@tools@\GSAR.EXE -s%% -r%%%% -o update-cuesheet.bat
CALL update-cuesheet.bat
DEL update-cuesheet.bat

Here they are in the WavPack section:

IF @Wavpack@==1 (
    PUSHD %TrackDir_Wavpack%
        IF %add_rg%==1 @tools@\wvgain.exe -a *.wv
        REM COPY /Y "@eaclog@" "EAClog.txt"
        @tools@\GSAR.EXE -s%% -r%%%% -o update-cuesheet.bat
        CALL update-cuesheet.bat
        DEL update-cuesheet.bat
    POPD
)

These three lines are universal, and can be added to any format's section with no need for change.


Requirements

You will need to download the Windows version of GSAR, and put the executable in your REACT tools directory.


Using GSAR For Other Requirements

If you will be using GSAR for other string replacement in your config, you may need to ensure that two characters are escaped before creating your GSAR command line.

If you are dealing solely with filenames, as in the section above, you do not need to worry: these are both illegal filename characters and therefore cannot possibly raise an issue.

If you are not dealing solely in filenames, you will need to ensure that any double quotes (") and colons (:) are escaped. Double quotes may be escaped by replacing one instance with three (" -> """) or by replacing it with the correct character code (" -> :034 (decimal) or " -> :x22 (hex)). Colons should be escaped by prefixing with another colon. (: -> ::)


E.g.: If your string is as follows:

A Test: using "both" characters

... any of the lines below may be used in its place:

A Test:: using """both""" characters
A Test:: using :034both:034 characters
A Test:: using :x22both:x22 characters


Below is some example code to escape an existing batch file variable, "myVar", before passing it to GSAR:

SET myVar=%myVar::=::%
SET myVar=%myVar:"=:x22%

@tools@\GSAR.EXE "-sSome Existing Text" "-r%myVar%" -o myfile.txt

Using GSAR to Escape Percent Signs Written to Batch Files

When using a percent sign in your config it must be escaped like so: %%. This ensures that it is not mistaken for the beginning of a batch file variable (e.g.: %myVar%).

If your config needs to create and execute a batch file on the fly, as the example in Using GSAR does, you will need to re-escape any percent signs, as the act of writing the batch file will unescape any written.


You can use GSAR, before executing your batch file, to ensure that all percent signs written to the file are properly escaped.

GSAR.EXE -s%% -r%%%% -o update-cuesheet.bat

This command will escape all percent signs (% -> %%) in the file "update-cuesheet.bat". The -o switch tells GSAR to overwrite the file, rather than write the amended text to a new file.


Using SED

The additional config code below uses the GNU tool SED to parse the cuesheet created by EAC, and create a new cuesheet referencing the correctly-named files. This is achieved in the following way:

  1. Every time a track is processed a SED command, to replace that track's filename, is written to a temporary text file called "sedlist.txt".
  2. When the last track is processed this file is passed to SED which executes each command on the cuesheet text, and writes the new text to a new cuesheet file named "$cdartist$ - $album$.cue".
  3. The file "sedlist.txt" is deleted.


Writing the SED commands for each track

The following line needs to be added to the code which is run for the format you are using for each track:

ECHO s/FILE "@basename@\.wav"/FILE "%TrackName%\.wv"/>>sedlist.txt

Here it is in the WavPack section:

IF NOT @Wavpack@==1 GOTO end_wavpack_tracks
    IF NOT EXIST %TrackDir_Wavpack% MKDIR %TrackDir_Wavpack%
    PUSHD %TrackDir_Wavpack%
        IF @various@==1 SET VA_tag=-w "album artist=@VA@"
        ECHO ON
        @tools@\wavpack.exe @Opt_Wavpack@ %VA_tag% -w artist="@artist@" -w album="@album@" -w track="@track@/@numtracks@" -w title="@title@" -w year="@year@" -w genre="@genre@" -w comment="@comment@" -w encodedby="%USERNAME%" -w encodersettings="Wavpack @Ver_Wavpack@ @Opt_Wavpack@" "@source@" "%TrackName%.wv"
        ECHO s/FILE "@basename@\.wav"/FILE "%TrackName%\.wv"/>>sedlist.txt
        @ECHO OFF
        IF %have_cover%==1 IF NOT EXIST folder.jpg COPY "@cover@" folder.jpg
        TITLE @track@/@numtracks@ - "@album@"
    POPD
:end_wavpack_tracks

Note that the extension ("wv") will need to be changed depending on the format that you are using. Additionally, if you are using MP3, you will need to use the following line instead, which correctly changes the file type to MP3 from WAVE:

ECHO s/FILE "@basename@\.wav" WAVE/FILE "%TrackName%\.mp3" MP3/>>sedlist.txt


Executing SED

The following lines need to be added to the code which is run for the format you are using at the end of the config:

@tools@\SED -f sedlist.txt <"@albumfile@.[mg].cue" >"$cdartist$ - $album$.cue"
DEL sedlist.txt

Here they are in the WavPack section:

IF @Wavpack@==1 (
    PUSHD %TrackDir_Wavpack%
        IF %add_rg%==1 @tools@\wvgain.exe -a *.wv
        REM COPY /Y "@eaclog@" "EAClog.txt"
        @tools@\SED -f sedlist.txt <"@albumfile@.[mg].cue" >"$cdartist$ - $album$.cue"
        DEL sedlist.txt
    POPD
)

These two lines are universal, and can be added to any format's section with no need for change. Note though, that the example uses the "multiple WAVE files with gaps (non-compliant)" cuesheet as its source. This is the cuesheet that most users would require; however you can replace "@albumfile@.[mg].cue" with "@albumfile@.[m].cue" or "@albumfile@.[mc].cue" if you wish. NOTE! When using Akkurat's Mod 2.0.akku.b03 or higher version, if you change the [mg] used in the example to another cuesheet, you must change the CreateCuesheet= option to match your replacement.

Requirements

You will need to download the Windows version of SED, including its dependencies ("libintl3.dll" and "libiconv2.dll"), and put all three files in your REACT tools directory.


Related Thread

This tip is a result of a string of posts between lipidicman and Synthetic Soul in the REACT 2 thread beginning with this post.