Class Mp3Info
In: lib/mp3info/extension_modules.rb
lib/mp3info.rb
Parent: Object

coding:utf-8

License:Ruby
Author:Guillaume Pierronnet (moumar_AT__rubyforge_DOT_org)
Website:ruby-mp3info.rubyforge.org/

Methods

Constants

VERSION = "0.6.16"
LAYER = [ nil, 3, 2, 1]
BITRATE = { 1 => [ [32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448], [32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384], [32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320] ], 2 => [ [32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256], [8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160], [8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160]
SAMPLERATE = { 1 => [ 44100, 48000, 32000 ], 2 => [ 22050, 24000, 16000 ], 2.5 => [ 11025, 12000, 8000 ]
CHANNEL_MODE = [ "Stereo", "JStereo", "Dual Channel", "Single Channel"]
GENRES = [ "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta", "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American", "Cabaret", "New Wave", "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock", "Folk", "Folk/Rock", "National Folk", "Swing", "Fast-Fusion", "Bebob", "Latin", "Revival", "Celtic", "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus", "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba", "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle", "Duet", "Punk Rock", "Drum Solo", "A capella", "Euro-House", "Dance Hall", "Goa", "Drum & Bass", "Club House", "Hardcore", "Terror", "Indie", "BritPop", "NegerPunk", "Polsk Punk", "Beat", "Christian Gangsta", "Heavy Metal", "Black Metal", "Crossover", "Contemporary C", "Christian Rock", "Merengue", "Salsa", "Thrash Metal", "Anime", "JPop", "SynthPop" ]
TAG1_SIZE = 128
TAG_MAPPING_2_2 = { "title" => "TT2", "artist" => "TP1", "album" => "TAL", "year" => "TYE", "tracknum" => "TRK", "comments" => "COM", "genre_s" => "TCO"   map to fill the "universal" tag (tag attribute) for id3v2.2
TAG_MAPPING_2_3 = { "title" => "TIT2", "artist" => "TPE1", "album" => "TALB", "year" => "TYER", "tracknum" => "TRCK", "comments" => "COMM", "genre_s" => "TCON"   for id3v2.3 and 2.4
SAMPLES_PER_FRAME = [ nil, {1=>384, 2=>384, 2.5=>384}, # Layer I {1=>1152, 2=>1152, 2.5=>1152}, # Layer II {1=>1152, 2=>576, 2.5=>576}   www.codeproject.com/audio/MPEGAudioInfo.asp

Attributes

bitrate  [R]  bitrate in kbps
channel_mode  [R]  channel mode => "Stereo", "JStereo", "Dual Channel" or "Single Channel"
error_protection  [R]  error protection => true or false
filename  [R]  the original filename unless used with a StringIO
header  [R]  Hash representing values in the MP3 frame header. Keys are one of the following:
  • :private (boolean)
  • :copyright (boolean)
  • :original (boolean)
  • :padding (boolean)
  • :error_protection (boolean)
  • :mode_extension (integer in the 0..3 range)
  • :emphasis (integer in the 0..3 range)

detailled explanation can be found here: www.mp3-tech.org/programmer/frame_header.html

layer  [R]  layer = 1, 2, or 3
length  [R]  length in seconds as a Float
mpeg_version  [R]  mpeg version = 1 or 2
samplerate  [R]  samplerate in Hz
tag  [R]  a sort of "universal" tag, regardless of the tag version, 1 or 2, with the same keys as @tag1 this tag has priority over @tag1 and @tag2 when writing the tag with close
tag1  [RW]  id3v1 tag as a Hash. You can modify it, it will be written when calling "close" method.
tag2  [RW]  id3v2 tag attribute as an ID3v2 object. You can modify it, it will be written when calling "close" method.
vbr  [R]  variable bitrate => true or false

Public Class methods

Test the presence of an id3v1 tag in file or StringIO filename_or_io

Test the presence of an id3v2 tag in file or StringIO filename_or_io

Instantiate Mp3Info object with name filename. options hash is used for ID3v2#new. Specify :parse_tags => false to disable the processing of the tags (read and write). Specify :parse_mp3 => false to disable processing of the mp3

"block version" of Mp3Info::new()

Remove id3v1 tag from filename

Remove id3v2 tag from filename

Public Instance methods

this method returns the "audio-only" data boundaries of the file, i.e. content stripped form tags. Useful to compare 2 files with the same audio content but with differents tags. Returned value is an array [position_in_the_file, length_of_the_data]

Flush pending modifications to tags and close the file not used when source IO is a StringIO

iterates over each mpeg frame over the file, allowing you to write some funny things, like an mpeg lossless cutter, or frame counter, or whatever you like ;) frame is a hash with the following keys: :layer, :bitrate, :samplerate, :mpeg_version, :padding and :size (in bytes)

close and reopen the file, i.e. commit changes to disk and reload it (only works with "true" files, not StringIO ones)

return the length in seconds of one frame

Does the file has an id3v1 tag?

Does the file has an id3v2 tag?

Does the file has an id3v1 or v2 tag?

reload (or load for the first time) the file from disk

Remove id3v1 from mp3

Remove id3v2 from mp3

write to another filename at close()

inspect inside Mp3Info

[Validate]