-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate_ids.go
301 lines (261 loc) · 8.79 KB
/
generate_ids.go
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// Copyright 2017 Tom Thorogood. All rights reserved.
// Use of this source code is governed by a Modified
// BSD License that can be found in the LICENSE file.
//+build ignore
package main
import (
"bufio"
"flag"
"log"
"os"
"strings"
"text/template"
)
// Taken from http://id3.org/id3v2.4.0-frames.
// id3v2.4.0-frames.txt,v 1.1 2003/07/27 18:28:34 id3 Exp
const v24Spec = `
4.19 AENC Audio encryption
4.14 APIC Attached picture
4.30 ASPI Audio seek point index
4.10 COMM Comments
4.24 COMR Commercial frame
4.25 ENCR Encryption method registration
4.12 EQU2 Equalisation (2)
4.5 ETCO Event timing codes
4.15 GEOB General encapsulated object
4.26 GRID Group identification registration
4.20 LINK Linked information
4.4 MCDI Music CD identifier
4.6 MLLT MPEG location lookup table
4.23 OWNE Ownership frame
4.27 PRIV Private frame
4.16 PCNT Play counter
4.17 POPM Popularimeter
4.21 POSS Position synchronisation frame
4.18 RBUF Recommended buffer size
4.11 RVA2 Relative volume adjustment (2)
4.13 RVRB Reverb
4.29 SEEK Seek frame
4.28 SIGN Signature frame
4.9 SYLT Synchronised lyric/text
4.7 SYTC Synchronised tempo codes
4.2.1 TALB Album/Movie/Show title
4.2.3 TBPM BPM (beats per minute)
4.2.2 TCOM Composer
4.2.3 TCON Content type
4.2.4 TCOP Copyright message
4.2.5 TDEN Encoding time
4.2.5 TDLY Playlist delay
4.2.5 TDOR Original release time
4.2.5 TDRC Recording time
4.2.5 TDRL Release time
4.2.5 TDTG Tagging time
4.2.2 TENC Encoded by
4.2.2 TEXT Lyricist/Text writer
4.2.3 TFLT File type
4.2.2 TIPL Involved people list
4.2.1 TIT1 Content group description
4.2.1 TIT2 Title/songname/content description
4.2.1 TIT3 Subtitle/Description refinement
4.2.3 TKEY Initial key
4.2.3 TLAN Language(s)
4.2.3 TLEN Length
4.2.2 TMCL Musician credits list
4.2.3 TMED Media type
4.2.3 TMOO Mood
4.2.1 TOAL Original album/movie/show title
4.2.5 TOFN Original filename
4.2.2 TOLY Original lyricist(s)/text writer(s)
4.2.2 TOPE Original artist(s)/performer(s)
4.2.4 TOWN File owner/licensee
4.2.2 TPE1 Lead performer(s)/Soloist(s)
4.2.2 TPE2 Band/orchestra/accompaniment
4.2.2 TPE3 Conductor/performer refinement
4.2.2 TPE4 Interpreted, remixed, or otherwise modified by
4.2.1 TPOS Part of a set
4.2.4 TPRO Produced notice
4.2.4 TPUB Publisher
4.2.1 TRCK Track number/Position in set
4.2.4 TRSN Internet radio station name
4.2.4 TRSO Internet radio station owner
4.2.5 TSOA Album sort order
4.2.5 TSOP Performer sort order
4.2.5 TSOT Title sort order
4.2.1 TSRC ISRC (international standard recording code)
4.2.5 TSSE Software/Hardware and settings used for encoding
4.2.1 TSST Set subtitle
4.2.2 TXXX User defined text information frame
4.1 UFID Unique file identifier
4.22 USER Terms of use
4.8 USLT Unsynchronised lyric/text transcription
4.3.1 WCOM Commercial information
4.3.1 WCOP Copyright/Legal information
4.3.1 WOAF Official audio file webpage
4.3.1 WOAR Official artist/performer webpage
4.3.1 WOAS Official audio source webpage
4.3.1 WORS Official Internet radio station homepage
4.3.1 WPAY Payment
4.3.1 WPUB Publishers official webpage
4.3.2 WXXX User defined URL link frame
`
// Taken from http://id3.org/id3v2.3.0 §4.
const v23Spec = `
4.20 AENC [[#sec4.20|Audio encryption]]
4.15 APIC [#sec4.15 Attached picture]
4.11 COMM [#sec4.11 Comments]
4.25 COMR [#sec4.25 Commercial frame]
4.26 ENCR [#sec4.26 Encryption method registration]
4.13 EQUA [#sec4.13 Equalization]
4.6 ETCO [#sec4.6 Event timing codes]
4.16 GEOB [#sec4.16 General encapsulated object]
4.27 GRID [#sec4.27 Group identification registration]
4.4 IPLS [#sec4.4 Involved people list]
4.21 LINK [#sec4.21 Linked information]
4.5 MCDI [#sec4.5 Music CD identifier]
4.7 MLLT [#sec4.7 MPEG location lookup table]
4.24 OWNE [#sec4.24 Ownership frame]
4.28 PRIV [#sec4.28 Private frame]
4.17 PCNT [#sec4.17 Play counter]
4.18 POPM [#sec4.18 Popularimeter]
4.22 POSS [#sec4.22 Position synchronisation frame]
4.19 RBUF [#sec4.19 Recommended buffer size]
4.12 RVAD [#sec4.12 Relative volume adjustment]
4.14 RVRB [#sec4.14 Reverb]
4.10 SYLT [#sec4.10 Synchronized lyric/text]
4.8 SYTC [#sec4.8 Synchronized tempo codes]
4.2.1 TALB [#TALB Album/Movie/Show title]
4.2.1 TBPM [#TBPM BPM (beats per minute)]
4.2.1 TCOM [#TCOM Composer]
4.2.1 TCON [#TCON Content type]
4.2.1 TCOP [#TCOP Copyright message]
4.2.1 TDAT [#TDAT Date]
4.2.1 TDLY [#TDLY Playlist delay]
4.2.1 TENC [#TENC Encoded by]
4.2.1 TEXT [#TEXT Lyricist/Text writer]
4.2.1 TFLT [#TFLT File type]
4.2.1 TIME [#TIME Time]
4.2.1 TIT1 [#TIT1 Content group description]
4.2.1 TIT2 [#TIT2 Title/songname/content description]
4.2.1 TIT3 [#TIT3 Subtitle/Description refinement]
4.2.1 TKEY [#TKEY Initial key]
4.2.1 TLAN [#TLAN Language(s)]
4.2.1 TLEN [#TLEN Length]
4.2.1 TMED [#TMED Media type]
4.2.1 TOAL [#TOAL Original album/movie/show title]
4.2.1 TOFN [#TOFN Original filename]
4.2.1 TOLY [#TOLY Original lyricist(s)/text writer(s)]
4.2.1 TOPE [#TOPE Original artist(s)/performer(s)]
4.2.1 TORY [#TORY Original release year]
4.2.1 TOWN [#TOWN File owner/licensee]
4.2.1 TPE1 [#TPE1 Lead performer(s)/Soloist(s)]
4.2.1 TPE2 [#TPE2 Band/orchestra/accompaniment]
4.2.1 TPE3 [#TPE3 Conductor/performer refinement]
4.2.1 TPE4 [#TPE4 Interpreted, remixed, or otherwise modified by]
4.2.1 TPOS [#TPOS Part of a set]
4.2.1 TPUB [#TPUB Publisher]
4.2.1 TRCK [#TRCK Track number/Position in set]
4.2.1 TRDA [#TRDA Recording dates]
4.2.1 TRSN [#TRSN Internet radio station name]
4.2.1 TRSO [#TRSO Internet radio station owner]
4.2.1 TSIZ [#TSIZ Size]
4.2.1 TSRC [#TSRC ISRC (international standard recording code)]
4.2.1 TSSE [#TSEE Software/Hardware and settings used for encoding]
4.2.1 TYER [#TYER Year]
4.2.2 TXXX [#TXXX User defined text information frame]
4.1 UFID [#sec4.1 Unique file identifier]
4.23 USER [#sec4.23 Terms of use]
4.9 USLT [#sec4.9 Unsychronized lyric/text transcription]
4.3.1 WCOM [#WCOM Commercial information]
4.3.1 WCOP [#WCOP Copyright/Legal information]
4.3.1 WOAF [#WOAF Official audio file webpage]
4.3.1 WOAR [#WOAR Official artist/performer webpage]
4.3.1 WOAS [#WOAS Official audio source webpage]
4.3.1 WORS [#WORS Official internet radio station homepage]
4.3.1 WPAY [#WPAY Payment]
4.3.1 WPUB [#WPUB Publishers official webpage]
4.3.2 WXXX [#WXXX User defined URL link frame]
`
var tmpl = template.Must(template.New("").Parse(
"// Code generated by `go run generate_ids.go`. DO NOT EDIT." + `
// Copyright 2017 Tom Thorogood. All rights reserved.
// Use of this source code is governed by a Modified
// BSD License that can be found in the LICENSE file.
package id3v2
// These are the standard frame ids as specified in the
// v2.4.0 and v2.3.0 specifications.
const (
{{- range .}}
Frame{{.ID}} FrameID = '{{index .ID 0 | printf "%c"}}'<<24 | '{{index .ID 1 | printf "%c"}}'<<16 | '{{index .ID 2 | printf "%c"}}'<<8 | '{{index .ID 3 | printf "%c"}}' // {{.Description}}
{{- end}}
)
var _FrameID_map = map[FrameID]string{
{{- range .}}
Frame{{.ID}}: "{{.ID}}: {{.Description}}",
{{- end}}
}
func (id FrameID) String() string {
if str, ok := _FrameID_map[id]; ok {
return str
}
buf := [4]byte{
byte(id >> 24),
byte(id >> 16),
byte(id >> 8),
byte(id),
}
return "FrameID(\"" + string(buf[:]) + "\")"
}
`))
type frameID struct {
ID, Description string
}
func main() {
out := flag.String("out", "frame_ids.go", "the file to write the ids to")
flag.Parse()
var ids []frameID
s := bufio.NewScanner(strings.NewReader(v24Spec))
for s.Scan() {
parts := strings.Fields(s.Text())
if len(parts) < 2 || parts[0][:2] != "4." {
continue
}
ids = append(ids, frameID{parts[1], strings.Join(parts[2:], " ")})
}
if s.Err() != nil {
log.Fatal(s.Err())
}
s = bufio.NewScanner(strings.NewReader(v23Spec))
for s.Scan() {
parts := strings.Fields(s.Text())
if len(parts) < 2 || parts[0][:2] != "4." {
continue
}
comm := strings.IndexByte(s.Text(), '[')
spce := strings.IndexByte(s.Text()[comm:], ' ')
ids = append(ids, frameID{
parts[1],
strings.TrimSpace(s.Text()[comm+spce : len(s.Text())-1]),
})
}
if s.Err() != nil {
log.Fatal(s.Err())
}
uniq := ids[:0]
outer:
for _, id := range ids {
for _, iid := range uniq {
if iid.ID == id.ID {
continue outer
}
}
uniq = append(uniq, id)
}
w, err := os.Create(*out)
if err != nil {
log.Fatal(err)
}
defer w.Close()
if err := tmpl.Execute(w, uniq); err != nil {
log.Fatal(err)
}
}