-
Notifications
You must be signed in to change notification settings - Fork 5
/
tag.go
64 lines (53 loc) · 997 Bytes
/
tag.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
package tag
import (
"io"
"os"
)
func ReadFile(path string) (Metadata, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
return Read(file)
}
func Read(input io.ReadSeeker) (Metadata, error) {
version := CheckVersion(input)
switch version {
case VersionID3v1:
return ReadID3v1(input)
case VersionID3v22:
return ReadID3v22(input)
case VersionID3v23:
return ReadID3v23(input)
case VersionID3v24:
return ReadID3v24(input)
case VersionMP4:
return ReadMp4(input)
case VersionFLAC:
return ReadFLAC(input)
default:
return nil, ErrUnsupportedFormat
}
}
func CheckVersion(input io.ReadSeeker) Version {
if checkID3v24(input) {
return VersionID3v24
}
if checkID3v23(input) {
return VersionID3v23
}
if checkID3v22(input) {
return VersionID3v22
}
if checkID3v1(input) {
return VersionID3v1
}
if checkMp4(input) {
return VersionMP4
}
if checkFLAC(input) {
return VersionFLAC
}
return VersionUndefined
}