Advertisement
woohoo

flac2mp3

Feb 14th, 2012
1,511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.71 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Copyright 2008 Octavio Ruiz
  4. # Distributed under the terms of the GNU General Public License v3
  5. # $Header: $
  6. #
  7. # Yet Another FLAC to MP3 script
  8. #
  9. # Author:
  10. # Octavio Ruiz (Ta^3) <tacvbo@tacvbo.net>
  11. # Thanks:
  12. # Those comments at:
  13. # http://www.linuxtutorialblog.com/post/solution-converting-flac-to-mp3
  14. # WebPage:
  15. # https://github.com/tacvbo/yaflac2mp3/tree
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY. YOU USE AT YOUR OWN RISK. THE AUTHOR
  19. # WILL NOT BE LIABLE FOR DATA LOSS, DAMAGES, LOSS OF PROFITS OR ANY
  20. # OTHER KIND OF LOSS WHILE USING OR MISUSING THIS SOFTWARE.
  21. # See the GNU General Public License for more details.
  22. #
  23. # Modified by woohoo
  24. #
  25. # you need zenity package for notifications.
  26. # please note that you can put this script in ~/.gnome2/nautilus-scripts
  27. # and it will show up in right-click menu in any folder in gnome.
  28. #
  29. # modify the lame options to your preference example change -b 320 to -b 128 or -b 192 or -b 256
  30. # LAME_OPTS="--vbr-new -V 0 -b 256"
  31. # LAME_OPTS="-V 0 --vbr-new"
  32.  
  33. LAME_OPTS="-b 320 -h --cbr"
  34.  
  35. old_IFS=${IFS}
  36. IFS='
  37. '
  38.  
  39. # when running from nautilus-scripts, it useful to find the current folder
  40. base="`echo $NAUTILUS_SCRIPT_CURRENT_URI | cut -d'/' -f3- | sed 's/%20/ /g'`"
  41. if [ -z "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then
  42.   dir="$base"
  43. else
  44.   while [ ! -z "$1" -a ! -d "$base/$1" ]; do shift; done
  45.   dir="$base/$1"
  46. fi
  47.  
  48. if [ "$dir" != "" ]; then
  49.   cd "$dir"
  50. fi
  51.  
  52. id3v2=$(which id3v2)
  53.  
  54. files=`find . -type f -regex '^.+\.flac$' | sort`
  55.  
  56. declare -i nn=0
  57. for file in ${files}
  58. do
  59.   fn=$(readlink -f "$file")
  60.   vars=( `metaflac --no-utf8-convert --export-tags-to=- "${fn}"` )
  61.  
  62.   for N_vars in ${!vars[@]}
  63.   do
  64.     export "$(echo "${vars[${N_vars}]%=*}" | tr [:upper:] [:lower:])=${vars[${N_vars}]#*=}"
  65.   done
  66.  
  67.   dest=`echo "$fn"|sed -e 's/\.flac$/\.mp3/'`
  68.  
  69.   flac -dc "$fn" |\
  70.     lame --ignore-tag-errors --add-id3v2 ${LAME_OPTS} \
  71.         ${artist:+--ta} ${artist} \
  72.         ${tracknumber:+--tn} ${tracknumber} \
  73.         ${title:+--tt} ${title} \
  74.         ${album:+--tl} ${album} \
  75.         ${date:+--ty} ${date} \
  76.         ${genre:+--tg} ${genre} \
  77.         ${comment:+--tc} ${comment} \
  78.         - $dest
  79.  
  80.     [[ -x ${id3v2} ]] && ${id3v2} \
  81.         ${artist:+--artist} ${artist} \
  82.         ${tracknumber:+--track} ${tracknumber} \
  83.         ${title:+--song} ${title} \
  84.         ${album:+--album} ${album} \
  85.         ${date:+--year} ${date} \
  86.         ${genre:+--genre} ${genre} \
  87.         ${comment:+--comment} ${comment} \
  88.         $dest
  89.  
  90.   let nn=nn+1
  91. done
  92.  
  93. zenity --notification --text "Finished converting flac to mp3.${IFS}Processed ${nn} files."
  94. #zenity --info --text "Done!"
  95. IFS=${old_IFS}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement