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.
 
 
 
 
 
 

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