Module: AudioRating::M4A
- Defined in:
- lib/audio_rating/m4a.rb
Overview
Base class for M4A files.
Class Method Summary collapse
-
.get(path) ⇒ Integer, ...
Get an M4A file’s embedded star-rating metadata if present.
-
.get_item_value(item) ⇒ Integer
private
Gets the value from an MP4 Item.
-
.get_itunes_rating_item(item_map) ⇒ TagLib::MP4::Item?
private
Gets the iTunes rating MP4 Item from an MP4 ItemMap, if present.
Class Method Details
.get(path) ⇒ Integer, ...
Get an M4A file’s embedded star-rating metadata if present.
Uses taglib-ruby class: rubydoc.info/gems/taglib-ruby/TagLib/MP4/File
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/audio_rating/m4a.rb', line 16 def self.get(path) TagLib::MP4::File.open(path) do |file| next unless file&.valid? && file&.mp4_tag? items = file.tag.item_map if items.contains 'rate' # MusicBee & MediaMonkey sets this rate_value = get_item_value(items.fetch('rate')) return RATE_VALUE_TO_STAR_RATING[rate_value] end itunes_item = (items) get_item_value(itunes_item) if itunes_item end end |
.get_item_value(item) ⇒ Integer (private)
Gets the value from an MP4 Item.
Uses taglib-ruby class: rubydoc.info/gems/taglib-ruby/TagLib/MP4/Item
39 40 41 |
# File 'lib/audio_rating/m4a.rb', line 39 def self.get_item_value(item) item.to_string_list.first.to_i end |
.get_itunes_rating_item(item_map) ⇒ TagLib::MP4::Item? (private)
Gets the iTunes rating MP4 Item from an MP4 ItemMap, if present.
Uses taglib-ruby class: rubydoc.info/gems/taglib-ruby/TagLib/MP4/ItemMap
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/audio_rating/m4a.rb', line 53 def self.(item_map) key_a = '----:com.apple.iTunes:Rating' # foobar2000 sets this return item_map.fetch(key_a) if item_map.contains key_a key_b = '----:com.apple.iTunes:rating' # Unsure of source return item_map.fetch(key_b) if item_map.contains key_b key_c = '----:com.apple.iTunes:RATING' # Unsure of source item_map.fetch(key_c) if item_map.contains key_c end |