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.
 
 
 
 
 
 

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