Guest User

Untitled

a guest
Jul 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # converts all .flac files to .mp3 and copies them to the
  3. # OUT directory; copies all .mp3 files to the OUT directory.
  4.  
  5. LAMEOPTS="-V0 --quiet"
  6.  
  7. if [ "$#" -ne 2 ]
  8. then
  9. echo "usage: $0 MUSIC_DIR OUTPUT_DIR"
  10. exit 1
  11. fi
  12.  
  13. IN=$1
  14. if [ ! -d "$IN" ]
  15. then
  16. echo "$IN is not a directory"
  17. exit 1
  18. fi
  19.  
  20. OUT=$2
  21. if [ ! -d "$OUT" ]
  22. then
  23. mkdir "$OUT"
  24. fi
  25.  
  26. # first, find all .mp3s and copy them to the OUT dir
  27. # unless they are already there
  28. find "$IN" -iname "*.mp3" | while read mp3;
  29. do
  30. OF=`echo "$mp3" | sed s,"$IN","$OUT\/",g`
  31. dir=`dirname "$OF"`
  32. if [ ! -d "$dir" ]
  33. then
  34. mkdir -p "$dir"
  35. fi
  36. if [ ! -e "$OF" ]
  37. then
  38. echo "copying $mp3 to $OF"
  39. cp "$mp3" "$OF"
  40. fi
  41. done
  42.  
  43. # now, find all .flacs and convert them to .mp3
  44. # unless they have already been converted
  45. find "$IN" -iname "*.flac" | while read flac;
  46. do
  47. OF=`echo "$flac" | sed s/\.flac/\.mp3/g | sed s,"$IN","$OUT\/",g`
  48. dir=`dirname "$OF"`
  49. if [ ! -d "$dir" ]
  50. then
  51. mkdir -p "$dir"
  52. fi
  53. if [ ! -e "$OF" ]
  54. then
  55. # retrieve ID3 tags
  56. ARTIST=`metaflac "$flac" --show-tag=ARTIST | sed s/.*=//g`
  57. TITLE=`metaflac "$flac" --show-tag=TITLE | sed s/.*=//g`
  58. ALBUM=`metaflac "$flac" --show-tag=ALBUM | sed s/.*=//g`
  59. GENRE=`metaflac "$flac" --show-tag=GENRE | sed s/.*=//g`
  60. TRACKNUMBER=`metaflac "$flac" --show-tag=TRACKNUMBER | sed s/.*=//g`
  61. DATE=`metaflac "$flac" --show-tag=DATE | sed s/.*=//g`
  62.  
  63. # convert to MP3, preserving ID3 tags
  64. echo "encoding $flac to $OF"
  65. flac -c -dF --silent "$flac" | lame $LAMEOPTS \
  66. --add-id3v2 --pad-id3v2 --ignore-tag-errors --tt "$TITLE" --tn "${TRACKNUMBER:-0}" --ta "$ARTIST" --tl "$ALBUM" --ty "$DATE" --tg "${GENRE:-12}" \
  67. - "$OF"
  68. fi
  69. done
Add Comment
Please, Sign In to add comment