Class: Flacky::MetadataGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/flacky/metadata_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dirObject (readonly)

Returns the value of attribute dir.



11
12
13
# File 'lib/flacky/metadata_generator.rb', line 11

def dir
  @dir
end

#file_metadataObject (readonly)

Returns the value of attribute file_metadata.



11
12
13
# File 'lib/flacky/metadata_generator.rb', line 11

def 
  @file_metadata
end

#metadata_fileObject (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_dataObject



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_metadataObject



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

    common_tags.each { |t| result[t] = md[t] if md[t] }
  end
  result["year"] = result.delete("date") if result["date"]

  result
end

#scraped_metadataObject



43
44
45
46
47
48
49
# File 'lib/flacky/metadata_generator.rb', line 43

def 
  url = ["allmusic_url"]
  return Hash.new if !url || (url && url.empty?)

  scraper = Flacky::Scraper.new(url)
  { 'style' => scraper.styles.join(';'), 'mood' => scraper.moods.join(';') }
end