musicfix

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

commit 8e4bbf0021e21cb89959aaa829842e6b92c16f97
parent 3353f89e164bb4664cb86452f2d5fed964b6945e
Author: lostd <lostd@2f30.org>
Date:   Sun Jan 12 12:45:35 +0000

Look for any yaml when loading release file, save release file

Diffstat:
bin/musicfix | 52++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 42 insertions(+), 10 deletions(-)
diff --git a/bin/musicfix b/bin/musicfix @@ -155,7 +155,7 @@ ARGV.delete 'fake' cmd = ARGV[0] || (puts usage; exit) case cmd when 'load' then - relfile = ARGV[1] || 'release.yaml' + relfile = ARGV[1] || nil when 'dump' then relid = ARGV[1] || (puts usage; exit) relfile = ARGV[2] || 'release.yaml' @@ -169,6 +169,7 @@ cfg = {} cfg['mdir'] = '~/music' cfg['track'] = '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{d}#{fn}-#{fa}-#{ft}.#{x}"' cfg['image'] = '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{zz}-#{fba}-#{fb}_cover.jpg"' +cfg['rdata'] = '"#{mdir}/#{fba}-#{my}-#{fb}-#{fv}/#{zz}-#{fba}-#{fb}_release.yaml"' #cfg['after'] = '"mpc update #{fba}-#{my}-#{fb}-#{fv}"' # User configuration overrides @@ -185,7 +186,13 @@ cfg['mdir'] = File.expand_path cfg['mdir'] puts 'Configuration' puts cfg.to_yaml -unless cmd == 'dump' then +# Early file checks +if cmd == 'dump' then + if File.exists? relfile then + puts "Release file #{relfile} exists!" + exit + end +else # Supported formats fmtre = /mp3|ogg|m4a|mpc|flac|wv/i # Construct file list @@ -202,13 +209,28 @@ end # Initialize release info if cmd == 'load' then # Load release data from file - if File.exists? relfile then - puts "Loading release data..." - rel = YAML.load File.open(relfile, 'r') + if relfile then + # The user specified some file + unless File.exists? relfile then + puts "Release file #{relfile} not found!" + exit + end else - puts "Release file #{relfile} not found." - exit + # Look for 'release.yaml' first + if File.exists? 'release.yaml' then + relfile = 'release.yaml' + else + # Look for any '.yaml' file + relfl = Dir['*'].select {|f| File.extname(f).match /yaml/i} + relfile = relfl.sort.first + end + unless relfile then + puts 'No release file found!' + exit + end end + puts "Loading release data..." + rel = YAML.load File.open(relfile, 'r') else # Get release data from Discogs puts "Geting release data..." @@ -330,18 +352,28 @@ end zz = '0' * (mkdiscnum tl.last['pos'].to_s).join.length imgname = eval cfg['image'] if rel['imgurl'] then - puts "Save cover to #{imgname}" + puts "Save image to #{imgname}" unless fake img = open(rel['imgurl'], Headers).read File.open(imgname, 'wb').write img end end +# Also save the release file for future use +relfile = eval cfg['rdata'] +puts "Save rdata to #{relfile}" +unless fake + File.open(relfile, 'w') do |f| + f.puts rel.to_yaml + end +end # Execute command if provided if cfg['after'] then puts "Executing finishing command" - run = eval cfg['after'] - `#{run}` + unless fake + run = eval cfg['after'] + `#{run}` + end end # vim:set ts=4 sw=4 et: