kopia lustrzana https://github.com/jcs/id3-go
Fix sizes affected by encoding
rodzic
8b38aba2a1
commit
6efa87ae15
25
v2/frame.go
25
v2/frame.go
|
@ -299,7 +299,8 @@ type DescTextFrame struct {
|
|||
|
||||
func NewDescTextFrame(ft FrameType, desc, text string) *DescTextFrame {
|
||||
f := NewTextFrame(ft, text)
|
||||
f.size += uint32(len(desc))
|
||||
nullLength := encodedbytes.EncodingNullLengthForIndex(f.encoding)
|
||||
f.size += uint32(len(desc) + nullLength)
|
||||
|
||||
return &DescTextFrame{
|
||||
TextFrame: *f,
|
||||
|
@ -355,12 +356,16 @@ func (f *DescTextFrame) SetEncoding(encoding string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
newNullLength := encodedbytes.EncodingNullLengthForIndex(i)
|
||||
oldNullLength := encodedbytes.EncodingNullLengthForIndex(f.encoding)
|
||||
nullDiff := newNullLength - oldNullLength
|
||||
|
||||
textDiff, err := encodedbytes.EncodedDiff(i, f.description, f.encoding, f.description)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f.changeSize(descDiff + textDiff)
|
||||
f.changeSize(descDiff + nullDiff + textDiff)
|
||||
f.encoding = i
|
||||
return nil
|
||||
}
|
||||
|
@ -399,9 +404,6 @@ func NewUnsynchTextFrame(ft FrameType, desc, text string) *UnsynchTextFrame {
|
|||
f := NewDescTextFrame(ft, desc, text)
|
||||
f.size += uint32(3)
|
||||
|
||||
// add null length for this encoding
|
||||
f.size += uint32(encodedbytes.EncodingNullLengthForIndex(f.encoding))
|
||||
|
||||
return &UnsynchTextFrame{
|
||||
DescTextFrame: *f,
|
||||
language: "eng",
|
||||
|
@ -447,19 +449,6 @@ func (f *UnsynchTextFrame) SetLanguage(language string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (f *UnsynchTextFrame) SetEncoding(encoding string) error {
|
||||
prevIndex := f.encoding
|
||||
err := f.DescTextFrame.SetEncoding(encoding)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n1 := encodedbytes.EncodingNullLengthForIndex(prevIndex)
|
||||
n2 := encodedbytes.EncodingNullLengthForIndex(f.encoding)
|
||||
f.changeSize(n2 - n1)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f UnsynchTextFrame) String() string {
|
||||
return fmt.Sprintf("%s\t%s:\n%s", f.language, f.description, f.text)
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue