Any bash scripters can help me with a metaflac bash script

Hello All,

First of all I am not a coder by any stretch of the imagination. I got a script off the internet and adapted it to my needs or the best that I could do, but it’s not quite there yet and I am pulling my hair out trying to get it to do what I would like :angry: . Please be gentle ok :smiley:

I have this script that scans thru my entire music library. It gathers replaygain tag data and only logs to a text file any replaygain values lower than a number that I give it. So I tell it I want only anything lower than -4dB replaygain_track_gain to be sent to a log and it does just that but I can’t seem to get it to log anything other than replaygain_track_gain?? So my goal is to start low, say around -10dB on the replaygain value and look thru those flacs for clipping and fix them. Then go to -9dB and so on. What I have found is that almost all of the flacs I have with a replaygain value of -10dB or more have some clipping on them, and the higher I go towards 0dB acorrding to replaygain data the clipping drops off accordingly, and it seems that usually anything above -5dB(going towards 0dB) is normally a clean track or album(usually). Like I said, the script works as it should but just isn’t giving me all the info I need, which is ARTIST, TITLE, REPLAYGAIN_TRACK_GAIN, REPLAYGAIN_ALBUM_GAIN. Here is an example of what I would like to see:

The script that produced this snippet works well, but it doesn’t sort the replaygain values. I don’t need the ones that are say, above -4dB(going towards 0dB) because chances are they aren’t clipped.

Tag Values Retrieved:
artist=Fleetwood Mac
title=Second Hand News
REPLAYGAIN_TRACK_GAIN=-8.88 dB
REPLAYGAIN_ALBUM_GAIN=-7.71 dB
artist=Fleetwood Mac
title=Dreams
REPLAYGAIN_TRACK_GAIN=-6.65 dB
REPLAYGAIN_ALBUM_GAIN=-7.71 dB
artist=Fleetwood Mac
title=Never Going Back Again
REPLAYGAIN_TRACK_GAIN=-3.49 dB
REPLAYGAIN_ALBUM_GAIN=-7.71 dB

And this snippet is the same script with the awk sorting command inserted into the script which sorts the replaygain values nicely but doesn’t give me the info as above nice and proper in it’s place.

/media/Storage/Music/Rock/Coldplay - Discography Lite/2002-08-26 - A Rush of Blood to the Head - Parlophone 540 5042 GB (11 FLAC files)
Tag Values Retrieved:
REPLAYGAIN_TRACK_GAIN=-8.52 dB
REPLAYGAIN_TRACK_GAIN=-8.67 dB
REPLAYGAIN_TRACK_GAIN=-9.28 dB
REPLAYGAIN_TRACK_GAIN=-8.72 dB
REPLAYGAIN_TRACK_GAIN=-8.85 dB
REPLAYGAIN_TRACK_GAIN=-9.00 dB
REPLAYGAIN_TRACK_GAIN=-9.58 dB
REPLAYGAIN_TRACK_GAIN=-8.31 dB
REPLAYGAIN_TRACK_GAIN=-8.98 dB
/media/Storage/Music/Rock/Coldplay - Discography Lite/2011-10-21 - Mylo Xyloto - Parlophone 087 5532 DE (14 FLAC files)
Tag Values Retrieved:
REPLAYGAIN_TRACK_GAIN=-9.34 dB
REPLAYGAIN_TRACK_GAIN=-9.46 dB
REPLAYGAIN_TRACK_GAIN=-9.54 dB
REPLAYGAIN_TRACK_GAIN=-8.83 dB
REPLAYGAIN_TRACK_GAIN=-9.63 dB
REPLAYGAIN_TRACK_GAIN=-8.68 dB
REPLAYGAIN_TRACK_GAIN=-8.82 dB
/media/Storage/Music/Rock/Coldplay - Discography Lite/2005-06-06 - X&Y - (no release info) AU (13 FLAC files)
Tag Values Retrieved:
REPLAYGAIN_TRACK_GAIN=-8.67 dB
REPLAYGAIN_TRACK_GAIN=-9.09 dB
REPLAYGAIN_TRACK_GAIN=-8.94 dB
REPLAYGAIN_TRACK_GAIN=-9.63 dB
REPLAYGAIN_TRACK_GAIN=-8.11 dB
REPLAYGAIN_TRACK_GAIN=-9.40 dB
REPLAYGAIN_TRACK_GAIN=-8.85 dB
REPLAYGAIN_TRACK_GAIN=-8.98 dB
REPLAYGAIN_TRACK_GAIN=-8.87 dB
REPLAYGAIN_TRACK_GAIN=-8.89 dB
REPLAYGAIN_TRACK_GAIN=-8.62 dB
REPLAYGAIN_TRACK_GAIN=-9.66 dB

And here is the script

#!/bin/bash -u
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:"
flacfiles=`ls -1 "$1"/*.flac`
IFS=$'\012'
for file in $flacfiles
do 	metaflac --show-tag=ALBUM --show-tag=TITLE --show-tag=REPLAYGAIN_TRACK_GAIN --show-tag=REPLAYGAIN_ALBUM_GAIN "$file" | awk 'BEGIN {FS="[ =]"}; $(NF-1)[b]<-8[/b] { print }'
#The number above in bold is adjusted to log only tracks that go below, in this case, -8dB.

done) 2>&1 | tee -a rgainvaluesMUSIC.log

I use this script to call the above scritp:

#!/bin/bash

#This script calls metadata1.sh in my home directory to search recursively thru the music #library for replaygain values lower than any number I give it i.e.-4dB, -5dB -8dB ect.ect.


# Define error codes
ARGUMENT_NOT_DIRECTORY=10
FILE_NOT_FOUND=11

# Check that the argument passed to this script is a directory.
# If it's not, then exit with an error code.
if [ ! -d "$1" ]
then
	echo "Arg "$1" is NOT a directory!"
	exit $ARGUMENT_NOT_DIRECTORY
fi

echo "********************************************************"
echo "Calling metadata1.sh on each directory in:"
echo $1
echo ""
find "$1" -type d -exec ~/metadata1.sh '{}' ;

I am sure the problem lies in the awk command of the script. Some descriptor not allowing it to print out what I would like but for the life of me I can’t figure it out and get it to do what I want. :angry:

So that’s it, I guess. I would like to thank you for any help in advance that you could be so kind to pass along to an older fellow whose brain isn’t what it used to be. :smiley:

Cheers,

Singtoh

Yup, there’s far too little awk in that script, so I’ve added some more. :wink:

#!/bin/bash
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:"
flacfiles=`ls -1 "$1"/*.flac`
IFS='
'
for file in $flacfiles
do    metaflac --show-tag=ALBUM --show-tag=TITLE --show-tag=REPLAYGAIN_TRACK_GAIN --show-tag=REPLAYGAIN_ALBUM_GAIN "$file"  | awk 'BEGIN {
        FS="=";
        LIMIT=-8; # Adjust LIMIT to taste.
}

/Album/ { ALBUM=$2 }
/Title/ { TITLE=$2 }
/REPLAYGAIN_TRACK_GAIN/ {
        split($2, array, " ");
        TRACKGAIN=array[1];
}
/REPLAYGAIN_ALBUM_GAIN/ {
        split($2, array, " ");
        ALBUMGAIN=array[1];
        if(TRACKGAIN < LIMIT) {
                # Pick your style of print-out, either each tag on a separate line...
                # print "Album="ALBUM"nTitle="TITLE"nREPLAYGAIN_TRACK_GAIN="TRACKGAIN" dBnREPLAYGAIN_ALBUM_GAIN="ALBUMGAIN" dBn";

                # ...or all tags on one line, verbose.
                # print "Album="ALBUM" Title="TITLE" REPLAYGAIN_TRACK_GAIN="TRACKGAIN" REPLAYGAIN_ALBUM_GAIN="ALBUMGAIN;

                # Ditto, but terse. Tag values separated by pipe signs.
                # print ALBUM" | "TITLE" | "TRACKGAIN" | "ALBUMGAIN;

                # Ditto, even terser. Only Title and track gain.
                print TITLE" | "TRACKGAIN;

        }
}
'
done)  2>&1 | tee -a rgainvaluesMUSIC.log

The LIMIT variable is where you decide which tracks to show. Only tracks with REPLAYGAIN_TRACK_GAIN less than LIMIT are shown.

The script can produce four different styles of print-out, just comment out/uncomment the appropriate “print” statement.
Each tag on a separate line:

Album=Sounds of Sweden
Title=Lykke Li / I Follow Rivers
REPLAYGAIN_TRACK_GAIN=-8.81 dB
REPLAYGAIN_ALBUM_GAIN=-8.43 dB

Album=Sounds of Sweden
Title=Niki & The Dove / Mother Project
REPLAYGAIN_TRACK_GAIN=-8.14 dB
REPLAYGAIN_ALBUM_GAIN=-8.43 dB

Album=Sounds of Sweden
Title=Swedish House Mafia / Miami 2 Ibiza
REPLAYGAIN_TRACK_GAIN=-8.24 dB
REPLAYGAIN_ALBUM_GAIN=-8.43 dB

Album=Sounds of Sweden
Title=Pacific! / Narcissus
REPLAYGAIN_TRACK_GAIN=-8.90 dB
REPLAYGAIN_ALBUM_GAIN=-8.43 dB

One track per line, verbose:

Album=Sounds of Sweden Title=Lykke Li / I Follow Rivers REPLAYGAIN_TRACK_GAIN=-8.81 REPLAYGAIN_ALBUM_GAIN=-8.43
Album=Sounds of Sweden Title=Niki & The Dove / Mother Project REPLAYGAIN_TRACK_GAIN=-8.14 REPLAYGAIN_ALBUM_GAIN=-8.43
Album=Sounds of Sweden Title=Swedish House Mafia / Miami 2 Ibiza REPLAYGAIN_TRACK_GAIN=-8.24 REPLAYGAIN_ALBUM_GAIN=-8.43
Album=Sounds of Sweden Title=Pacific! / Narcissus REPLAYGAIN_TRACK_GAIN=-8.90 REPLAYGAIN_ALBUM_GAIN=-8.43

Terse, one track per line:

Sounds of Sweden | Lykke Li / I Follow Rivers | -8.81 | -8.43
Sounds of Sweden | Niki & The Dove / Mother Project | -8.14 | -8.43
Sounds of Sweden | Swedish House Mafia / Miami 2 Ibiza | -8.24 | -8.43
Sounds of Sweden | Pacific! / Narcissus | -8.90 | -8.43

Even terser, only title and track gain:

Lykke Li / I Follow Rivers | -8.81
Niki & The Dove / Mother Project | -8.14
Swedish House Mafia / Miami 2 Ibiza | -8.24
Pacific! / Narcissus | -8.90

I’m sure there are lots of refinements to be made (like passing LIMIT as an argument on the command line, and it’s utterly devoid of error checking), but those are left as exercises for the reader. :laughing:

Ragnar

Hello Ragnar,

Wow! thanks for the reply and the beautiful clear explanation, and of course the updated code :smiley: I’ll give this a try now as soon as I get my head around it a little bit :slight_smile: and post back with the results.

Thanks again Ragnar, I really appreciate your kind help :smiley:

Cheers,

Singtoh

Hello again Ragnar,

Wow! You guys/Girls that do this code are something special, I really don’t know how you do it, I can hardly remember my name anymore :laughing: Any way here is a snippet of what the script is outputting now, with you refined code and an added tweak on my part to log the artist as well:

album=No Line on the Horizon
artist=U2
title=Magnificent
REPLAYGAIN_TRACK_GAIN=-8.09 dB
REPLAYGAIN_ALBUM_GAIN=-8.18 dB

album=No Line on the Horizon
artist=U2
title=Moment of Surrender
REPLAYGAIN_TRACK_GAIN=-7.55 dB
REPLAYGAIN_ALBUM_GAIN=-8.18 dB

album=No Line on the Horizon
artist=U2
title=Unknown Caller
REPLAYGAIN_TRACK_GAIN=-8.38 dB
REPLAYGAIN_ALBUM_GAIN=-8.18 dB

There is some kind of capitilization thing that doesn’t let it log something in CAPS?? As you can see album,artist, and title aren’t CAPS. Please don’t misunderstand, it is just super the way it is, I am not complaining, I don’t care if its CAPS or not just so long as I have the info :smiley: There is one other thing I would like to ask you if it could be done?? Here is a snippet of something else I am getting with the output:

/media/Storage/Music/Rock/Don Mclean - Various Albums/1995 - Back to Back Hits - CEMA Special Markets (10 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Don Mclean - Various Albums/1971-10 - American Pie - United Artists UAS-5535 US (10 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Journey - The Essential Journey - Columbia C2K 86080 US (32 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/The Decemberists - The King Is Dead - Rough Trade Germany DE (10 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Pat Benatar - Various Albums/1993 - Gravity’s Rainbow - Chrysalis 0946 3 21982 8 XE (12 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Pat Benatar - Various Albums/2005 - Greatest Hits - Capitol Records 72435-78858-2-9 US (20 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Bruce Hornsby & The Range - Discography Lite/1988 - Scenes From the Southside - RCA Records PD86686 DE (9 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Bruce Hornsby & The Range - Discography Lite/1990-06-19 - A Night on the Town - BMG Music 2041-2-R US (11 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Bruce Hornsby & The Range - Discography Lite/1986 - The Way It Is - RCA Records PCD1-5904 US (9 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Carole King - The Collection/1971 - Music - Sony Music 484462 2 US (13 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Carole King - The Collection/1999 - Tapestry - Epic EPC 493180 2 XE (15 FLAC files)
Tag Values Retrieved:

I don’t really know the issue with these, I know that some of them do not have replaygain tags due to the fact that they are vinyl rips 24/96 and the replaygain program isn’t able to tag them. My whole library has ben ran thru the replaygain program and tags applied where possible. But I have been looking at many of these tags and most of them that are logging above as “Tag Values Retrieved:” do have replaygain tags and it’t not showing in the log. I will have to investigate this further, but know to my question. Would it be possible somehow to tell the script that if no replaygain tags are found or if it’s not able to print album,artist,title,REPLAYGAIN_TRACK_GAIN,REPLAYGAIN_ALBUM_GAIN to the log, that it could put all of these “errors” so to speak at the end of the log all together so they don’t pollute the rest of the log?? There is about 3000 lines or more like this for some reason?? And at the risk of being greedy :blush: and asking you for too much would it be possible to make it output in alphabetical order??? I’m sorry if this is asking too much, and if it’s too great a problem to implement please tell me to go jump off a bridge or something. :unamused: You have helped me greatly already :smiley: If you were here I’d buy you a boatload of beers :smiley: Thank you again for your patience, help and that wonderful bit of fine code you so graciously gave freely :sunglasses:

Cheers,

Singtoh

Well, the tag names come from the print statement:
print "Album="ALBUM"nArtist="ARTIST"nTitle=“TITLE"nREPLAYGAIN_TRACK_GAIN=“TRACKGAIN” dBnREPLAYGAIN_ALBUM_GAIN=“ALBUMGAIN” dBn”
so they’re easy to change:
print "ALBUM="ALBUM"nARTIST="ARTIST"nTITLE=“TITLE"nREPLAYGAIN_TRACK_GAIN=“TRACKGAIN” dBnREPLAYGAIN_ALBUM_GAIN=“ALBUMGAIN” dBn”

That will happen if any of the tags the script assumes are present, are in fact missing.

Do you know that you can add replaygain tags with metaflac? The simple command metaflac --add-replay-gain *.flac will compute REPLAYGAIN_TRACK_GAIN for each track and since we use the asterisk wildcard for file names metaflac will treat the entire directory as an album and add REPLAYGAIN_ALBUM_GAIN to all tracks.
The –set-tag option is handy to set any tag, e.g. metaflac --set-tag=“ARTIST=The Beatles” LoveMeDo.flac
man metaflac” is your friend.

The following script detects missing REPLAYGAIN_TRACK_GAIN and REPLAYGAIN_ALBUM_GAIN tags and puts those tracks at the end of the log.
There will be a “========= ReplayGain Data Missing =========” separator in the log.
But the ALBUM, ARTIST and TITLE tags must still be present.



#!/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:"
flacfiles=`ls -1 "$1"/*.flac`
IFS='
'
for file in $flacfiles
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.
        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";
        }
}
END { close (GAIN_MISSING_FILE) }
'
done
[ -f "$GAIN_MISSING_FILE" ] && echo "========= ReplayGain Data Missing =========" && cat $GAIN_MISSING_FILE                                                                                                 
)  2>&1 | tee -a rgainvaluesMUSIC.log                                                                                                                                                                       
rm -f $GAIN_MISSING_FILE



Go jump off a bridge or something! :wink:
Alphabetical on what? Track title? Artist? Or a combination of several tags? We’ll see if I can find some time to tinker …

\

Ragnar

Hello Ragnar,

Ok, heading to my local bridge after this post :laughing: ,just kidding :smiley: . Thanks again for the help and the new code. The new code/script doesn’t seem to work at the moment. I need to look at it and make sure I’m not doing something stupid, with my fingers before i post any results from that. :wink: Saturday morning and a bit foggy in the head :slight_smile: Yeah, that alphabetical request was about making the Artists all come out in alphabetical order, please disregard that one, that’s not a big deal at all. But here is what I have been trying to do with the previous script you were so gracious to help me with. I wasn’t really thinking ahead when I requested that the script search for and log anything below say as an example -10db. What I should have said was, equal to 10db, because as I am finding out, when I start at the lowest number say for example -10db, it finds and logs all those just nicely. But when i get down to say -7db it finds those just nicely as well, but it of course also finds and logs the rest i.e -8db,-9db,-10db ect.ect. which gets to be kind of a mess when I get down into the -4db range. So, I think in order for it to do just equal to eg. -10db so it only logs those, the REPLAYGAIN_TRACK_GAIN and REPLAYGAIN_ALBUM_GAIN would have to be rounded to the nearest integer would’nt they??? This would make it a bit easier to search thru I think. Anyway, not being a coder I just read a bit then try different things kinda trial and error :blush: This is what I added to the script

print "ALBUM="album"nARTIST="artist"nTITLE="title"nREPLAYGAIN_TRACK_GAIN="TRACKGAIN" dBnREPLAYGAIN_ALBUM_GAIN="ALBUMGAIN" dBn"; [color=#FF0000]split($2,a,".");PREC=length(a[n])0;printf"%0."PREC"fn",$2

[/color]
and the output of that is:

ALBUM=How to Dismantle an Atomic Bomb
ARTIST=U2
TITLE=Love and Peace or Else
REPLAYGAIN_TRACK_GAIN=-10.68 dB
REPLAYGAIN_ALBUM_GAIN=-10.68 dB

-11
ALBUM=How to Dismantle an Atomic Bomb
ARTIST=U2
TITLE=City of Blinding Lights
REPLAYGAIN_TRACK_GAIN=-10.06 dB
REPLAYGAIN_ALBUM_GAIN=-10.06 dB

-10
ALBUM=How to Dismantle an Atomic Bomb
ARTIST=U2
TITLE=All Because of You
REPLAYGAIN_TRACK_GAIN=-11.48 dB
REPLAYGAIN_ALBUM_GAIN=-11.48 dB

-11

So it kinda works as far as rounding goes but obviously the rounding bit isn’t integrated with the REPLAYGAIN_TRACK_GAIN and REPLAYGAIN_ALBUM_GAIN bits because the rounded number is on the line below whereas what the rounded bits should read: REPLAYGAIN_TRACK_GAIN=-11 dB and REPLAYGAIN_ALBUM_GAIN=-11 dB :unamused:

So in this case:

ALBUM=The Miracle
ARTIST=Queen
TITLE=Was It All Worth It
REPLAYGAIN_TRACK_GAIN=-10.14 dB
REPLAYGAIN_ALBUM_GAIN=-9.39 dB

I guess the rounded result would be:

ALBUM=The Miracle
ARTIST=Queen
TITLE=Was It All Worth It
REPLAYGAIN_TRACK_GAIN=-10 dB
REPLAYGAIN_ALBUM_GAIN=-9 dB

Then there is the equal to part of the code which I haven’t yet fumbled with :blush: , and ideally after that is in place, when I tell the script to do a (=to) -10 it would output only those ALBUM,ARTIST,TITLE,REPLAYGAIN_TRACK_GAIN=-10 dB,REPLAYGAIN_ALBUM_GAIN=-10dB that are equal to -10db as in the format below:

ALBUM=Innuendo
ARTIST=Queen
TITLE=Innuendo
REPLAYGAIN_TRACK_GAIN=-10 dB
REPLAYGAIN_ALBUM_GAIN=-10 dB

ALBUM=Innuendo
ARTIST=Queen
TITLE=I Can’t Live With You
REPLAYGAIN_TRACK_GAIN=-10 dB
REPLAYGAIN_ALBUM_GAIN=-10 dB

ALBUM=Innuendo
ARTIST=Queen
TITLE=The Hitman
REPLAYGAIN_TRACK_GAIN=-10 dB
REPLAYGAIN_ALBUM_GAIN=-10 dB

That would make things nice and tidy so I could just have a bunch of files eg. rgainvalue-10db.log, rgainvalue-9db.log ect. ect. instead of it being all together in one file :wink:

Ok, coffee is in the system, a little bit less hungover now, so I will give the new script a go now and see how I get on :wink:

Thanks again Ragnar for all the help, your a super trooper :smiley:

Cheers,

Singtoh

Hello again Ragnar,

I just tried this new script and it doesn’t seem to want to run correctly?? Here is the output from the new script

The FLAC file could not be opened. Most likely the file does not exist
or is not readable.
Smith: 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.
-: 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.
Dream: 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.
of: 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.
Life: ERROR: reading metadata, status = “FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE”

and it goes like this all the way thru to the end. :confused: The original script runs on thru with no worries though.

Thanks again Ragnar,

Cheers,

Singtoh

I think that what we have are file names with spaces and/or dashes in them and you and I have different versions of the “ls” command.

Try this: Find these four lines

flacfiles=`ls -1 "$1"/*.flac`
IFS='
'
for file in $flacfiles

Remove the first three lines and change the last one into

for file in "$1"/*.flac


Ragnar

Hello Ragnar,

Yeah, you nailed it with that. it works as it is supposed to. Here is some snippets of some of the output:


========= ReplayGain Data Missing =========
ALBUM=Tango in the Night
ARTIST=Fleetwood Mac
TITLE=Big Love
REPLAYGAIN_TRACK_GAIN=N/A
REPLAYGAIN_ALBUM_GAIN=N/A

ALBUM=Tango in the Night
ARTIST=Fleetwood Mac
TITLE=Seven Wonders
REPLAYGAIN_TRACK_GAIN=N/A
REPLAYGAIN_ALBUM_GAIN=N/A

ALBUM=Tango in the Night
ARTIST=Fleetwood Mac
TITLE=Everywhere
REPLAYGAIN_TRACK_GAIN=N/A
REPLAYGAIN_ALBUM_GAIN=N/A

The above is due to the fact that this album is a vinyl rip 24/96, perfect. :smiley: There are a few albums that I forgot to replaygain and this points that out nicely, perfect again. :smiley:


Next:

Tag Values Retrieved:
ALBUM=Say You Will
ARTIST=Fleetwood Mac
TITLE=What’s the World Coming To
REPLAYGAIN_TRACK_GAIN=-10.42 dB
REPLAYGAIN_ALBUM_GAIN=-10.42 dB

ALBUM=Say You Will
ARTIST=Fleetwood Mac
TITLE=Murrow Turning Over in His Grave
REPLAYGAIN_TRACK_GAIN=-11.48 dB
REPLAYGAIN_ALBUM_GAIN=-11.48 dB

ALBUM=Say You Will
ARTIST=Fleetwood Mac
TITLE=Illume (9-11)
REPLAYGAIN_TRACK_GAIN=-8.95 dB
REPLAYGAIN_ALBUM_GAIN=-8.95 dB

The above is because this album went below the input variable of -6dB, perfect. :smiley:

Next:

/media/Storage/Music/Rock/Fleetwood Mac - Discography Lite/1987 - Kiln House - Reprise Records 7599-27453-2 US (10 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Fleetwood Mac - Discography Lite/1990 - Penguin - Reprise Records 7599-26178-2 XE (9 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Fleetwood Mac - Discography Lite/1987 - Future Games - Reprise Records 6465-2 US (8 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Fleetwood Mac - Discography Lite/1973-10-15 - Mystery to Me - (no release info) GB (12 FLAC files)
Tag Values Retrieved:
/media/Storage/Music/Rock/Fleetwood Mac - Discography Lite/1987 - Tango in the Night - Warner Bros. Records WX65 GB (12 FLAC files)

The above threw me off a bit because I thought there was something wrong with the script or my flac files, but what this is, is simply that these albums didn’t go below the -6dB threshold and it just threw this onto the log. This is what I was talking about yesterday but I didn’t clue in that this “cruft” was due to not breaking the -XdB threshold, it throws the above onto the log because either it didn’ break the -XdB threshold or because it is a vinyl rip and there is no replaygain tag or because a few tracks from that album went below the -XdB threshold. For instance if I put the the -X threshold to -20dB the log would be full of what what is printed above because nothing in the library is replaygained to -20dB or below. 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) :blush: ?? Just curious?? 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, but I better quit while I am ahead :smiley: Afterall, you already told me to go jump off a bridge once today :smiley: It’s perfect enough for this “Old Gasbag” anyway :smiley: Thank you so much for your patience and help with this coding stuff Ragnar, I would never have been able to acomplish this on my own :sunglasses:

Time for a beer,

Cheers and thanks again,

Singtoh :smiley: :smiley: :smiley:

/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…

[ -f "$GAIN_MISSING_FILE" ] && echo "========= ReplayGain Data Missing =========" && cat $GAIN_MISSING_FILE

…and finally the temp file is removed.

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.

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”.

OK, will do. :smiley:


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: :slight_smile: 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. :smiley: Yes, between -10dB and -10.99dB rounded/truncated so the awk knows only to log what the -/+X value is that would be super :smiley: +/- one dB is not going to affect what I am trying to accomplish :wink: if it’s not too much trouble that is, I don’t mean to put you out, you have been wonderful :smiley: 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. :confused: . 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 :confused: Maybe the code in my original script is out of whack a bit?? :blush: I have been trying different things but can’t seem to make it go away?? :frowning: Thanks Ragnar, again, I can’t thank you enough :smiley:

Ok, more beer :smiley: :smiley: :smiley: :smiley: :smiley:

Cheers,

Singtoh

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

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

#!/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 :smiley: ).
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

Hello Ragnar,

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

#!/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 :sunglasses: :sunglasses:
REPLAYGAIN_ALBUM_GAIN=N/A<<<<<<<<<<Never Mind :sunglasses: :sunglasses:

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 :wink: :wink:
REPLAYGAIN_ALBUM_GAIN=N/A <<<<<<<<<<" " :wink: :wink:

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 :wink: 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” :smiley: :smiley: :smiley:. I owe you some beers :exclamation: :exclamation: :exclamation:

Thanks again Ragnar,

Cheers,

Singtoh

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

ragnar@bakis:~/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

split($1, array, "="); SAMPLERATE=array[2]

has to be changed into this

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:

name_of_script my_music_directory -10

And here’s the complete latest version:

#!/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

Perfect Ragnar, absolutely perfect. You’re super :smiley: :smiley:

Cheers, and Thanks Again, :smiley:

Singtoh

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 :blush: 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 :smiley: 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. :angry: Fortunatley for me I don’t have many of the latter :smiley: 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 LIMIT=@.999956000 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?? :wink:

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 :blush: :

#!/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 :smiley:

Cheers,

Singtoh