It is currently Wed May 25, 2016 9:00 am

very odd loop-behavior...

All times are UTC - 6 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Thu Sep 24, 2009 5:53 am   

Joined: Thu Sep 24, 2009 5:08 am
Posts: 1
Location: Berlin
Hello everybody!

I just started Bash-scripting because I'm too lazy to the following by hand:

My music-collection contains several hundreds of CDs - already named & sorted correctly...BUT some of them are *.wma and I want them in * I thought about scripting...after some work (and with some Google-study ^^) I figured out a script doing what I want: renaming the file without uppercases & spaces, converting (Mplayer + LAME) and renaiming it again to the originial name but with *.mp3-ending instead of *.wma...I even found kinda workaround for smaller problems like mv-errors if the file was already small and without spaces or if there wasn't any *.wma at I want to enhance functionality by running through subdirectories as well...Google often presented me solutions using find -type d and the exec-command to run my working script on every subdirectory, but to be honest: now I'm too aspiring to just give up!
I wrote the following:
sdir=$PWD                                             # storing start-directory,
find ./ -type d |                                     # identifying all subdirectories     
while read cdir                                       # and parsing them
do                                                    # by
cd "$sdir${cdir:1}"                                   # entering them (from startdirectory),
for wma in *.[Ww][Mm][Aa                              # extracting wmas
do                                                    # after
  if [ "$wma" != "*.[Ww][Mm][Aa]" ]                   # checking for their existance
  then                                                # and
   basename=`basename "$wma" .wma`                    # storing the orig. name without ending,
   workname=`echo $wma | tr '[A-Z]' '[a-z]' | tr ' ' '_'` # removing uppercases & spaces
   if [ "$workname" != "$wma" ]                       # to check wether
   then                                               # or not
    mv "$wma" "$workname"                             # to set a workname
   fi                                                 # before
#   echo "converting $workname ..."
   mplayer -vo null -vc dummy -af resamp  le=44100 -ao pcm:waveheader $workname && lame -m s audiodump.wav $workname                               # ripping with Mplayer & encoding with LAME,
   mv "$workname" "$basename.mp3"                     # restoring the orig name with mp3-ending
  fi                                                  # and
done                                                  # after
if [ -e audiodump.wav ]                               # checking for its existance
  rm audiodump.wav                                    # removing the therefore used wav-file

I'm testing on one folder ~/test(2) with subdirs ~/test/Artist A(0) ~/test/Artist B(2) ~/test/Artist A/Disc 1(>10) ~/test/Artist A/Disc 2(4) ~/test/Artist B/Disc 1(5) ~/test/Artist B/Disc 2(10) and ~/test/Artist B/Disc 3(>10). (number of *.wma-files)
If I'm using the echo "converting $workname ..." instead of "mplayer - vo ..." it seems to work: every *.wma is found and echoed to get converted (even renaming is done)...but when I actually try the script as seen above, it stops after converting the two *.wma-files in ~/test as if the converting of those 2 files ends the reading from the find-piping...

How is that possible? :-/
As you see I'm actual entering the directories, so the directory-names shouldn't cause any problem while converting...there isn't even any error-message: It just quits after the first while-loop... o:|

 Profile WWW ICQ  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group