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.
 
 
 
 
 
 

169 lines
2.8 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. fields='TITLE VERSION ALBUM TRACKNUMBER ARTIST PERFORMER COPYRIGHT LICENSE ORGANIZATION DESCRIPTION GENRE DATE LOCATION CONTACT ISRC'
  33. # fields' corresponding cueprint conversion characters
  34. # seperate alternates with a space
  35. TITLE='%t'
  36. VERSION=''
  37. ALBUM='%T'
  38. TRACKNUMBER='%n'
  39. ARTIST='%c %p'
  40. PERFORMER='%p'
  41. COPYRIGHT=''
  42. LICENSE=''
  43. ORGANIZATION=''
  44. DESCRIPTION='%m'
  45. GENRE='%g'
  46. DATE=''
  47. LOCATION=''
  48. CONTACT=''
  49. ISRC='%i %u'
  50. (for field in $fields; do
  51. value=""
  52. for conv in `eval echo \\$$field`; do
  53. value=`$CUEPRINT -n $1 -t "$conv\n" $cue_file`
  54. if [ -n "$value" ]; then
  55. echo "$field=$value"
  56. break
  57. fi
  58. done
  59. done) | $VORBISTAG "$2"
  60. }
  61. id3()
  62. {
  63. MP3INFO=mp3info
  64. # space seperated list of ID3 v1.1 tags
  65. # see http://id3lib.sourceforge.net/id3/idev1.html
  66. fields="TITLE ALBUM ARTIST YEAR COMMENT GENRE TRACKNUMBER"
  67. # fields' corresponding cueprint conversion characters
  68. # seperate alternates with a space
  69. TITLE='%t'
  70. ALBUM='%T'
  71. ARTIST='%p'
  72. YEAR=''
  73. COMMENT='%c'
  74. GENRE='%g'
  75. TRACKNUMBER='%n'
  76. for field in $fields; do
  77. value=""
  78. for conv in `eval echo \\$$field`; do
  79. value=`$CUEPRINT -n $1 -t "$conv\n" $cue_file`
  80. if [ -n "$value" ]; then
  81. break
  82. fi
  83. done
  84. if [ -n "$value" ]; then
  85. case $field in
  86. TITLE)
  87. $MP3INFO -t "$value" "$2"
  88. ;;
  89. ALBUM)
  90. $MP3INFO -l "$value" "$2"
  91. ;;
  92. ARTIST)
  93. $MP3INFO -a "$value" "$2"
  94. ;;
  95. YEAR)
  96. $MP3INFO -y "$value" "$2"
  97. ;;
  98. COMMENT)
  99. $MP3INFO -c "$value" "$2"
  100. ;;
  101. GENRE)
  102. $MP3INFO -g "$value" "$2"
  103. ;;
  104. TRACKNUMBER)
  105. $MP3INFO -n "$value" "$2"
  106. ;;
  107. esac
  108. fi
  109. done
  110. }
  111. main()
  112. {
  113. if [ $# -lt 1 ]; then
  114. usage
  115. exit
  116. fi
  117. cue_file=$1
  118. shift
  119. ntrack=`cueprint -d '%N' $cue_file`
  120. trackno=1
  121. if [ $# -ne $ntrack ]; then
  122. echo "warning: number of files does not match number of tracks"
  123. fi
  124. for file in $@; do
  125. case $file in
  126. *.[Ff][Ll][Aa][Cc])
  127. vorbis $trackno "$file"
  128. ;;
  129. *.[Oo][Gg][Gg])
  130. vorbis $trackno "$file"
  131. ;;
  132. *.[Mm][Pp]3)
  133. id3 $trackno "$file"
  134. ;;
  135. *)
  136. echo "$file: uknown file type"
  137. ;;
  138. esac
  139. trackno=$(($trackno + 1))
  140. done
  141. }
  142. main "$@"