Class: Flacky::MetadataGenerator
- Inherits:
-
Object
- Object
- Flacky::MetadataGenerator
- Defined in:
- lib/flacky/metadata_generator.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#file_metadata ⇒ Object
readonly
Returns the value of attribute file_metadata.
-
#metadata_file ⇒ Object
readonly
Returns the value of attribute metadata_file.
Instance Method Summary collapse
- #combined_data ⇒ Object
- #flac_metadata ⇒ Object
-
#initialize(metadata_file) ⇒ MetadataGenerator
constructor
A new instance of MetadataGenerator.
- #scraped_metadata ⇒ Object
Constructor Details
#initialize(metadata_file) ⇒ MetadataGenerator
Returns a new instance of MetadataGenerator.
13 14 15 16 17 |
# File 'lib/flacky/metadata_generator.rb', line 13 def initialize() @metadata_file = @dir = File.dirname(@metadata_file) @file_metadata = end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
11 12 13 |
# File 'lib/flacky/metadata_generator.rb', line 11 def dir @dir end |
#file_metadata ⇒ Object (readonly)
Returns the value of attribute file_metadata.
11 12 13 |
# File 'lib/flacky/metadata_generator.rb', line 11 def @file_metadata end |
#metadata_file ⇒ Object (readonly)
Returns the value of attribute metadata_file.
11 12 13 |
# File 'lib/flacky/metadata_generator.rb', line 11 def @metadata_file end |
Instance Method Details
#combined_data ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/flacky/metadata_generator.rb', line 51 def combined_data result = { "allmusic_url" => "" } result["flac"] = (result["flac"] || Hash.new).merge() result = result.deep_merge() result["flac"] = result["flac"].merge() result end |
#flac_metadata ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/flacky/metadata_generator.rb', line 19 def flacs = Dir.glob(File.join(dir.shellescape, '*.flac')) return Hash.new if flacs.empty? result = Hash.new result["totaltracks"] = [] flacs.each do |flac| md = (flac) track_total = (md["totaltracks"] || -1).to_i disc_number = (md["discnumber"] || -1).to_i next if track_total < 0 || disc_number < 0 next if result["totaltracks"][disc_number - 1] result["totaltracks"][disc_number - 1] = track_total .each { |t| result[t] = md[t] if md[t] } end result["year"] = result.delete("date") if result["date"] result end |