-
Notifications
You must be signed in to change notification settings - Fork 52
/
picture_frame.go
65 lines (55 loc) · 1.61 KB
/
picture_frame.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
// Copyright 2016 Albert Nigmatzianov. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package id3v2
import (
"io"
)
// PictureFrame structure is used for picture frames (APIC).
// The information about how to add picture frame to tag you can
// see in the docs to tag.AddAttachedPicture function.
//
// Available picture types you can see in constants.
type PictureFrame struct {
Encoding Encoding
MimeType string
PictureType byte
Description string
Picture []byte
}
func (pf PictureFrame) UniqueIdentifier() string {
return pf.Description
}
func (pf PictureFrame) Size() int {
return 1 + len(pf.MimeType) + 1 + 1 + encodedSize(pf.Description, pf.Encoding) +
len(pf.Encoding.TerminationBytes) + len(pf.Picture)
}
func (pf PictureFrame) WriteTo(w io.Writer) (n int64, err error) {
return useBufWriter(w, func(bw *bufWriter) {
bw.WriteByte(pf.Encoding.Key)
bw.WriteString(pf.MimeType)
bw.WriteByte(0)
bw.WriteByte(pf.PictureType)
bw.EncodeAndWriteText(pf.Description, pf.Encoding)
bw.Write(pf.Encoding.TerminationBytes)
bw.Write(pf.Picture)
})
}
func parsePictureFrame(br *bufReader) (Framer, error) {
encoding := getEncoding(br.ReadByte())
mimeType := br.ReadText(EncodingISO)
pictureType := br.ReadByte()
description := br.ReadText(encoding)
picture := br.ReadAll()
if br.Err() != nil {
return nil, br.Err()
}
pf := PictureFrame{
Encoding: encoding,
MimeType: string(mimeType),
PictureType: pictureType,
Description: decodeText(description, encoding),
Picture: picture,
}
return pf, nil
}