Module: AudioRating::ID3v2

Defined in:
lib/audio_rating/id3v2.rb

Overview

Base class for ID3v2 tags, used by AIFF, MP3 and WAV files.

Class Method Summary collapse

Class Method Details

.get(tag) ⇒ Integer, ...

Get an ID3v2 tag’s star-rating metadata if present.

Uses taglib-ruby class: rubydoc.info/gems/taglib-ruby/TagLib/ID3v2/PopularimeterFrame

Parameters:

  • tag (TagLib::ID3v2::Tag)

    the ID3v2 tag

Returns:

  • (Integer)

    the star-rating of 1, 2, 3, 4 or 5

  • (Float)

    the star-rating of 0.5, 1.5, 2.5, 3.5 or 4.5

  • (nil)

    if file not found, or file has no star-rating metadata



16
17
18
19
20
21
22
23
24
25
# File 'lib/audio_rating/id3v2.rb', line 16

def self.get(tag)
  popm_frames = tag.frame_list 'POPM'
  return if popm_frames.empty?

  popm_frames.each do |frame|
    star_rating = POPM_VALUE_TO_STAR_RATING[frame.rating]
    star_rating ||= RATE_VALUE_TO_STAR_RATING[frame.rating]
    return star_rating if star_rating
  end
end