[Techtalk] Clueless Ripping Revisited--Hardware ?s

Conor Daly conor.daly at oceanfree.net
Mon Oct 21 23:56:40 EST 2002


On Sat, Oct 19, 2002 at 02:59:13PM +0100 or so it is rumoured hereabouts, 
Conor Daly thought:
> On Wed, Oct 16, 2002 at 07:06:07PM -0400 or so it is rumoured hereabouts, 
> Beth Johnson thought:
> > On Wed, 2002-10-16 at 16:55, Conor Daly wrote:
> > 
> > > Do ya want my mp3-catalogue[0] script?  It searches out and catalogues mp3
> > > files in and below the current directory and makes index files that xmms
> > > can use.
> 
> Beth,
> 
> Here ya go.  If you name your mp3 directories in the form <band>/<cd
> name>, you end up with a nice useful index for xmms to use.
> 
> Enjoy ripping!..
> 
> Conor

Oops!  Did I forget the script?  Here it is...

Conor
-- 
Conor Daly <conor.daly at oceanfree.net>

Domestic Sysadmin :-)
---------------------
Faenor.cod.ie
 12:06am  up 52 days,  4:33,  0 users,  load average: 0.00, 0.00, 0.00
Hobbiton.cod.ie
 11:55pm  up 52 days,  4:04,  3 users,  load average: 0.28, 0.27, 0.27
-------------- next part --------------
#!/bin/bash

#########################################################################
#
# mp3-catalogue
#
# Name:		mp3-catalogue
# Version:	0.1
# Date:		22-Dec-2001
# Author:	Conor Daly <conor.daly at oceanfree.net>
# License:	GPL <http://www.copyleft.org>
#
# Purpose:	Catalogue all mp3 files found below the current directory
#		Generates an index file of the form <dirname>.m3u which
#		is readable by the likes of xmms and others.
#		If you run this from the root of your machine's filesystem
#		You'll end up with an index file in _every_ directory that
#		has mp3 files in *or below* it.
#
# Bugs:		It's recursive.  If your directory structure is deep 
#		enough, it'll break
#
#########################################################################

# Throw away errors
exec 2>/dev/null

# See where we start from probably so we can get back here when we're done
THIS_DIR=`pwd`

# Check for commandline args
if [ ! $1 ]; then

  # If we didn't get any, we set standard values
  BASE_DIR="."
  FNAME=`basename $THIS_DIR`
  INDENT=1
  echo "Processing "$THIS_DIR" ..."
else

  # Read the commandline args
  BASE_DIR=$1
  FNAME=`basename $BASE_DIR`
  INDENT=`echo $(($2 + 1))`
fi

# set the number of lines to use in the index.  This is for looks
LINES="-"
for j in `seq 1 $INDENT`;do
  LINES=$LINES"-"
done
END_LINES=$LINES

# Tell the user what we're doing...
echo "Entering directory       <"$FNAME">..."
echo "Generating mp3 catalogue <"$FNAME".m3u>..."

# Insert the directory name into the current index file
echo $LINES"_"$FNAME"_"$END_LINES > $BASE_DIR/$FNAME.m3u

# Figure out how big the index file is now.  We'll use this later
# to see if there were any entries made in it.
FIL=`ls -l $BASE_DIR/$FNAME.m3u`
HEAD_SIZ=`echo $FIL | cut -f5 -d" "`
#echo "FIL: "$FIL" SIZ: "$SIZ" HEAD_SIZ: "$HEAD_SIZ

# Start a loop over the contents of the current directory
for i in `/bin/ls $BASE_DIR`; do

  # If this entry is itself a directory
  if [ -d $BASE_DIR/$i ]; then
    DIR=$BASE_DIR/$i

    # Do the recursive bit.  Call ourself with the new directory as arg
    $0 $DIR $INDENT
    THIS_STATUS=$?

    # When we return, we need to process the index just made
    # to incorporate it into _this_ directory's index
    #
    # We could have used the exit status from the call to $0
    # to make this decision but I'm not sure if we generate an exit status
    # in any case!
   
#    if [ -f $DIR/`basename $DIR`.m3u ]; then
    if [ $THIS_STATUS -eq 0 ]; then
      
      # We have an index from the last go so let's read it
      exec < $DIR/`basename $DIR`.m3u
      read MP
      #echo $MP

      # and set the exit status for this iteration
      STATUS=0

      # Loop over the entries in the index
      while [ $MP ]; do

	# See if the entry is an actual file or a directory divider
        X=`echo $MP | cut -b 1-2`
        if [ $X = "./" ]; then
          MP=`echo $MP | cut -b 3-`
        fi

	# and add it to the current index
        if [ $X = "--" ]; then
          echo $MP >> $BASE_DIR/$FNAME.m3u
        else
          echo "./"`basename $DIR`/$MP >> $BASE_DIR/$FNAME.m3u
        fi
        read MP
      done 	# End scan index loop
    fi
  fi
done	# End current dir loop

# Now find all of the mp3 files in the _current_ dir, sort them and stuff them 
# onto the end of the current dir's index

find $BASE_DIR/ -name '*.mp3' -maxdepth 1 -exec basename {} \; | sort >> $BASE_DIR/$FNAME.m3u

#pwd
#echo "find "$BASE_DIR" -name '*.mp3' -maxdepth 1"
#find $BASE_DIR/ -name '*.mp3' -maxdepth 1

# Figure out how big the index file is now
FIL=`ls -l $BASE_DIR/$FNAME.m3u`
SIZ=`echo $FIL | cut -f5 -d" "`
#echo "FIL: "$FIL" SIZ: "$SIZ" HEAD_SIZ: "$HEAD_SIZ

# See if it got any entries
if [ $SIZ -eq $HEAD_SIZ ]; then

  # if not, dump it
  rm -f $BASE_DIR/$FNAME.m3u

  # Set a "nothing found" exit status
  STATUS=-1

  # and tell the user
  echo "***Nothing to catalogue for directory <"$FNAME"> !***" 
#  echo "***Nothing to catalogue for directory <"$FNAME"> !***" >&2
fi

# Tell the user we're done
echo "Leaving directory        <"$FNAME">..."

exit $STATUS


More information about the Techtalk mailing list