TagFile
TagFile is a simple Class for building objects from binary audio files. It currently supports .flac, .mp3, & .ogg file formats. Using the ultra-fast TagLib2, TagFile extracts embedded metadata and builds a hash from user-defined values. This hash can be easily serialized and persisted in a database or document store.
Example usage
class Track < TagFile::Document
extract_tag_for :artist, :album
end
track = Track.new('valid_file.flac')
track.tags => {artist: 'artist', album: 'album'}
In order to build '#tags' you must specify which tags to use. The following tags can be extracted:
Embedded tags (from TagLib2)
- album
- artist
- genre
- title
- track
- year
Custom tags (from TagFile)
class Track < TagFile::Document
extract_tag_for :artist
# extract_tag_for :artist, :path, :title
# extract_tag_for :all
# extract_tag_for :all, except: [:artist, :album]
end
Verifications
TagFile includes several user-specified verifications. While path and format have built-in verifications, format can be customized to verify a subset of formats. Note: all valid TagFile objects will have a filename, length, path, and format attribute by default.
class Track < TagFile::Document
extract_tag_for :artist
verify_tag_for :artist
end
class Track < TagFile::Document
extract_tags_for :all
verify_tag_for :artist, :album
# verify_tag_for :all
# verify_tag_for :all, except: [:artist, :genre]
# verify_format_is :flac, :mp3
end
Errors
With custom verifications in place, all errors are written to '#errors'.
class Track < TagFile::Document
extract_tag_for :artist
verify_tag_for :artist
verify_format_is :mp3
end
track = Track.new('missing_artist.flac')
track.errors => ["Missing artist tag: missing_artist.flac", "File not of format :mp3: missing_artist.flac"]