func TestInitialiseFromHeaderBlockWithValidHeaders(t *testing.T) { buf, reader := bufWrap(id3v2_header) buf[3] = 2 buf[4] = 0 tag, err := id3v2.ExtractTag(reader) if err != nil { t.Error(err) return } assert(t, tag.Version() == "2.0", "expected version 2.0, got", tag.Version()) buf[3] = 3 tag, err = id3v2.ExtractTag(reader) if err != nil { t.Error(err) return } assert(t, tag.Version() == "3.0", "expected version 3.0, got", tag.Version()) buf[3] = 4 tag, err = id3v2.ExtractTag(reader) if err != nil { t.Error(err) return } assert(t, tag.Version() == "4.0", "expected version 4.0, got", tag.Version()) }
func TestNonSupportedVersionInId3v2HeaderBlock(t *testing.T) { buf, reader := bufWrap(id3v2_header) buf[3] = 5 buf[4] = 0 _, err := id3v2.ExtractTag(reader) assert(t, err != nil, "expected error (wrong ID3v2 version), got nil") }
// FIXME: use some minimal interface instead of os.File in the argument // TODO: verify if errors handling (and ignoring) is ok func ParseFile(raw *os.File, bufferLength int) (*File, os.Error) { if bufferLength == 0 { bufferLength = DEFAULT_BUFFER_LENGTH } mp3file := &File{ startOffset: -1, endOffset: -1, xingOffset: -1, bitrates: make(map[int]int)} mp3file.calcLength(raw) // TODO: try to move all Seek()s into this function mp3file.id3v1tag, _ = ExtractId3v1Tag(raw) offset := int64(0) id3v2tagHeader, _ := id3v2.ExtractTagHeader(raw) if id3v2tagHeader != nil { offset = int64(len(id3v2tagHeader)) + int64(id3v2tagHeader.DataLength()) } err := mp3file.scanFile(raw, offset, bufferLength) if err != nil { return nil, err } if mp3file.startOffset < 0 { return nil, os.NewError("No mpegs frames found") } mp3file.id3v2tag, _ = id3v2.ExtractTag(raw) mp3file.extractCustomTag(raw) return mp3file, nil }
func TestCalculateCorrectDataLengthsFromHeaderBlock(t *testing.T) { buf, reader := bufWrap(id3v2_header) tag, err := id3v2.ExtractTag(reader) if err != nil { t.Error(err) return } assert(t, tag.DataLength() == 257, "data length expected 257, got", tag.DataLength()) buf[8] = 0x09 buf[9] = 0x41 tag, err = id3v2.ExtractTag(reader) if err != nil { t.Error(err) return } assert(t, tag.DataLength() == 1217, "data length expected 1217, got", tag.DataLength()) }
func loadId3TagFile(fname string) (*id3v2.Tag, os.Error) { f, err := os.Open(RES_DIR+fname, os.O_RDONLY, 0) if err != nil { return nil, err } defer f.Close() tag, err := id3v2.ExtractTag(f) if err != nil { return nil, err } return tag, nil }