Module: AudioRating::Ogg

Defined in:
lib/audio_rating/ogg.rb

Overview

Base class for Ogg files.

Class Method Summary collapse

Class Method Details

.get(path) ⇒ Integer, ...

Get an Ogg file’s embedded star-rating metadata if present.

Uses taglib-ruby class: rubydoc.info/gems/taglib-ruby/TagLib/Ogg/Vorbis/File

Parameters:

  • path (String)

    the Ogg file path

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
26
27
28
29
# File 'lib/audio_rating/ogg.rb', line 16

def self.get(path)
  TagLib::Ogg::Vorbis::File.open(path) do |file|
    next unless file&.valid?

    fields = file.tag.field_list_map
    next unless fields.key? 'RATING'

    rating = fields['RATING'].first.to_i
    return rating if rating <= 5 # foobar2000 sets <= 5

    # MusicBee & MediaMonkey sets > 5
    RATE_VALUE_TO_STAR_RATING[rating] if rating > 5
  end
end