Class: WahWah::ID3::ImageFrameBody

Inherits:
FrameBody
  • Object
show all
Defined in:
lib/wahwah/id3/image_frame_body.rb

Constant Summary collapse

TYPES =
%i[
  other
  file_icon
  other_file_icon
  cover_front
  cover_back
  leaflet
  media
  lead_artist
  artist
  conductor
  band
  composer
  lyricist
  recording_location
  during_recording
  during_performance
  movie_screen_capture
  bright_coloured_fish
  illustration
  band_logotype
  publisher_logotype
]

Constants inherited from FrameBody

FrameBody::ENCODING_MAPPING, FrameBody::ENCODING_TERMINATOR_SIZE

Instance Attribute Summary

Attributes inherited from FrameBody

#value

Instance Method Summary collapse

Methods inherited from FrameBody

#initialize

Constructor Details

This class inherits a constructor from WahWah::ID3::FrameBody

Instance Method Details

#mime_typeObject



30
31
32
33
# File 'lib/wahwah/id3/image_frame_body.rb', line 30

def mime_type
  mime_type = @mime_type.downcase.yield_self { |type| type == "jpg" ? "jpeg" : type }
  @version > 2 ? mime_type : "image/#{mime_type}"
end

#parseObject

ID3v2.2 image frame structure:

Text encoding $xx Image format $xx xx xx Picture type $xx Description <text string according to encoding> $00 (00) Picture data <binary data>

ID3v2.3 and ID3v2.4 image frame structure:

Text encoding $xx MIME type <text string> $00 Picture type $xx Description <text string according to encoding> $00 (00) Picture data <binary data>



50
51
52
53
54
55
56
57
# File 'lib/wahwah/id3/image_frame_body.rb', line 50

def parse
  frame_format = @version > 2 ? "CZ*Ca*" : "Ca3Ca*"
  encoding_id, @mime_type, type_index, rest_content = @content.unpack(frame_format)
  encoding = ENCODING_MAPPING[encoding_id]
  _description, data = Helper.split_with_terminator(rest_content, ENCODING_TERMINATOR_SIZE[encoding])

  @value = {data: data, mime_type: mime_type, type: TYPES[type_index]}
end