kopia lustrzana https://github.com/jcs/id3-go
Merge branch 'develop'
commit
1e647678c4
|
@ -0,0 +1,7 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.0
|
||||
- 1.1
|
||||
- 1.2
|
||||
- 1.3
|
||||
- tip
|
|
@ -137,16 +137,16 @@ func nullIndex(data []byte, encoding byte) (atIndex, afterIndex int) {
|
|||
return
|
||||
}
|
||||
|
||||
func EncodedDiff(ea byte, a string, eb byte, b string) (int, error) {
|
||||
encodedStringA, err := Encoders[ea].ConvertString(a)
|
||||
func EncodedDiff(newEncoding byte, newString string, oldEncoding byte, oldString string) (int, error) {
|
||||
newEncodedString, err := Encoders[newEncoding].ConvertString(newString)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
encodedStringB, err := Encoders[eb].ConvertString(b)
|
||||
oldEncodedString, err := Encoders[oldEncoding].ConvertString(oldString)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return len(encodedStringA) - len(encodedStringB), nil
|
||||
return len(newEncodedString) - len(oldEncodedString), nil
|
||||
}
|
||||
|
|
33
v2/frame.go
33
v2/frame.go
|
@ -247,7 +247,7 @@ func (f *TextFrame) SetEncoding(encoding string) error {
|
|||
return errors.New("encoding: invalid encoding")
|
||||
}
|
||||
|
||||
diff, err := encodedbytes.EncodedDiff(f.encoding, f.text, i, f.text)
|
||||
diff, err := encodedbytes.EncodedDiff(i, f.text, f.encoding, f.text)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -350,17 +351,21 @@ func (f *DescTextFrame) SetEncoding(encoding string) error {
|
|||
return errors.New("encoding: invalid encoding")
|
||||
}
|
||||
|
||||
descDiff, err := encodedbytes.EncodedDiff(f.encoding, f.text, i, f.text)
|
||||
descDiff, err := encodedbytes.EncodedDiff(i, f.text, f.encoding, f.text)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
textDiff, err := encodedbytes.EncodedDiff(f.encoding, f.description, i, f.description)
|
||||
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)
|
||||
}
|
||||
|
@ -536,7 +525,7 @@ func (f *ImageFrame) SetEncoding(encoding string) error {
|
|||
return errors.New("encoding: invalid encoding")
|
||||
}
|
||||
|
||||
diff, err := encodedbytes.EncodedDiff(f.encoding, f.description, i, f.description)
|
||||
diff, err := encodedbytes.EncodedDiff(i, f.description, f.encoding, f.description)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -4,26 +4,27 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestUnsynchTextFrame_SetEncoding(t *testing.T) {
|
||||
f := NewUnsychTextFrame(V23CommonFrame["Comments"], "Foo", "Bar")
|
||||
func TestUnsynchTextFrameSetEncoding(t *testing.T) {
|
||||
f := NewUnsynchTextFrame(V23CommonFrame["Comments"], "Foo", "Bar")
|
||||
size := f.Size()
|
||||
expectedDiff := 11
|
||||
|
||||
err := f.SetEncoding("UTF-16")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newSize := f.Size()
|
||||
if newSize-size != 1 {
|
||||
if int(newSize-size) != expectedDiff {
|
||||
t.Errorf("expected size to increase to %d, but it was %d", size+1, newSize)
|
||||
}
|
||||
|
||||
size = newSize
|
||||
err := f.SetEncoding("UTF-16")
|
||||
err = f.SetEncoding("ISO-8859-1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newSize := f.Size()
|
||||
if newSize-size != -1 {
|
||||
newSize = f.Size()
|
||||
if int(newSize-size) != -expectedDiff {
|
||||
t.Errorf("expected size to decrease to %d, but it was %d", size-1, newSize)
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue