class ID3::Frame
This class models ID3-Frames independent of
the D3-version, e.g. 2.2.0, 2.3.0, 2.4.0 This module
tries to hide all the ugly details about the Frame-internals and how to
parse each Frame-type for each ID3-version.
The user doesn't need to use any of the methods provided by this
module, but s/he can access the Instance Variables to examine each
Frame.
Each Frame is organized as a "ordered Hash" , to preserve the order of it's fields, as they are defined by the ID3-standard
Because the names of the ID3-Frames vary between the ID3-versions, we are using a symbolic name to reference the Frame, not it's real (short) name.
Provided Functionality:
- Reads and parses a frame upon initialization
- Dumps a frame raw into a string
- Low-level interface to ID3-Frames
- Not all Frame-types are fully parsed, but can be accessed/copied/dumped as raw
Instance Variables:
- name
- version
- raw
- rawdata
- rawheader
- rawflags # if version is larger than 2.2.x
- flags
# Hash with the parsed flags, if version > 2.2.x
- headerStartX
- dataStartX
Instance Methods:
- initialize
# does all the hard work.. parses the Frame, defines parse/dump-methods
- parse
# defined during run-time, depending on the particular Frame-Type
- dump
# defined during run-time, depending on the particular Frame-Type
Examples:
> require 'id3'
=> true
# here we're just creating an ID3::Tag2 object and read-in an mp3-file
> t = ID3::Tag2.new
=> {}
> t.read("mp3/b.mp3")
=> true
> t.version
=> "2.2.0"
> t.keys
=> ["ARTIST", "SONGLEN", "CONTENTTYPE", "ALBUM", "ENCODEDBY", "TRACKNUM", "TITLE", "YEAR", "PICTURE", "MEDIATYPE", "COMMENT"]
# NOW let's look at the internals of a Frame:
> t['ARTIST']
=> {"encoding"=>0, "text"=>"Juno reactor"}
> t['ARTIST'].keys
=> ["encoding", "text"]
> t['ARTIST'].order
=> ["encoding", "text"]
# PLEASE NOTE that the author does not have expertise with other than western character encodings..
# I'd like to hear some input how this can be implemented better.. and if/how Ruby can detect
# the character encoding of a string which was provided by the user
> t['ARTIST']['text'] = "Juno Reactor"
=> "Juno Reactor"
> t['ARTIST'].raw
=> "TP1\000\000\016\000Juno reactor\000"
> t['ARTIST'].rawheader
=> "TP1\000\000\016"
> t['ARTIST'].rawdata
=> "\000Juno reactor\000"
# a lot of the really useful Frame types are text frames..
> t['CONTENTTYPE']
=> {"encoding"=>0, "text"=>"Electronica/Dance"}
> t['YEAR']
=> {"encoding"=>0, "text"=>"1997"}
> t['SONGLEN']
=> {"encoding"=>0, "text"=>"258847"}