Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion picture_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package id3v2

import (
"fmt"
"io"
)

Expand All @@ -22,7 +23,7 @@ type PictureFrame struct {
}

func (pf PictureFrame) UniqueIdentifier() string {
return pf.Description
return fmt.Sprintf("%02X%s", pf.PictureType, pf.Description)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea to use 2 bytes for picture type in unique identifier 👍

}

func (pf PictureFrame) Size() int {
Expand Down
51 changes: 37 additions & 14 deletions sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ func TestSequenceCommentFramesUniqueness(t *testing.T) {
defer putSequence(s)

s.AddFrame(CommentFrame{Language: "A", Description: "A"})
testSequenceA(t, s)
testSequenceCount(t, s, 1)
testFrameUniqueIdentifier(t, s.Frames()[0], "AA")

s.AddFrame(CommentFrame{Language: "B", Description: "B"})
testSequenceAB(t, s)
testSequenceCount(t, s, 2)
testFrameUniqueIdentifier(t, s.Frames()[0], "AA")
testFrameUniqueIdentifier(t, s.Frames()[1], "BB")

s.AddFrame(CommentFrame{Language: "B", Description: "B"})
testSequenceAB(t, s)
testSequenceCount(t, s, 2)
testFrameUniqueIdentifier(t, s.Frames()[0], "AA")
testFrameUniqueIdentifier(t, s.Frames()[1], "BB")
}

func TestSequencePictureFramesUniqueness(t *testing.T) {
Expand All @@ -28,14 +33,27 @@ func TestSequencePictureFramesUniqueness(t *testing.T) {
s := getSequence()
defer putSequence(s)

s.AddFrame(PictureFrame{Description: "A"})
testSequenceA(t, s)

s.AddFrame(PictureFrame{Description: "B"})
testSequenceAB(t, s)
s.AddFrame(PictureFrame{Description: "A", PictureType: 0x00})
testSequenceCount(t, s, 1)
testFrameUniqueIdentifier(t, s.Frames()[0], "00A")

s.AddFrame(PictureFrame{Description: "B"})
testSequenceAB(t, s)
// Test against https://github.com/bogem/id3v2/issues/65 regression.
s.AddFrame(PictureFrame{Description: "A", PictureType: 0x01})
testSequenceCount(t, s, 2)
testFrameUniqueIdentifier(t, s.Frames()[0], "00A")
testFrameUniqueIdentifier(t, s.Frames()[1], "01A")

s.AddFrame(PictureFrame{Description: "B", PictureType: 0x00})
testSequenceCount(t, s, 3)
testFrameUniqueIdentifier(t, s.Frames()[0], "00A")
testFrameUniqueIdentifier(t, s.Frames()[1], "01A")
testFrameUniqueIdentifier(t, s.Frames()[2], "00B")

s.AddFrame(PictureFrame{Description: "B", PictureType: 0x00})
testSequenceCount(t, s, 3)
testFrameUniqueIdentifier(t, s.Frames()[0], "00A")
testFrameUniqueIdentifier(t, s.Frames()[1], "01A")
testFrameUniqueIdentifier(t, s.Frames()[2], "00B")
}

func TestSequenceUSLFsUniqueness(t *testing.T) {
Expand All @@ -45,13 +63,18 @@ func TestSequenceUSLFsUniqueness(t *testing.T) {
defer putSequence(s)

s.AddFrame(UnsynchronisedLyricsFrame{Language: "A", ContentDescriptor: "A"})
testSequenceA(t, s)
testSequenceCount(t, s, 1)
testFrameUniqueIdentifier(t, s.Frames()[0], "AA")

s.AddFrame(UnsynchronisedLyricsFrame{Language: "B", ContentDescriptor: "B"})
testSequenceAB(t, s)
testSequenceCount(t, s, 2)
testFrameUniqueIdentifier(t, s.Frames()[0], "AA")
testFrameUniqueIdentifier(t, s.Frames()[1], "BB")

s.AddFrame(UnsynchronisedLyricsFrame{Language: "B", ContentDescriptor: "B"})
testSequenceAB(t, s)
testSequenceCount(t, s, 2)
testFrameUniqueIdentifier(t, s.Frames()[0], "AA")
testFrameUniqueIdentifier(t, s.Frames()[1], "BB")
}

func TestSequenceUDTFsUniqueness(t *testing.T) {
Expand Down Expand Up @@ -96,7 +119,7 @@ func testSequenceCount(t *testing.T, s *sequence, expected int) {
}

func testFrameUniqueIdentifier(t *testing.T, f Framer, expected string) {
got := f.UniqueIdentifier()[:1]
got := f.UniqueIdentifier()
if got != expected {
t.Errorf("Expected frame with unique identifier %v, got %v", expected, got)
}
Expand Down