-
Notifications
You must be signed in to change notification settings - Fork 0
/
udta.go
58 lines (49 loc) · 959 Bytes
/
udta.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
package bmff
import (
"encoding/binary"
)
type UserData struct {
*box
Copyright *Copyright
Boxes []*box
}
func (b *UserData) parse() error {
for subBox := range readBoxes(b.raw) {
var fb *fullbox
switch subBox.boxtype {
case "cprt":
fb = &fullbox{box: subBox}
if err := fb.decode(); err != nil {
return err
}
}
switch subBox.boxtype {
case "cprt":
cprt := &Copyright{fullbox: fb}
if err := cprt.parse(); err != nil {
return err
}
b.Copyright = cprt
default:
b.Boxes = append(b.Boxes, subBox)
}
}
b.raw = nil
return nil
}
type Copyright struct {
*fullbox
LanguageCode string
Data string
}
func (b *Copyright) parse() error {
lang := binary.BigEndian.Uint16(b.raw[0:2]) // first bit is padding
b.LanguageCode = string([]byte{
uint8(lang&0x7C00>>10) + 0x60,
uint8(lang&0x03E0>>5) + 0x60,
uint8(lang&0x001F) + 0x60,
})
b.Data = string(b.raw[2:])
b.raw = nil
return nil
}