Class: WahWah::ID3::Frame

Inherits:
Object
  • Object
show all
Includes:
LazyRead
Defined in:
lib/wahwah/id3/frame.rb

Constant Summary collapse

ID_MAPPING =
{
  # ID3v2.2 frame id
  COM: :comment,
  TRK: :track,
  TYE: :year,
  TAL: :album,
  TP1: :artist,
  TT2: :title,
  TCO: :genre,
  TPA: :disc,
  TP2: :albumartist,
  TCM: :composer,
  PIC: :image,
  ULT: :lyrics,

  # ID3v2.3 and ID3v2.4 frame id
  COMM: :comment,
  TRCK: :track,
  TYER: :year,
  TALB: :album,
  TPE1: :artist,
  TIT2: :title,
  TCON: :genre,
  TPOS: :disc,
  TPE2: :albumartist,
  TCOM: :composer,
  APIC: :image,
  USLT: :lyrics,

  # ID3v2.4 use TDRC replace TYER
  TDRC: :year
}
V3_HEADER_FLAGS_INDICATIONS =

ID3v2.3 frame flags field is defined as follows.

%abc00000 %ijk00000

a - Tag alter preservation b - File alter preservation c - Read only i - Compression j - Encryption k - Grouping identity

Array.new(16).tap do |array|
  array[0] = :tag_alter_preservation
  array[1] = :file_alter_preservation
  array[2] = :read_only
  array[8] = :compression
  array[9] = :encryption
  array[10] = :grouping_identity
end
V4_HEADER_FLAGS_INDICATIONS =

ID3v2.4 frame flags field is defined as follows.

%0abc0000 %0h00kmnp

a - Tag alter preservation b - File alter preservation c - Read only h - Grouping identity k - Compression m - Encryption n - Unsynchronisation p - Data length indicator

Array.new(16).tap do |array|
  array[1] = :tag_alter_preservation
  array[2] = :file_alter_preservation
  array[3] = :read_only
  array[9] = :grouping_identity
  array[12] = :compression
  array[13] = :encryption
  array[14] = :unsynchronisation
  array[15] = :data_length_indicator
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LazyRead

#data, prepended, #skip

Constructor Details

#initialize(version) ⇒ Frame

Returns a new instance of Frame.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/wahwah/id3/frame.rb', line 85

def initialize(version)
  @version = version

  parse_frame_header

  # In ID3v2.3 when frame is compressed using zlib
  # with 4 bytes for 'decompressed size' appended to the frame header.
  #
  # In ID3v2.4 A 'Data Length Indicator' byte MUST be included in the frame
  # when frame is compressed, and 'Data Length Indicator'represented as a 32 bit
  # synchsafe integer
  #
  # So skip those 4 byte.
  if compressed? || data_length_indicator?
    @file_io.seek(4, IO::SEEK_CUR)
    @size -= 4
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



83
84
85
# File 'lib/wahwah/id3/frame.rb', line 83

def name
  @name
end

Instance Method Details

#compressed?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/wahwah/id3/frame.rb', line 108

def compressed?
  @flags.include? :compression
end

#data_length_indicator?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/wahwah/id3/frame.rb', line 112

def data_length_indicator?
  @flags.include? :data_length_indicator
end

#valid?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/wahwah/id3/frame.rb', line 104

def valid?
  @size > 0 && !@name.nil?
end

#valueObject



116
117
118
119
120
121
122
# File 'lib/wahwah/id3/frame.rb', line 116

def value
  return unless @size > 0

  content = compressed? ? Zlib.inflate(data) : data
  frame_body = frame_body_class.new(content, @version)
  frame_body.value
end