forked from perkeep/perkeep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
taglib.go
52 lines (45 loc) · 1.13 KB
/
taglib.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
// Package taglib provides utilities for parsing audio tags in
// various formats.
package taglib
import (
"bytes"
"errors"
"io"
"time"
"camlistore.org/third_party/taglib/id3"
)
var (
ErrUnrecognizedFormat = errors.New("taglib: format not recognized")
)
// GenericTag is implemented by all the tag types in this project. It
// gives an incomplete view of the information in each tag type, but
// is good enough for most purposes.
type GenericTag interface {
Title() string
Artist() string
Album() string
Comment() string
Genre() string
Year() time.Time
Track() uint32
}
// Decode reads r and determines which tag format the data is in, if
// any, and calls the decoding function for that format. size
// indicates the total number of bytes accessible through r.
func Decode(r io.ReaderAt, size int64) (GenericTag, error) {
magic := make([]byte, 4)
if _, err := r.ReadAt(magic, 0); err != nil {
return nil, err
}
if !bytes.Equal(magic[:3], []byte("ID3")) {
return nil, ErrUnrecognizedFormat
}
switch magic[3] {
case 3:
return id3.Decode23(r)
case 4:
return id3.Decode24(r)
default:
return nil, ErrUnrecognizedFormat
}
}