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