|
|
@ -72,8 +72,7 @@ func (h *Header) readExtendedHeader(r io.Reader) error { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return fmt.Errorf("could not read from reader: %s", err) |
|
|
|
return fmt.Errorf("could not read from reader: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
flagbits := fmt.Sprintf("%08b", extendedFlag[0]) |
|
|
|
if util.GetBit(extendedFlag[0], 1) { |
|
|
|
if flagbits[0] == 1 { |
|
|
|
|
|
|
|
extended.Flags.CRCpresent = true |
|
|
|
extended.Flags.CRCpresent = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
extended.Flags.CRCpresent = false |
|
|
|
extended.Flags.CRCpresent = false |
|
|
@ -90,20 +89,19 @@ func (h *Header) readExtendedHeader(r io.Reader) error { |
|
|
|
return fmt.Errorf("could not read from reader: %s", err) |
|
|
|
return fmt.Errorf("could not read from reader: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
flagBits := fmt.Sprintf("%08b", flagByte[0]) |
|
|
|
if util.GetBit(flagByte[0], 2) { |
|
|
|
if flagBits[1] == 1 { |
|
|
|
|
|
|
|
extended.Flags.UpdateTag = true |
|
|
|
extended.Flags.UpdateTag = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
extended.Flags.UpdateTag = false |
|
|
|
extended.Flags.UpdateTag = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if flagBits[2] == 1 { |
|
|
|
if util.GetBit(flagByte[0], 3) { |
|
|
|
extended.Flags.CRCpresent = true |
|
|
|
extended.Flags.CRCpresent = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
extended.Flags.CRCpresent = false |
|
|
|
extended.Flags.CRCpresent = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if flagBits[3] == 1 { |
|
|
|
if util.GetBit(flagByte[0], 4) { |
|
|
|
extended.Flags.HasRestrictions = true |
|
|
|
extended.Flags.HasRestrictions = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
extended.Flags.HasRestrictions = false |
|
|
|
extended.Flags.HasRestrictions = false |
|
|
@ -195,7 +193,7 @@ func readHeader(rs io.ReadSeeker) (Header, error) { |
|
|
|
|
|
|
|
|
|
|
|
identifier := hBytes[0:3] |
|
|
|
identifier := hBytes[0:3] |
|
|
|
|
|
|
|
|
|
|
|
// check if has identifier ID3v2
|
|
|
|
// check if has ID3v2 identifier
|
|
|
|
if !bytes.Equal([]byte(HEADERIDENTIFIER), identifier) { |
|
|
|
if !bytes.Equal([]byte(HEADERIDENTIFIER), identifier) { |
|
|
|
return Header{}, ErrDoesNotUseID3v2 |
|
|
|
return Header{}, ErrDoesNotUseID3v2 |
|
|
|
} |
|
|
|
} |
|
|
@ -219,33 +217,31 @@ func readHeader(rs io.ReadSeeker) (Header, error) { |
|
|
|
// flags
|
|
|
|
// flags
|
|
|
|
flags := hBytes[5] |
|
|
|
flags := hBytes[5] |
|
|
|
|
|
|
|
|
|
|
|
flagBits := fmt.Sprintf("%08b", flags) // 1 byte is 8 bits
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v3.0 and v4.0 have different amount of flags
|
|
|
|
// v3.0 and v4.0 have different amount of flags
|
|
|
|
switch header.Version { |
|
|
|
switch header.Version { |
|
|
|
case V2_2: |
|
|
|
case V2_2: |
|
|
|
if flagBits[0] == 1 { |
|
|
|
if util.GetBit(flags, 1) { |
|
|
|
header.Flags.Unsynchronisated = true |
|
|
|
header.Flags.Unsynchronisated = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
header.Flags.Unsynchronisated = false |
|
|
|
header.Flags.Unsynchronisated = false |
|
|
|
} |
|
|
|
} |
|
|
|
if flagBits[1] == 1 { |
|
|
|
if util.GetBit(flags, 2) { |
|
|
|
header.Flags.Compressed = true |
|
|
|
header.Flags.Compressed = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
header.Flags.Compressed = false |
|
|
|
header.Flags.Compressed = false |
|
|
|
} |
|
|
|
} |
|
|
|
case V2_3: |
|
|
|
case V2_3: |
|
|
|
if flagBits[0] == 1 { |
|
|
|
if util.GetBit(flags, 1) { |
|
|
|
header.Flags.Unsynchronisated = true |
|
|
|
header.Flags.Unsynchronisated = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
header.Flags.Unsynchronisated = false |
|
|
|
header.Flags.Unsynchronisated = false |
|
|
|
} |
|
|
|
} |
|
|
|
if flagBits[1] == 1 { |
|
|
|
if util.GetBit(flags, 2) { |
|
|
|
header.Flags.HasExtendedHeader = true |
|
|
|
header.Flags.HasExtendedHeader = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
header.Flags.HasExtendedHeader = false |
|
|
|
header.Flags.HasExtendedHeader = false |
|
|
|
} |
|
|
|
} |
|
|
|
if flagBits[2] == 1 { |
|
|
|
if util.GetBit(flags, 3) { |
|
|
|
header.Flags.Experimental = true |
|
|
|
header.Flags.Experimental = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
header.Flags.Experimental = false |
|
|
|
header.Flags.Experimental = false |
|
|
@ -254,22 +250,22 @@ func readHeader(rs io.ReadSeeker) (Header, error) { |
|
|
|
header.Flags.FooterPresent = false |
|
|
|
header.Flags.FooterPresent = false |
|
|
|
|
|
|
|
|
|
|
|
case V2_4: |
|
|
|
case V2_4: |
|
|
|
if flagBits[0] == 1 { |
|
|
|
if util.GetBit(flags, 1) { |
|
|
|
header.Flags.Unsynchronisated = true |
|
|
|
header.Flags.Unsynchronisated = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
header.Flags.Unsynchronisated = false |
|
|
|
header.Flags.Unsynchronisated = false |
|
|
|
} |
|
|
|
} |
|
|
|
if flagBits[1] == 1 { |
|
|
|
if util.GetBit(flags, 2) { |
|
|
|
header.Flags.HasExtendedHeader = true |
|
|
|
header.Flags.HasExtendedHeader = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
header.Flags.HasExtendedHeader = false |
|
|
|
header.Flags.HasExtendedHeader = false |
|
|
|
} |
|
|
|
} |
|
|
|
if flagBits[2] == 1 { |
|
|
|
if util.GetBit(flags, 3) { |
|
|
|
header.Flags.Experimental = true |
|
|
|
header.Flags.Experimental = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
header.Flags.Experimental = false |
|
|
|
header.Flags.Experimental = false |
|
|
|
} |
|
|
|
} |
|
|
|
if flagBits[3] == 1 { |
|
|
|
if util.GetBit(flags, 4) { |
|
|
|
header.Flags.FooterPresent = true |
|
|
|
header.Flags.FooterPresent = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
header.Flags.FooterPresent = false |
|
|
|
header.Flags.FooterPresent = false |
|
|
|