Register
It is currently Thu Apr 24, 2014 12:15 am

Add bitrate to mp3 filename


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Thu Oct 28, 2010 3:52 pm   

Joined: Thu Oct 28, 2010 3:48 pm
Posts: 1
Code:
#!/bin/bash

   set -e

   # use this to recursively search directories
   # will not work if filenames have spaces!
   for FILENAME in $(find . -name "*.mp3"); do

      # test if audio file already has bitrate in filename?
      # use 'sed' to test the three characters before the extension
      # if they are numeric characters or not.
      while [[ `echo $FILENAME | sed 's/^.*\(...\)\..*/\1/'` != *[0-9]* ]]

         do
         
            break
            
         done
   

      if [[ `echo $FILENAME | sed 's/^.*\(...\)\..*/\1/'` != *[0-9]* ]]; then

         BASENAME="${FILENAME%.[^.]*}"
         EXT="${FILENAME:${#BASENAME} + 1}"

      # id3info does NOT read VBR correctly!
      # vbrfix improves bitrate accuraccy but not for every file
         BITRATE=`id3info "$FILENAME" | grep "Bitrate" | cut -c 10-12`

      # this conditional only works for id3info
         if [[ $BITRATE = ??K ]]; then

         # Bitrate is less than 100
            BITRATE=0${BITRATE:0:2}

         fi

         echo $BASENAME.$BITRATE.$EXT

         # uncomment to actually rename files
         #mv -Tv "$FILENAME" "$BASENAME.$BITRATE.$EXT"
   
      fi

   done
      


enjoy!


Top
 Profile  
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: No registered users and 4 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
© 2003 - 2011 USA LINUX USERS GROUP