Advertisement
julian_hughes

cue2flacs improved

Jul 8th, 2012
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # cue2flacs
  4. # Copyright (C) 2012 Julian Hughes julianhughes<at>gmailDOTcom
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # DEPENDENCIES:
  20. # shntool ; cuetag ; flac ; iconv ; python-chardet
  21. # and any other codecs required: for a list of supported codecs see
  22. # the shntool manpage
  23. #
  24.  
  25. function usage ()
  26. {
  27. printf "\n\nUSAGE:\
  28. \t$(basename "$0") /path/to/cue_file.cue\n
  29. \tUse find for recursion/multiple cue+image files:\n
  30. \tfind <path> -iname "*.cue" -execdir $(basename "$0") "{}" \+\n
  31. \tThe lossless file must be named exactly as stated in the cue\n\tfile.
  32. \n\t$(basename "$0") splits cue+lossless into individual flacs, named
  33. \tand tagged using the info in the cue.
  34. \tIf the cue sheet is non UTF-8 then a new UTF-8 cue is created.
  35. \tThis preserves diacritic marks and non-Latin characters.\n
  36. \t$(basename "$0") outputs to a new directory whose name is derived
  37. \tfrom the cue's first TITLE field. No existing files are deleted
  38. \toverwritten or modified by this script.
  39. \tFor a list of supported codecs see the shntool manpage.\n
  40. \tThere are no user options or settings.\n
  41. \tI didn't include error checking so if it fails uncomment
  42. \t'set -x' and have a look for yourself.\n\n"
  43. }
  44.  
  45. if [ $# -lt 1 ]; then
  46. usage
  47. exit 1
  48. fi
  49.  
  50. for i in "$@" ; do
  51.  
  52. #find character encoding of cue. if not utf-8 then create new utf-8 cue
  53. UTFCUE="${i%.*}"_utf.cue
  54. CHARSET="$(chardet "$i" |cut -d ":" -f 2|cut -d "(" -f 1 )"
  55. if [ "$CHARSET" != utf-8 ]; then
  56. iconv -f "$CHARSET" -t utf8 "$i" -o "$UTFCUE"
  57. CUE="$UTFCUE"
  58. else
  59. CUE="$i"
  60. fi
  61.  
  62. #get lossless image file name from $CUE
  63. IMG="$(dirname "$i")"/"$(grep FILE "$CUE"|awk -F "\"" '{print $2}')"
  64.  
  65. #get album title from $CUE; remove unwanted characters.
  66. ALBUM="$(cueprint -d '%T\n' "$CUE")"
  67. ALBUM="$(echo $ALBUM |sed 's/[;]/-/g;s/[/]/-/g;s/[<]/-/g;s/[>]/-/g;s/[:]/-/g;s/[|]/-/g;s/[\]/-/g;s/[\]/-/g')"
  68.  
  69. OUTDIR="$(dirname "$i")"/$ALBUM
  70.  
  71. #quit if lossless image file doesn't exist
  72. if [ ! -e "$IMG" ]; then
  73. printf "\n\tSupported lossless file not found. Check that cue \
  74. file references a valid file\n\n"
  75. exit
  76. fi
  77.  
  78. #create output directory
  79. if [ ! -d "$OUTDIR" ]; then
  80. mkdir "$OUTDIR"
  81. fi
  82.  
  83. #split image and set file names from cue: 'number - title'
  84. shnsplit -d "$OUTDIR" -f "$CUE" -t "%n - %t" -o flac "$IMG"
  85.  
  86. #remove unwanted pregap files (if any)
  87. if [ -e "$OUTDIR"/"00 - pregap.flac" ]; then
  88. rm "$OUTDIR"/"00 - pregap.flac"
  89. fi
  90.  
  91. #write tags from cue to new files
  92. cuetag "$CUE" "$OUTDIR"/*.flac
  93. done
  94. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement