flac2perfect3.sh 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/bin/ash
  2. # Requires:
  3. # - flac
  4. # - lame
  5. # - eyeD3
  6. TMP_CONVERT=".tmp"
  7. rm -rf $TMP_CONVERT
  8. mkdir $TMP_CONVERT
  9. # We do it on all tracks in case we hit one with missing infos
  10. extract_album() {
  11. metaflac --show-tag=artist --show-tag=album --show-tag=date --show-tag=genre *.flac \
  12. | sed 's/^.*://g' \
  13. | sort | uniq \
  14. | while read line; do
  15. part1=$(echo $line | cut -f 1 -d = | tr '[A-Z]' '[a-z]')
  16. part2=$(echo $line | cut -f 2 -d =)
  17. echo "${part1}=\"${part2}\"" >> $TMP_CONVERT/album
  18. done
  19. }
  20. # Get track title and number
  21. extract_tracks() {
  22. ls -1 *.flac \
  23. | while read file; do
  24. metaflac --show-tag=title --show-tag=tracknumber "${file}" \
  25. | while read line; do
  26. part1=$(echo $line | cut -f 1 -d = | tr '[A-Z]' '[a-z]')
  27. part2=$(echo $line | cut -f 2 -d =)
  28. echo "${part1}=\"${part2}\"" >> $TMP_CONVERT/"${file}".track
  29. done
  30. done
  31. }
  32. # Verify we get album details
  33. verify_album() {
  34. . $TMP_CONVERT/album
  35. if [ -z $artist ]; then
  36. echo "Missing artist name. Please provide"
  37. read ARTIST
  38. sed -i "s#^artist=.*#artist=\"$ARTIST\"#" $TMP_CONVERT/album
  39. fi
  40. }
  41. # CBR 320
  42. make_320() {
  43. mkdir -p $TMP_CONVERT/320
  44. . $TMP_CONVERT/album
  45. ls -1 *.flac \
  46. | while read file; do
  47. . $TMP_CONVERT/"${file}".track
  48. flac -d -c "${file}" \
  49. | lame -b 320 - $TMP_CONVERT/320/"${file/.flac/.mp3}"
  50. eyeD3 -2 \
  51. -a "$artist" \
  52. -A "$album" \
  53. -Y "$date" \
  54. -G "$genre" \
  55. -t "$title" \
  56. -n "$tracknumber" \
  57. $TMP_CONVERT/320/"${file/.flac/.mp3}"
  58. done
  59. }
  60. # VBR 0
  61. make_V0() {
  62. mkdir -p $TMP_CONVERT/V0
  63. . $TMP_CONVERT/album
  64. ls -1 *.flac \
  65. | while read file; do
  66. . $TMP_CONVERT/"${file}".track
  67. flac -d -c "${file}" \
  68. | lame -V0 - $TMP_CONVERT/V0/"${file/.flac/.mp3}"
  69. eyeD3 -2 \
  70. -a "$artist" \
  71. -A "$album" \
  72. -Y "$date" \
  73. -G "$genre" \
  74. -t "$title" \
  75. -n "$tracknumber" \
  76. $TMP_CONVERT/V0/"${file/.flac/.mp3}"
  77. done
  78. }
  79. # VBR 2
  80. make_V2() {
  81. mkdir -p $TMP_CONVERT/V2
  82. . $TMP_CONVERT/album
  83. ls -1 *.flac \
  84. | while read file; do
  85. . $TMP_CONVERT/"${file}".track
  86. flac -d -c "${file}" \
  87. | lame -V2 - $TMP_CONVERT/V2/"${file/.flac/.mp3}"
  88. eyeD3 -2 \
  89. -a "$artist" \
  90. -A "$album" \
  91. -Y "$date" \
  92. -G "$genre" \
  93. -t "$title" \
  94. -n "$tracknumber" \
  95. $TMP_CONVERT/V2/"${file/.flac/.mp3}"
  96. done
  97. }
  98. make_directories() {
  99. HERE="$(basename "$(pwd)")"
  100. for i in 320 V0 V2; do
  101. THERE=$(echo ${HERE} | sed "s#flac#MP3 $i#i")
  102. mkdir ../"${THERE}"
  103. mv $TMP_CONVERT/$i/* ../"${THERE}"
  104. cp -f *.jpg *.JPG *.png *.PNG ../"${THERE}"
  105. done
  106. }
  107. cleanup() {
  108. rm -rf $TMP_CONVERT
  109. }
  110. # Main function
  111. main() {
  112. extract_album
  113. extract_tracks
  114. #verify_album
  115. make_320
  116. make_V0
  117. make_V2
  118. make_directories
  119. cleanup
  120. }
  121. # START
  122. main