You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

181 lines
3.3 KiB

  1. #! /bin/sh
  2. # cuetag.sh - tag files based on cue/toc file information
  3. # uses cueprint output
  4. # usage: cuetag.sh <cuefile|tocfile> [file]...
  5. CUEPRINT=cueprint
  6. cue_file=""
  7. # print usage instructions
  8. usage()
  9. {
  10. echo "usage: cuetag.sh <cuefile|tocfile> [file]..."
  11. echo
  12. echo "cuetag.sh adds tags to autofiles based on cue or toc information"
  13. echo
  14. echo "Supported formats (format extension, format name, tagging utility):"
  15. echo "ogg, Ogg Vorbis, vorbiscomment"
  16. echo "flac, FLAC, metaflac"
  17. echo "mp3, MP3, mp3info"
  18. echo
  19. echo "cuetag.sh uses cueprint, which must be in your path"
  20. }
  21. # Vorbis Comments
  22. # for FLAC and Ogg Vorbis files
  23. vorbis()
  24. {
  25. # FLAC tagging
  26. # --remove-vc-all overwrites existing comments
  27. METAFLAC="metaflac --remove-vc-all --import-vc-from=-"
  28. # Ogg Vorbis tagging
  29. # -w overwrites existing comments
  30. # -a appends to existing comments
  31. VORBISCOMMENT="vorbiscomment -w -c -"
  32. case "$2" in
  33. *.[Ff][Ll][Aa][Cc])
  34. VORBISTAG=$METAFLAC
  35. ;;
  36. *.[Oo][Gg][Gg])
  37. VORBISTAG=$VORBISCOMMENT
  38. ;;
  39. esac
  40. # space seperated list of recomended stardard field names
  41. # see http://www.xiph.org/ogg/vorbis/doc/v-comment.html
  42. # TRACKTOTAL is not in the Xiph recomendation, but is in common use
  43. fields='TITLE VERSION ALBUM TRACKNUMBER TRACKTOTAL ARTIST PERFORMER COPYRIGHT LICENSE ORGANIZATION DESCRIPTION GENRE DATE LOCATION CONTACT ISRC'
  44. # fields' corresponding cueprint conversion characters
  45. # seperate alternates with a space
  46. TITLE='%t'
  47. VERSION=''
  48. ALBUM='%T'
  49. TRACKNUMBER='%n'
  50. TRACKTOTAL='%N'
  51. ARTIST='%c %p'
  52. PERFORMER='%p'
  53. COPYRIGHT=''
  54. LICENSE=''
  55. ORGANIZATION=''
  56. DESCRIPTION='%m'
  57. GENRE='%g'
  58. DATE=''
  59. LOCATION=''
  60. CONTACT=''
  61. ISRC='%i %u'
  62. (for field in $fields; do
  63. value=""
  64. for conv in `eval echo \\$$field`; do
  65. value=`$CUEPRINT -n $1 -t "$conv\n" $cue_file`
  66. if [ -n "$value" ]; then
  67. echo "$field=$value"
  68. break
  69. fi
  70. done
  71. done) | $VORBISTAG "$2"
  72. }
  73. id3()
  74. {
  75. MP3INFO=mp3info
  76. # space seperated list of ID3 v1.1 tags
  77. # see http://id3lib.sourceforge.net/id3/idev1.html
  78. fields="TITLE ALBUM ARTIST YEAR COMMENT GENRE TRACKNUMBER"
  79. # fields' corresponding cueprint conversion characters
  80. # seperate alternates with a space
  81. TITLE='%t'
  82. ALBUM='%T'
  83. ARTIST='%p'
  84. YEAR=''
  85. COMMENT='%c'
  86. GENRE='%g'
  87. TRACKNUMBER='%n'
  88. for field in $fields; do
  89. value=""
  90. for conv in `eval echo \\$$field`; do
  91. value=`$CUEPRINT -n $1 -t "$conv\n" $cue_file`
  92. if [ -n "$value" ]; then
  93. break
  94. fi
  95. done
  96. if [ -n "$value" ]; then
  97. case $field in
  98. TITLE)
  99. $MP3INFO -t "$value" "$2"
  100. ;;
  101. ALBUM)
  102. $MP3INFO -l "$value" "$2"
  103. ;;
  104. ARTIST)
  105. $MP3INFO -a "$value" "$2"
  106. ;;
  107. YEAR)
  108. $MP3INFO -y "$value" "$2"
  109. ;;
  110. COMMENT)
  111. $MP3INFO -c "$value" "$2"
  112. ;;
  113. GENRE)
  114. $MP3INFO -g "$value" "$2"
  115. ;;
  116. TRACKNUMBER)
  117. $MP3INFO -n "$value" "$2"
  118. ;;
  119. esac
  120. fi
  121. done
  122. }
  123. main()
  124. {
  125. if [ $# -lt 1 ]; then
  126. usage
  127. exit
  128. fi
  129. cue_file=$1
  130. shift
  131. ntrack=`cueprint -d '%N' $cue_file`
  132. trackno=1
  133. if [ $# -ne $ntrack ]; then
  134. echo "warning: number of files does not match number of tracks"
  135. fi
  136. for file in $@; do
  137. case $file in
  138. *.[Ff][Ll][Aa][Cc])
  139. vorbis $trackno "$file"
  140. ;;
  141. *.[Oo][Gg][Gg])
  142. vorbis $trackno "$file"
  143. ;;
  144. *.[Mm][Pp]3)
  145. id3 $trackno "$file"
  146. ;;
  147. *)
  148. echo "$file: uknown file type"
  149. ;;
  150. esac
  151. trackno=$(($trackno + 1))
  152. done
  153. }
  154. main "$@"