musicfix

music file renamer and tagger
git clone git://git.2f30.org/musicfix.git
Log | Files | Refs | README | LICENSE

commit 92778bb65084c0cab4dfd7fed58112533b391eb1
parent 00cd5ee372ea3b44c10241b1f32026f34b25b754
Author: lostd <lostd@2f30.org>
Date:   Sat, 17 May 2014 11:53:26 +0000

Consistency in program output, better tracks filter handling

Diffstat:
bin/musicfix | 47++++++++++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 17 deletions(-)

diff --git a/bin/musicfix b/bin/musicfix @@ -198,13 +198,13 @@ end cfg['mdir'] = File.expand_path cfg['mdir'] # Print configuration -puts 'Configuration' +puts '# Configuration' puts cfg.to_yaml # Early file checks if cmd == 'dump' or cmd == 'tags' then if File.exists? relfile then - puts "Release file #{relfile} exists!" + STDERR.puts "Release file #{relfile} exists!" exit end end @@ -215,11 +215,11 @@ unless cmd == 'dump' then # Construct file list fl = Dir['*'].select {|f| File.extname(f).match fmtre}.sort if fl.empty? then - puts 'No music files found!' - exit + STDERR.puts 'No music files found!' + exit 1 end # Output file list - puts 'Files to process' + puts '# Files to process' puts fl.to_yaml end @@ -229,8 +229,8 @@ if cmd == 'load' then if relfile then # The user specified some file unless File.exists? relfile then - puts "Release file #{relfile} not found!" - exit + STDERR.puts "Release file #{relfile} not found!" + exit 1 end else # Look for 'release.yaml' first @@ -242,14 +242,15 @@ if cmd == 'load' then relfile = relfl.sort.first end unless relfile then - puts 'No release file found!' - exit + STDERR.puts 'No release file found!' + exit 1 end end - puts "Loading release data..." + STDERR.puts "Loading release data from file..." rel = YAML.load File.open(relfile, 'r') elsif cmd == 'tags' then # Generate release file from audio file tags + STDERR.puts "Generating release data from tags..." rel = {} rel['artist'] = [] rel['album'] = [] @@ -295,7 +296,7 @@ elsif cmd == 'tags' then rel['format'] = 'CD' else # Get release data from Discogs - puts "Getting release data..." + STDERR.puts "Getting release data from Discogs..." r = YAML.load(open("http://api.discogs.com/release/#{relid}?f=json", Headers))['resp']['release'] mr = if r['master_id'] then @@ -307,8 +308,15 @@ else # Apply tracks filter if given if tracks then pl = mkposlist tracks - puts "Invalid tracks filter: #{tracks}" unless pl + unless pl + STDERR.puts "Invalid tracks filter: #{tracks}" + exit 1 + end tl = tl.select {|t| pl.include? t['position']} + if tl.empty? + STDERR.puts "Filter returned no tracks: #{tracks}" + exit 1 + end end # Gather release-wide data rel = {} @@ -323,6 +331,9 @@ else if r['genres'] then r['genres'].first end rel['format'] = mkformat r['formats'].first rel['comment'] = "Discogs: #{r['id']}" + if tracks then + rel['comment'] += ", tracks: #{tracks}" + end rel['imgurl'] = getimgurl r rel['tracklist'] = [] # Populate tracklist @@ -336,8 +347,10 @@ else end # Output release info +puts '# Release data' puts rel.to_yaml if cmd == 'dump' or cmd == 'tags' then + STDERR.puts "Save rdata to #{relfile}" unless fake File.open(relfile, 'w') do |f| f.puts rel.to_yaml @@ -395,7 +408,7 @@ fl.each do |ofname| nfname = eval cfg['track'] # Add filename to track descriptor trk['file'] = nfname - puts "Copy track to #{nfname}" + STDERR.puts "Copy track to #{nfname}" unless fake FileUtils.makedirs(File.dirname nfname) FileUtils.copy(ofname, nfname) @@ -416,7 +429,7 @@ end zz = '0' * (mkdiscnum tl.last['pos'].to_s).join.length imgname = eval cfg['image'] if rel['imgurl'] then - puts "Save image to #{imgname}" + STDERR.puts "Save image to #{imgname}" unless fake img = open(rel['imgurl'], Headers).read File.open(imgname, 'wb').write img @@ -424,7 +437,7 @@ if rel['imgurl'] then end # Also save the release file for future use relfile = eval cfg['rdata'] -puts "Save rdata to #{relfile}" +STDERR.puts "Save rdata to #{relfile}" unless fake # Sort tracklist in filename order and delete filenames rel['tracklist'].sort_by! {|s| s['file']} @@ -436,9 +449,9 @@ end # Execute command if provided if cfg['after'] then - puts "Executing finishing command" + run = eval cfg['after'] + STDERR.puts "Executing #{run}" unless fake - run = eval cfg['after'] `#{run}` end end