-
Notifications
You must be signed in to change notification settings - Fork 0
/
v1.go
256 lines (244 loc) · 4.02 KB
/
v1.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
package id3
import (
"errors"
"io"
"os"
"strings"
)
const (
v1TagSize = 128
)
func readv1(r io.ReadSeeker) (*Tag, error) {
_, err := r.Seek(-v1TagSize, os.SEEK_END)
if err != nil {
if strings.HasSuffix(err.Error(), "An attempt was made to move the file pointer before the beginning of the file.") {
return nil, ErrTooShort
}
return nil, err
}
data := make([]byte, v1TagSize)
n, err := io.ReadFull(r, data)
if err != nil {
return nil, err
}
if n < v1TagSize {
return nil, ErrTooShort
}
if string(data[:3]) != "TAG" {
return nil, ErrNoHeader
}
tag := emptyTag()
title := strings.TrimRight(string(data[3:33]), "\x00")
artist := strings.TrimRight(string(data[33:63]), "\x00")
album := strings.TrimRight(string(data[63:93]), "\x00")
year := strings.TrimRight(string(data[93:97]), "\x00")
comment := strings.TrimRight(string(data[97:127]), "\x00")
genreByte := int(data[127])
if genreByte >= len(v1Genres) {
return nil, errors.New("Unknown v1 genre")
}
genre := v1Genres[genreByte]
tag.addFrame(simpleTextFrame(tag, "TT2", title))
tag.addFrame(simpleTextFrame(tag, "TP1", artist))
tag.addFrame(simpleTextFrame(tag, "TAL", album))
tag.addFrame(simpleTextFrame(tag, "TYE", year))
tag.addFrame(simpleTextFrame(tag, "TCO", genre))
tag.addFrame(simpleTextFrame(tag, "COM", comment))
return tag, nil
}
var (
v1Genres = []string{
"Blues",
"Classic Rock",
"Country",
"Dance",
"Disco",
"Funk",
"Grunge",
"Hip-Hop",
"Jazz",
"Metal",
"New Age",
"Oldies",
"Other",
"Pop",
"R&B",
"Rap",
"Reggae",
"Rock",
"Techno",
"Industrial",
"Alternative",
"Ska",
"Death Metal",
"Pranks",
"Soundtrack",
"Euro-Techno",
"Ambient",
"Trip-Hop",
"Vocal",
"Jazz+Funk",
"Fusion",
"Trance",
"Classical",
"Instrumental",
"Acid",
"House",
"Game",
"Sound Clip",
"Gospel",
"Noise",
"AlternRock",
"Bass",
"Soul",
"Punk",
"Space",
"Meditative",
"Instrumental Pop",
"Instrumental Rock",
"Ethnic",
"Gothic",
"Darkwave",
"Techno-Industrial",
"Electronic",
"Pop-Folk",
"Eurodance",
"Dream",
"Southern Rock",
"Comedy",
"Cult",
"Gangsta",
"Top 40",
"Christian Rap",
"Pop/Funk",
"Jungle",
"Native American",
"Cabaret",
"New Wave",
"Psychadelic",
"Rave",
"Showtunes",
"Trailer",
"Lo-Fi",
"Tribal",
"Acid Punk",
"Acid Jazz",
"Polka",
"Retro",
"Musical",
"Rock & Roll",
"Hard Rock",
"Folk",
"Folk-Rock",
"National Folk",
"Swing",
"Fast Fusion",
"Bebop",
"Latin",
"Revival",
"Celtic",
"Bluegrass",
"Avantgarde",
"Gothic Rock",
"Progressive Rock",
"Psychedelic Rock",
"Symphonic Rock",
"Slow Rock",
"Big Band",
"Chorus",
"Easy Listening",
"Acoustic",
"Humour",
"Speech",
"Chanson",
"Opera",
"Chamber Music",
"Sonata",
"Symphony",
"Booty Bass",
"Primus",
"Porn groove",
"Satire",
"Slow Jam",
"Club",
"Tango",
"Samba",
"Folklore",
"Ballad",
"Power Ballad",
"Rhythmic Soul",
"Freestyle",
"Duet",
"Punk rock",
"Drum Solo",
"A capella",
"Euro-House",
"Dance Hall",
"Goa Trance",
"Drum & Bass",
"Club-House",
"Hardcore Techno",
"Terror",
"Indie",
"BritPop",
"Afro-punk",
"Polsk Punk",
"Beat",
"Christian Gangsta Rap",
"Heavy Metal",
"Black Metal",
"Crossover",
"Contemporary Christian",
"Christian Rock",
"Merengue",
"Salsa",
"Thrash Metal",
"Anime",
"Jpop",
"Synthpop",
"Abstract",
"Art Rock",
"Baroque",
"Bhangra",
"Big Beat",
"Breakbeat",
"Chillout",
"Downtempo",
"Dub",
"EBM",
"Eclectic",
"Electro",
"Electroclash",
"Emo",
"Experimental",
"Garage",
"Global",
"IDM",
"Illbient",
"Industro-Goth",
"Jam Band",
"Krautrock",
"Leftfield",
"Lounge",
"Math Rock",
"New Romantic",
"Nu-Breakz",
"Post-Punk",
"Post-Rock",
"Psytrance",
"Shoegaze",
"Space Rock",
"Trop Rock",
"World Music",
"Neoclassical",
"Audiobook",
"Audio Theatre",
"Neue Deutsche Welle",
"Podcast",
"Indie Rock",
"G-Funk",
"Dubstep",
"Garage Rock",
"Psybient",
}
)