Register
It is currently Fri Oct 24, 2014 3:32 am

encode mp3 from flac


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue May 17, 2005 7:47 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
Code:
#!/bin/bash
# Author:  Joshua Bailey
# Copyright: None :)
# Warranty: None :)
# Use as shown:
# flac2mp3 /source/directory/of/music/collection
# for me it's
# flac2mp3 /ripped/music/flac
# my files are stored in the format:
# /base/dir/flac/artist/album/song.flac
# so the command at that point would be:
# flac2mp3 /base/dir/flac


fSlash='/'

function notAForwardSlash
{
   if [[ $1 != $fSlash ]]
        then
      return 0
        else
           return 1
        fi
}
### end notAForwardSlash ###


function getFileName
{
   STRING="${1}"
        LENGTH=${#STRING}
   # echo "${STRING}: is ${LENGTH} long"
   for ((n=0;n <= $LENGTH; n++))
        do
      CHAR=${STRING:$n:1}
      if notAForwardSlash $CHAR
      then
         FileName="${FileName}${CHAR}"
      else
         FileName=""
      fi
      # echo "${FileName}"
   done
}
### end getFileName ###

function encode_mp3
{
   old_file="${1}"
   new_dir="${2}"
   getFileName "${old_file}"
   new_file="${FileName:0:${#FileName}-5}.mp3"
   
        # this is the important part of this script
        # the actual encoding
        # the rest is just stuff to make it easier and less tedious
   flac -d -o - "${old_file}" | lame -b 320 -h - > "${new_dir}/${new_file}"
}

source_dir="${1}"
if [[ "${source_dir:${#source_dir}-1:1}" = '/' ]]
then
   source_dir="${source_dir:0:${#source_dir}-1}"
fi

read -p "Enter the destination directory: " dir

if [[ ! -e "${dir}" ]]
then
   echo ":: That directory doesn't exist!"
   read -p "Would you like to create it? (Y|n)" ans
   if [[ ${#ans} > 0 ]]
   then
      ans=`echo ${ans} | tr [:upper:] [:lower:]`
   else
      ans='y'
   fi
   
if [[ ${ans} = 'n' ]]
then
   echo ":: ${dir} does not exist!"
   echo ":: Aborting!"
else
   mkdir "${dir}" 2> /dev/null
   if [[ $? = 0 ]]
   then
      echo ":: ${dir} created successfully"
   else
      echo ":: Failed creating ${dir}"
      echo ": Aborting!"
      exit
   fi
fi
fi

read -p "Enter the artists name: " artist

ls -Rd "${source_dir}/${artist}"/*/ > "${source_dir}/${artist}"/albumlist.dat
clear
echo ":: The albums found under that artists directory are as shown:"
cat "${source_dir}/${artist}/albumlist.dat"
read -p ":: Are these the correct albums that you would like to encode? (y|n) " ans
ans=`echo ${ans:0:1} | tr [:upper:] [:lower:]`
if [[ ${ans} != 'y' ]]
then
   exit
fi

until ! read cur_album
do
   album="${cur_album:0:${#cur_album}-1}"
   getFileName "${album}"
   album="${FileName}"
   ls "${source_dir}/${artist}/${album}"/*.flac > "${source_dir}/${artist}/${album}"/songsonalbum.dat
   clear
   echo ":: Beginning to encode the following songs:"
   cat "${source_dir}/${artist}/${album}/songsonalbum.dat"
   
   if [[ ! -e "${dir}/${artist}" ]]
   then
      mkdir "${dir}/${artist}"
   fi

   if [[ ! -e "${dir}/${artist}/${album}" ]]
   then
      mkdir "${dir}/${artist}/${album}"
   fi
   
   until ! read cur_song
   do
      getFileName "${cur_song}"
      song="${FileName}"
      FileName=""
      encode_mp3 "${cur_song}" "${dir}/${artist}/${album}" "${song}"
   done < "${source_dir}/${artist}/${album}"/songsonalbum.dat


done < "${source_dir}/${artist}"/albumlist.dat


Top
 Profile  
 PostPosted: Sat Jul 22, 2006 1:28 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
I'm probably not running this right, but I keep getting an error when executing this.

Code:
coastie@foxhole:~/Scripts> ./flactomp3
Enter the destination directory: /home/coastie/Desktop/Music/Romeo
Enter the artists name: Various\ Artists
./flactomp3: line 99: /Various Artists/albumlist.dat: No such file or directory


:: The albums found under that artists directory are as shown:
cat: /Various Artists/albumlist.dat: No such file or directory
:: Are these the correct albums that you would like to encode? (y|n) y
./flactomp3: line 139: /Various Artists/albumlist.dat: No such file or directory
coastie@foxhole:~/Scripts>


Top
 Profile YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 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