Class: Flacky::CLI
- Inherits:
-
Thor
- Object
- Thor
- Flacky::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/flacky/cli.rb
Instance Method Summary collapse
- #generate(root_dir = ENV['PWD']) ⇒ Object
- #missing_urls(root_dir = ENV['PWD']) ⇒ Object
- #to_mp3(*args) ⇒ Object
Instance Method Details
#generate(root_dir = ENV['PWD']) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/flacky/cli.rb', line 18 def generate(root_dir = ENV['PWD']) start_dir = File.join(File.(root_dir), '**/*.flac') Dir.glob(start_dir).map { |f| File.dirname(f) }.uniq.each do |dir| mdf = File.join(dir, "metadata.json") say("Processing <#{dir}>", :cyan) data = Flacky::MetadataGenerator.new(mdf).combined_data IO.write(mdf, JSON.pretty_generate(data)) end end |
#missing_urls(root_dir = ENV['PWD']) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/flacky/cli.rb', line 30 def missing_urls(root_dir = ENV['PWD']) start_dir = File.join(File.(root_dir), '**/metadata.json') files = [] Dir.glob(start_dir).each do |mdf| attr = JSON.parse(IO.read(mdf))["allmusic_url"] files << mdf if attr.nil? || attr.empty? end if [:print0] print files.join("\x0").concat("\x0") else puts files.join("\n") unless files.empty? end end |
#to_mp3(*args) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/flacky/cli.rb', line 52 def to_mp3(*args) %w{flac metaflac lame}.each do |cmd| abort "Command #{cmd} must be on your PATH" unless %x{which #{cmd}} end mp3izer = Flacky::Mp3Convertor.new( :lame_opts => [:'lame-opts'], :dest_root => [:destination] ) args.each { |glob| convert_files(glob, mp3izer) } end |