Class: Mp3file::ID3v2::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/mp3file/id3v2/header.rb

Defined Under Namespace

Classes: ID3v2HeaderFormat

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Header

Returns a new instance of Header.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/mp3file/id3v2/header.rb', line 26

def initialize(io)
  header = nil
  begin
    header = ID3v2HeaderFormat.read(io)
  rescue BinData::ValidityError => ve
    raise InvalidID3v2TagError, ve.message
  end

  @version = Version.new(header.vmaj, header.vmin)

  @unsynchronized = false
  @extended_header = false
  @compression = false
  @experimental = false
  @footer = false

  if @version >= ID3V2_2_0 && @version < ID3V2_3_0
    @unsynchronized = header.unsynchronized == 1
    # Bit 6 was redefined in v2.3.0+, and we picked the new name
    # for it above.
    @compression = header.extended_header == 1
    if header.experimental == 1 || header.footer == 1
      raise InvalidID3v2TagError, "Invalid flag set in ID3v2.2 header"
    end
  elsif @version >= ID3V2_3_0 && @version < ID3V2_4_0
    @unsynchronized = header.unsynchronized == 1
    @extended_header = header.extended_header == 1
    @experimental = header.experimental == 1
    if header.footer == 1
      raise InvalidID3v2TagError, "Invalid flag set in ID3v2.3 header"
    end
  elsif @version >= ID3V2_4_0 
    @unsynchronized = header.unsynchronized == 1
    @extended_header = header.extended_header == 1
    @experimental = header.experimental == 1
    @footer = header.footer == 1
  end

  @tag_size = BitPaddedInt.unpad_number(header.size_padded)
end

Instance Attribute Details

#compressionObject (readonly)

Returns the value of attribute compression.



3
4
5
# File 'lib/mp3file/id3v2/header.rb', line 3

def compression
  @compression
end

#experimentalObject (readonly)

Returns the value of attribute experimental.



3
4
5
# File 'lib/mp3file/id3v2/header.rb', line 3

def experimental
  @experimental
end

#extended_headerObject (readonly)

Returns the value of attribute extended_header.



3
4
5
# File 'lib/mp3file/id3v2/header.rb', line 3

def extended_header
  @extended_header
end

Returns the value of attribute footer.



3
4
5
# File 'lib/mp3file/id3v2/header.rb', line 3

def footer
  @footer
end

#tag_sizeObject (readonly)

Returns the value of attribute tag_size.



3
4
5
# File 'lib/mp3file/id3v2/header.rb', line 3

def tag_size
  @tag_size
end

#unsynchronizedObject (readonly)

Returns the value of attribute unsynchronized.



3
4
5
# File 'lib/mp3file/id3v2/header.rb', line 3

def unsynchronized
  @unsynchronized
end

#versionObject (readonly)

Returns the value of attribute version.



3
4
5
# File 'lib/mp3file/id3v2/header.rb', line 3

def version
  @version
end