class WahWah::ID3::V1
Constants
- DEFAULT_ENCODING
- GENRES
- TAG_ID
- TAG_SIZE
Public Instance Methods
size()
click to toggle source
# File lib/wahwah/id3/v1.rb, line 47 def size TAG_SIZE end
valid?()
click to toggle source
# File lib/wahwah/id3/v1.rb, line 55 def valid? @id == TAG_ID end
version()
click to toggle source
# File lib/wahwah/id3/v1.rb, line 51 def version 'v1' end
Private Instance Methods
parse()
click to toggle source
For ID3v1 info, see here en.wikipedia.org/wiki/ID3#ID3v1
header 3 “TAG” title 30 30 characters of the title artist 30 30 characters of the artist name album 30 30 characters of the album name year 4 A four-digit year comment 28 or 30 The comment. zero-byte 1 If a track number is stored, this byte contains a binary 0. track 1 The number of the track on the album, or 0. Invalid, if previous byte is not a binary 0. genre 1 Index in a list of genres, or 255
# File lib/wahwah/id3/v1.rb, line 71 def parse return unless @file_io.size >= TAG_SIZE @file_io.seek(-TAG_SIZE, IO::SEEK_END) @id = Helper.encode_to_utf8(@file_io.read(3), source_encoding: DEFAULT_ENCODING) return unless valid? @title = Helper.encode_to_utf8(@file_io.read(30), source_encoding: DEFAULT_ENCODING) @artist = Helper.encode_to_utf8(@file_io.read(30), source_encoding: DEFAULT_ENCODING) @album = Helper.encode_to_utf8(@file_io.read(30), source_encoding: DEFAULT_ENCODING) @year = Helper.encode_to_utf8(@file_io.read(4), source_encoding: DEFAULT_ENCODING) comment = @file_io.read(30) if comment.getbyte(-2) == 0 @track = comment.getbyte(-1) comment = comment.byteslice(0..-3) end @comments.push(Helper.encode_to_utf8(comment, source_encoding: DEFAULT_ENCODING)) @genre = GENRES[@file_io.getbyte] || '' end