Any bash scripters can help me with a metaflac bash script

Help for Audacity on GNU/Linux.
Forum rules
ImageThis forum is for Audacity on GNU/Linux.
Please state:
  • which version of Linux you are using,
  • the exact three-section version number of Audacity from Help menu > About Audacity,
  • whether you installed your distribution's release, PPA version, or compiled Audacity from source code.

Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade (see https://www.audacityteam.org/download/).
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Singtoh
Posts: 84
Joined: Fri Nov 23, 2012 1:43 am
Operating System: Please select

Re: Any bash scripters can help me with a metaflac bash scri

Post by Singtoh » Sat Dec 01, 2012 4:10 pm

ragnar.jensen wrote:
Singtoh wrote: Question for you though?? Isn't there suppose to be a log going into the /tmp/no_rpg_data.$$ directory, or is that just a place where the script works its magic?? If I go watch the tmp directory as this is working I can see flashes of files popping up on screen but nothing ever goes into the /tmp/no_rpg_data.$$ directory(I probably fingered something up again) :oops: ?? Just curious??
/tmp/no_rpg_data.$$ is a temporary file. $$ is substituted for the current process' ID, so the actual file name will be /tmp/no_rpg_data. with a number that is different for each run of the script appended. If the script detects that replaygain data is missing in a flac file, it prints its output to the temporary file instead of printing to the screen. Then, at the end of the script, it checks for the existence of the temporary file (meaning that we actually found flac files without replaygain data). If the temp file exists, the separator is printed, the temp file is dumped to the screen...

Code: Select all

[ -f "$GAIN_MISSING_FILE" ] && echo "========= ReplayGain Data Missing =========" && cat $GAIN_MISSING_FILE
...and finally the temp file is removed.

Code: Select all

rm -f $GAIN_MISSING_FILE
This is to be able to defer output for those files with missing tags to the end of the log.
Singtoh wrote:As I said in my last post, it would be really really good to be able to tell the script an equal to command, say equal to -10dB and it puts to the log only those files that are at -10dB, nothing higher, nothing lower...
By equal to -10, do you mean the truncated values (decimals removed) equals -10? I.e. "equals -10" means "is between -10.00 and -10.99".
Singtoh wrote:Time for a beer
OK, will do. :D

--
Ragnar
Hello Ragnar,

"By equal to -10, do you mean the truncated values (decimals removed) equals -10? I.e. "equals -10" means "is between -10.00 and -10.99"."

Yes, that will work, decimals removed/truncated. I'm not sure if awk will find a 10.99 figure or 8.50 figure or any variable numer and put it to log unless it a whole number. I'm not the code guru like you :ugeek: :) If we could define/limit it to outputting only equal to eg. -10db, -4dB , -6dB or whatever the -/+ X variable is that would be a good thing. :D Yes, between -10dB and -10.99dB rounded/truncated so the awk knows only to log what the -/+X value is that would be super :D +/- one dB is not going to affect what I am trying to accomplish ;) if it's not too much trouble that is, I don't mean to put you out, you have been wonderful :D Here is a snippet of the output I am getting now, I think something is amiss, maybe along the lines of what you posted earlier about the ls thing. Not sure but I still get that one ERROR: reading metadata, status = "FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE" at the start of the log and then the other "error stated below. :? . This is spread thru the log but there seems to be no pattern or consistency to it: It's maybe every 20 to 100 lines or so??

/home/patrick/keys/*.flac: ERROR: reading metadata, status = "FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE"

The FLAC file could not be opened. Most likely the file does not exist
or is not readable.
/home/patrick/keys/Carole King - The Collection/*.flac: ERROR: reading metadata, status = "FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE", this was taken from the very first line of the log.

And here is another snippet:

/home/patrick/ragnargainnewtest1.sh: 61: /home/patrick/ragnargainnewtest1.sh: /tmp/no_rpg_data.16010: not found

and that goes rite thru the log, it seems random :? Maybe the code in my original script is out of whack a bit?? :oops: I have been trying different things but can't seem to make it go away?? :( Thanks Ragnar, again, I can't thank you enough :D

Ok, more beer :D :D :D :D :D

Cheers,

Singtoh

Singtoh
Posts: 84
Joined: Fri Nov 23, 2012 1:43 am
Operating System: Please select

Re: Any bash scripters can help me with a metaflac bash scri

Post by Singtoh » Sun Dec 02, 2012 8:18 am

Hello again Ragnar,

I have been searching google for the problem with the FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE error I'm getting in the output of the script
("/media/Storage/processmusic/12replaygain/test/*.flac: ERROR: reading metadata, status = "FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE"

The FLAC file could not be opened. Most likely the file does not exist")

And I found this bit of info:

"This is just a problem with the path in your batch file. The batch file is trying to read non-existant files along the way. If you only had 10 files to check then they were checked and verified. It is the non-existent files that are giving you the errors.

This can be fixed by modifying the directory path settings in the batch file".

This came from someone running winDOZE and it is a very old post from 2004, but it may be related to what I am seeing. I haven't a clue about fixing the directory path settings in the script, if in fact that is the problem?? Would you happen to have any suggestions on what to change in the directory path settings?? I have been trying a few different things but am not having any luck making those "errors" dissappear.

Thanks Ragnar,

Cheers,

Singtoh

ragnar.jensen
Posts: 118
Joined: Thu Jan 26, 2012 7:39 pm
Operating System: Please select

Re: Any bash scripters can help me with a metaflac bash scri

Post by ragnar.jensen » Tue Dec 04, 2012 8:11 pm

I think there are still issues with file names with white space in them.
Try this one:

Code: Select all

#!/bin/bash
# This script assumes that your FLAC files have at least the ALBUM, ARTIST and TITLE tags.
# If any of them are missing in a file, that file will probably not be shown correctly, if at all.

GAIN_MISSING_FILE=/tmp/no_rpg_data.$$   # Name of temp file where we store tracks that have no replaygain data.
echo "You entered: '${*-}'"

(
if [ ! -d "$1" ]
then
   echo "Arg "$1" is NOT a directory!"
   exit $ARGUMENT_NOT_DIRECTORY
fi

flacnum=`ls "$1" | grep -c \.flac`

if [ $flacnum -lt 1 ]
then
   echo $1" (No FLAC files, moving on)"
   exit 0
else
   echo $1" ("$flacnum" FLAC files)"
fi

echo "Tag Values Retrieved:"
# Set bash's Internal Field Separator to newline only. It is important that there's nothing at all after the quote in the next line. Not even a space.
IFS='
'
for file in "$1"/*.flac
do
        metaflac --show-tag=ALBUM --show-tag=ARTIST --show-tag=TITLE --show-tag=REPLAYGAIN_TRACK_GAIN --show-tag=REPLAYGAIN_ALBUM_GAIN "$file"  | awk 'BEGIN {
        LIMIT=-8; # Adjust LIMIT to taste.
        LOWERLIMIT=LIMIT - 1
        IGNORECASE=1
        RS = ""
        FS = "n"
        GAIN_MISSING_FILE="'${GAIN_MISSING_FILE}'"
}

{
        REPLAYGAIN_TRACK_GAIN=$4 ; REPLAYGAIN_ALBUM_GAIN=$5
        split($1, array, "="); ALBUM=array[2]
        split($2, array, "="); ARTIST=array[2]
        split($3, array, "="); TITLE=array[2]
        if(REPLAYGAIN_TRACK_GAIN>"") {
                split($4, array, "=")
                split(array[2], array2, " ")
                TRACKGAIN=array2[1]
        } else {
                TRACKGAIN="N/A"
        }

        if(REPLAYGAIN_ALBUM_GAIN>"") {
                split($5, array, "=")
                split(array[2], array2, " ")
                ALBUMGAIN=array2[1]
        } else {
                ALBUMGAIN="N/A"
        }

        if(TRACKGAIN=="N/A" || ALBUMGAIN=="N/A") {
                print "ALBUM="ALBUM"nARTIST="ARTIST"nTITLE="TITLE"nREPLAYGAIN_TRACK_GAIN="TRACKGAIN"nREPLAYGAIN_ALBUM_GAIN="ALBUMGAIN"n" >> GAIN_MISSING_FILE
        } else {
                #if(TRACKGAIN<LIMIT) print "ALBUM="ALBUM"nARTIST="ARTIST"nTITLE="TITLE"nREPLAYGAIN_TRACK_GAIN="TRACKGAIN" dBnREPLAYGAIN_ALBUM_GAIN="ALBUMGAIN" dBn";
                if(TRACKGAIN<=LIMIT && TRACKGAIN>LOWERLIMIT) print "ALBUM="ALBUM"nARTIST="ARTIST"nTITLE="TITLE"nREPLAYGAIN_TRACK_GAIN="TRACKGAIN" dBnREPLAYGAIN_ALBUM_GAIN="ALBUMGAIN" dBn";
        }
}
'
done
[ -s "$GAIN_MISSING_FILE" ] && echo "========= ReplayGain Data Missing =========" && cat $GAIN_MISSING_FILE
)  2>&1 | tee -a rgainvaluesMUSIC.log
rm -f $GAIN_MISSING_FILE
I have reintroduced the custom IFS, to make bash ignore spaces in pathnames.
Setting LIMIT to X will now catch anything between X.00 and X.99


If you still get errors, please post a complete log and your version of the script (since you're hacking at it :D ).
You can add an "-x" to the very first line, so it reads "#!/bin/bash -x". That will cause bash to print a lot of extra output about what it's doing that might help in debugging.

--
Ragnar

Singtoh
Posts: 84
Joined: Fri Nov 23, 2012 1:43 am
Operating System: Please select

Re: Any bash scripters can help me with a metaflac bash scri

Post by Singtoh » Wed Dec 05, 2012 12:08 pm

Hello Ragnar,

Thank you very big for the new code :D and I would like to tell you that it works wonderfully :D Every thing happens as it is supposed to and you just made things a lot easier for me :D Here is the code after I added a couple of things to the metaflac section(TRACKNUMBER and SAMPLERATE):

Code: Select all

#!/bin/bash
# This script assumes that your FLAC files have at least the ALBUM, ARTIST and TITLE tags.
# If any of them are missing in a file, that file will probably not be shown correctly, if at all.

GAIN_MISSING_FILE=/tmp/no_rpg_data.$$   # Name of temp file where we store tracks that have no replaygain data.
#echo "You entered: '${*-}'"

(
if [ ! -d "$1" ]
then
   echo "Arg "$1" is NOT a directory!"
   exit $ARGUMENT_NOT_DIRECTORY
fi

flacnum=`ls "$1" | grep -c \.flac`

if [ $flacnum -lt 1 ]
then
   echo $1" (No FLAC files, moving on)"
   exit 0
else
   echo $1" ("$flacnum" FLAC files)"
fi

#echo "---------"
# Set bash's Internal Field Separator to newline only. It is important that there's nothing at all after the quote in the next line. Not even a space.
IFS='
'
for file in "$1"/*.flac 
do
        metaflac --show-sample-rate --show-tag=TRACKNUMBER --show-tag=ALBUM --show-tag=ARTIST --show-tag=TITLE --show-tag=REPLAYGAIN_TRACK_GAIN --show-tag=REPLAYGAIN_ALBUM_GAIN "$file" | awk 'BEGIN {
        LIMIT=-8; # Adjust LIMIT to taste.
        LOWERLIMIT=LIMIT - 1
        IGNORECASE=1
        RS = ""
        FS = "n"
        GAIN_MISSING_FILE="'${GAIN_MISSING_FILE}'"
}

{
        REPLAYGAIN_TRACK_GAIN=$6 ; REPLAYGAIN_ALBUM_GAIN=$7
	split($1, array, "="); SAMPLERATE=array[2]
	split($2, array, "="); TRACKNUMBER=array[2]
	split($3, array, "="); ALBUM=array[2]
        split($4, array, "="); ARTIST=array[2]
        split($5, array, "="); TITLE=array[2]
	if(REPLAYGAIN_TRACK_GAIN>"") {
                split($6, array, "=")
                split(array[2], array2, " ")
                TRACKGAIN=array2[1]
        } else {
                TRACKGAIN="N/A"
        }

        if(REPLAYGAIN_ALBUM_GAIN>"") {
                split($7, array, "=")
                split(array[2], array2, " ")
                ALBUMGAIN=array2[1]
        } else {
                ALBUMGAIN="N/A"
        }

        if(TRACKGAIN=="N/A" || ALBUMGAIN=="N/A") {
                print "SAMPLERATE="SAMPLERATE"nTRACKNUMBER="TRACKNUMBER"nALBUM="ALBUM"nARTIST="ARTIST"nTITLE="TITLE"nREPLAYGAIN_TRACK_GAIN="TRACKGAIN"nREPLAYGAIN_ALBUM_GAIN="ALBUMGAIN"n" >> GAIN_MISSING_FILE
        } else {
                #if(TRACKGAIN<LIMIT) print "SAMPLERATE="SAMPLERATE"nTRACKNUMBER="TRACKNUMBER"nALBUM="ALBUM"nARTIST="ARTIST"nTITLE="TITLE"nREPLAYGAIN_TRACK_GAIN="TRACKGAIN" dBnREPLAYGAIN_ALBUM_GAIN="ALBUMGAIN" dBn";
                if(TRACKGAIN<=LIMIT && TRACKGAIN>LOWERLIMIT) print "SAMPLERATE="SAMPLERATE"nTRACKNUMBER="TRACKNUMBER"nALBUM="ALBUM"nARTIST="ARTIST"nTITLE="TITLE"nREPLAYGAIN_TRACK_GAIN="TRACKGAIN" dBnREPLAYGAIN_ALBUM_GAIN="ALBUMGAIN" dBn";
        }
}
'
done
[ -s "$GAIN_MISSING_FILE" ] && echo "========= ReplayGain Data Missing =========" && cat $GAIN_MISSING_FILE
) 2>&1 | tee -a rgainX.log
rm -f $GAIN_MISSING_FILE 
and here is a snippet of the output:

SAMPLERATE=
TRACKNUMBER=8
ALBUM=Breakfast at Sweethearts
ARTIST=Cold Chisel
TITLE=Showtime
REPLAYGAIN_TRACK_GAIN=-8.27 dB
REPLAYGAIN_ALBUM_GAIN=-11.23 dB

SAMPLERATE=
TRACKNUMBER=9
ALBUM=The Soul of Rock and Roll
ARTIST=Roy Orbison
TITLE=Cat Called Domino
REPLAYGAIN_TRACK_GAIN=-8.06 dB
REPLAYGAIN_ALBUM_GAIN=-5.26 dB

You see the SAMPLERATE= is blank?? I was wondering if you can see anything in the bits that I added that might be wrong as to why it's not outputting the SAMPLERATE?? If I run "metaflac --show-sample-rate" on a directory it shows all of them, but in the script I can't seem to make it happen?? If I can get that to output like this:

SAMPLERATE=96000
TRACKNUMBER=1
ALBUM=The Piper at the Gates of Dawn
ARTIST=Pink Floyd
TITLE=Astronomy Domine
REPLAYGAIN_TRACK_GAIN=N/A<<<<<<<<<<Never Mind 8-) 8-)
REPLAYGAIN_ALBUM_GAIN=N/A<<<<<<<<<<Never Mind 8-) 8-)

or

SAMPLERATE=44100
TRACKNUMBER=1
ALBUM=Magnetic Skyline
ARTIST=Corinne West and Kelly Joe Phelps
TITLE=Whiskey Poet
REPLAYGAIN_TRACK_GAIN=N/A <<<<<<<<<<This needs checking ;) ;)
REPLAYGAIN_ALBUM_GAIN=N/A <<<<<<<<<<" " ;) ;)

then I can easily know that the REPLAYGAIN_TRACK_GAIN=N/A and REPLAYGAIN_ALBUM_GAIN=N/A is due to the fact that it is a "vinyl rip" and no more investigation is needed ;) I promise I won't bother you again after this Ragnar, but I have been trying different things for a few days on the code you have given me and I just can't get it to output the SAMPLERATE. Other than that "it's a beautiful thing" :D :D :D. I owe you some beers :!: :!: :!:

Thanks again Ragnar,

Cheers,

Singtoh

ragnar.jensen
Posts: 118
Joined: Thu Jan 26, 2012 7:39 pm
Operating System: Please select

Re: Any bash scripters can help me with a metaflac bash scri

Post by ragnar.jensen » Wed Dec 05, 2012 9:21 pm

I did a little test and it seems that SAMPLERATE is reported as a bare number, there's no tag name or equals sign.

Code: Select all

[email protected]:~/musik$ metaflac --show-sample-rate --show-tag=TRACKNUMBER --show-tag=ALBUM --show-tag=ARTIST --show-tag=TITLE --show-tag=REPLAYGAIN_TRACK_GAIN --show-tag=REPLAYGAIN_ALBUM_GAIN 01. Lykke Li - I Follow Rivers.flac 
44100
Tracknumber=01/20
Album=Sounds of Sweden
Artist=Sounds of Sweden
Title=Lykke Li / I Follow Rivers
REPLAYGAIN_TRACK_GAIN=-8.81 dB
REPLAYGAIN_ALBUM_GAIN=-9.20 dB
So, this line

Code: Select all

split($1, array, "="); SAMPLERATE=array[2]
has to be changed into this

Code: Select all

SAMPLERATE=$1
I've made another small change. I have moved LIMIT to the top of the script and it can now be overridden with an argument on the command line.
In the script that follows, the default LIMIT is -8, but a command line like this will change it to -10:

Code: Select all

name_of_script my_music_directory -10
And here's the complete latest version:

Code: Select all

#!/bin/bash
# This script assumes that your FLAC files have at least the ALBUM, ARTIST and TITLE tags.
# If any of them are missing in a file, that file will probably not be shown correctly, if at all.

LIMIT=-8  # Adjust LIMIT to taste. It can also be overridden on the commandline.
GAIN_MISSING_FILE=/tmp/no_rpg_data.$$   # Name of temp file where we store tracks that have no replaygain data.
#echo "You entered: '${*-}'"

(
if [ ! -d "$1" ]
then
   echo "Arg "$1" is NOT a directory!"
   exit $ARGUMENT_NOT_DIRECTORY
fi

[ ! -z "$2" ] && LIMIT=$2
flacnum=`ls "$1" | grep -c \.flac`

if [ $flacnum -lt 1 ]
then
   echo $1" (No FLAC files, moving on)"
   exit 0
else
   echo $1" ("$flacnum" FLAC files)"
fi

#echo "---------"
# Set bash's Internal Field Separator to newline only. It is important that there's nothing at all after the quote in the next line. Not even a space.
IFS='
'
for file in "$1"/*.flac 
do
        metaflac --show-sample-rate --show-tag=TRACKNUMBER --show-tag=ALBUM --show-tag=ARTIST --show-tag=TITLE --show-tag=REPLAYGAIN_TRACK_GAIN --show-tag=REPLAYGAIN_ALBUM_GAIN "$file" | awk 'BEGIN {
        LIMIT='$LIMIT';
        LOWERLIMIT=LIMIT - 1
        IGNORECASE=1
        RS = ""
        FS = "n"
        GAIN_MISSING_FILE="'${GAIN_MISSING_FILE}'"
}

{
        REPLAYGAIN_TRACK_GAIN=$6 ; REPLAYGAIN_ALBUM_GAIN=$7
        SAMPLERATE=$1
        split($2, array, "="); TRACKNUMBER=array[2]
        split($3, array, "="); ALBUM=array[2]
        split($4, array, "="); ARTIST=array[2]
        split($5, array, "="); TITLE=array[2]
        if(REPLAYGAIN_TRACK_GAIN>"") {
                split($6, array, "=")
                split(array[2], array2, " ")
                TRACKGAIN=array2[1]
        } else {
                TRACKGAIN="N/A"
        }

        if(REPLAYGAIN_ALBUM_GAIN>"") {
                split($7, array, "=")
                split(array[2], array2, " ")
                ALBUMGAIN=array2[1]
        } else {
                ALBUMGAIN="N/A"
        }

        if(TRACKGAIN=="N/A" || ALBUMGAIN=="N/A") {
                print "SAMPLERATE="SAMPLERATE"nTRACKNUMBER="TRACKNUMBER"nALBUM="ALBUM"nARTIST="ARTIST"nTITLE="TITLE"nREPLAYGAIN_TRACK_GAIN="TRACKGAIN"nREPLAYGAIN_ALBUM_GAIN="ALBUMGAIN"n" >> GAIN_MISSING_FILE
        } else {
                if(TRACKGAIN<=LIMIT && TRACKGAIN>LOWERLIMIT) print "SAMPLERATE="SAMPLERATE"nTRACKNUMBER="TRACKNUMBER"nALBUM="ALBUM"nARTIST="ARTIST"nTITLE="TITLE"nREPLAYGAIN_TRACK_GAIN="TRACKGAIN" dBnREPLAYGAIN_ALBUM_GAIN="ALBUMGAIN" dBn";
        }
}
'
done
[ -s "$GAIN_MISSING_FILE" ] && echo "========= ReplayGain Data Missing =========" && cat $GAIN_MISSING_FILE
) 2>&1 | tee -a rgainX.log
rm -f $GAIN_MISSING_FILE 
--
Ragnar

Singtoh
Posts: 84
Joined: Fri Nov 23, 2012 1:43 am
Operating System: Please select

Re: Any bash scripters can help me with a metaflac bash scri

Post by Singtoh » Thu Dec 06, 2012 4:56 am

Perfect Ragnar, absolutely perfect. You're super :D :D

Cheers, and Thanks Again, :D

Singtoh

Singtoh
Posts: 84
Joined: Fri Nov 23, 2012 1:43 am
Operating System: Please select

Re: Any bash scripters can help me with a metaflac bash scri

Post by Singtoh » Sun Dec 09, 2012 8:31 am

Hello Again Ragnar,

Just thought I would post the latest to the hatchet job on your code. This is working perfect, and only plots tracks that have REPLAYGAIN_TRACK_PEAK and REPLAYGAIN_ALBUM_PEAK with a value of 1.0000000 or above. I knew I was missing something by going with TRACK_GAIN and ALBUM_GAIN :oops: I had 1000's of lines of logs to look at. Now I just do all the A albums together B's together and so on thru the alphabet and it seems to pick the clipped tracks correctley in the %90 range :D It stands to reason that generally if the peaks are 1.00000 or above then you have clipping or the CD is a victim of the loudness wars. :x Fortunatley for me I don't have many of the latter :D Also using replaygain, that 1.00000 number isn't totally correct, it seems that replaygain caps it at 1.00000 and doesn't give the true peak. If I use r128gain, which gives the true peak, it shows around 1.4xxxxxx on both of the PEAK values. This result is ok for my purpose at the moment. This is what I get know as output:

EDIT: I have found a bit of an anomoly with REPLAYGAIN data! It seems to cap at 1.000000 on the ALBUM_PEAK and TRACK_PEAK and from my investigations if I look at those tracks with a 1.000000 I find clipping, some tracks heavily clipped! But, it seems REPLAYGAIN is a bit flaky, for lack of a better word. From what I have found is that REPLAYGAIN goes stupid at 0.99996948 and seems to lock there as well. Every track with 0.99996948 has clipping, some heavily! I have checked a couple hundred tracks that have a REPLAYGAIN_TRACK_PEAK of 0.99995xxx or below and not a single one has clipping. So, I set the [email protected] and the UPPERLIMIT=LIMIT= .999956000 and this is finding tracks with a single clip on them very nicely, and only logs those tracks that clip and nothing else. I don't know if anyone is interested in this or not, but thought I would post to clarify! I made it thru about 100 albums before I found this anomoly, went back and rechecked what I had already finished and was quite surprised at what I found! After I finish checking my library, I will REPLAYGAIN my library with "r128gain" instead of REPLAYGAIN (legacy edition). I think r128gain is more accurate!

Cheers, and I hope that this is clear enough for anyone who might be looking at this or is interested. I don't know of another way to find clipped tracks, does anyone else?? ;)

TRACKNUMBER=5
ALBUM=Living the Blues
ARTIST=Canned Heat
TITLE=Walking by Myself
SAMPLERATE=44100
REPLAYGAIN_TRACK_PEAK=0.99996948

TRACKNUMBER=8
ALBUM=Living the Blues
ARTIST=Canned Heat
TITLE=Parthenogenesis
SAMPLERATE=44100
REPLAYGAIN_TRACK_PEAK=0.99996948

TRACKNUMBER=9
ALBUM=Living the Blues
ARTIST=Canned Heat
TITLE=Refried Boogie
SAMPLERATE=44100
REPLAYGAIN_TRACK_PEAK=1.00000000


I'll post the script again just for giggles in case someone else is interested. It's a hackjob but it works :oops: :

Code: Select all

#!/bin/bash
    # This script assumes that your FLAC files have at least the ALBUM, ARTIST and TITLE tags.
    # If any of them are missing in a file, that file will probably not be shown correctly, if at all.

    LIMIT=.999956000  # Adjust LIMIT to taste. It can also be overridden on the commandline.
    GAIN_MISSING_FILE=/tmp/no_rpg_data.$$   # Name of temp file where we store tracks that have no replaygain data.
    #echo "You entered: '${*-}'"

    (
    if [ ! -d "$1" ]
    then
       echo "Arg "$1" is NOT a directory!"
       exit $ARGUMENT_NOT_DIRECTORY
    fi

    [ ! -z "$6" ] && LIMIT=$6
    flacnum=`ls "$1" | grep -c \.flac`

    if [ $flacnum -lt 1 ]
    then
       echo $1" (No FLAC files, moving on)"
       exit 0
    else
       echo $1" ("$flacnum" FLAC files)"
    fi

    #echo "---------"
    # Set bash's Internal Field Separator to newline only. It is important that there's nothing at all after the quote in the next line. Not even a space.
    IFS='
    '
    for file in "$1"/*.flac
    do
            metaflac --show-tag=TRACKNUMBER --show-tag=ALBUM --show-tag=ARTIST --show-tag=TITLE --show-sample-rate --show-tag=REPLAYGAIN_TRACK_PEAK --show-tag=REPLAYGAIN_ALBUM_PEAK "$file" | awk 'BEGIN {
            LIMIT='$LIMIT';
            UPPERLIMIT=LIMIT .999956000
            IGNORECASE=1
            RS = ""
            FS = "n"
            GAIN_MISSING_FILE="'${GAIN_MISSING_FILE}'"
    }

    {
            REPLAYGAIN_TRACK_PEAK=$6 ; REPLAYGAIN_ALBUM_PEAK=$7
            split($1, array, "="); TRACKNUMBER=array[2]
            split($2, array, "="); ALBUM=array[2]
            split($3, array, "="); ARTIST=array[2]
            split($4, array, "="); TITLE=array[2]
	    SAMPLERATE=$5
	            if(REPLAYGAIN_TRACK_PEAK>"") {
                    split($6, array, "=")
                    split(array[2], array2, " ")
                    TRACKPEAK=array2[1]
            } else {
                    TRACKPEAK="N/A"
            }

            if(REPLAYGAIN_ALBUM_PEAK>"") {
                    split($7, array, "=")
                    split(array[2], array2, " ")
                    ALBUMPEAK=array2[1]
            } else {
                    ALBUMPEAK="N/A"
	    }

            if(TRACKPEAK=="N/A" || ALBUMPEAK=="N/A") {
	                        print "TRACKNUMBER="TRACKNUMBER"nALBUM="ALBUM"nARTIST="ARTIST"nTITLE="TITLE"nSAMPLERATE="SAMPLERATE"nREPLAYGAIN_TRACK_PEAK="TRACKPEAK"nREPLAYGAIN_ALBUM_PEAK="ALBUMPEAK"n" >> GAIN_MISSING_FILE
            } else {
                    if(TRACKPEAK>=LIMIT && ALBUMPEAK>=UPPERLIMIT) {
					print "TRACKNUMBER="TRACKNUMBER"nALBUM="ALBUM"nARTIST="ARTIST"nTITLE="TITLE"nSAMPLERATE="SAMPLERATE"nREPLAYGAIN_TRACK_PEAK="TRACKPEAK"n";
		   }
            }
    }
    '
    done
    [ -s "$GAIN_MISSING_FILE" ] && echo "========= ReplayGain Data Missing =========" && cat $GAIN_MISSING_FILE
    ) 2>&1 | tee -a rgainMEDIAMUSICB.log
    rm -f $GAIN_MISSING_FILE
Thanks again for the help with this Ragnar :D

Cheers,

Singtoh

Post Reply