musicfix

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

commit bad8c76f8f914e8300b5977a872e0b052908f1d5
parent 23e7c2147773d60879bbd2b9f55b5bb118f34b0a
Author: lostd <lostd@2f30.org>
Date:   Mon, 31 Dec 2012 17:24:56 +0000

Better command line interface

Diffstat:
Mbin/musicfix | 35+++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/bin/musicfix b/bin/musicfix @@ -2,7 +2,7 @@ # encoding: utf-8 # Musicfix is a music file renamer and tagger with consistency concerns. -# It has a release-centered logic and gets data from www.discogs.com. +# It has a release-centered logic and gets data from the Discogs.com site. # First configure the target music directory (mdir variable). # Next browse the site and locate your album. Change to the album's # directory. Ensure the files are ordered and provide the release id @@ -123,12 +123,21 @@ def mkposlist tracks end # Parse command line -usage = "" -usage << "Usage: musicfix relfile\n" -usage << " musicfix relid [tracks]\n" -relfile = relid = ARGV[0] || (puts usage; exit) -tracks = ARGV[1] || nil -usefile = File.exists? relfile +usage = '' +usage << "Usage: musicfix relid [tracks]\n" +usage << " musicfix dump relid [relfile]\n" +usage << " musicfix load [relfile]\n" +cmd = ARGV[0] || (puts usage; exit) +case cmd +when 'load' then + relfile = ARGV[1] || 'release.yaml' +when 'dump' then + relid = ARGV[1] || (puts usage; exit) + relfile = ARGV[2] || 'release.yaml' +else + relid = ARGV[0] + tracks = ARGV[2] || nil +end # Construct file list fl = Dir['*'].select {|f| File.extname(f).match /mp3|ogg|mpc|flac|wv/i}.sort @@ -136,14 +145,14 @@ if fl.empty? then puts 'No music files found!' exit end -# Output audio files +# Output file list puts 'Files to process:' puts fl # Initialize release info rel = {} -if usefile then +if cmd == 'load' then # Load release data from file puts "Loading release data..." rel = YAML.load File.open(relfile, 'r') @@ -175,7 +184,7 @@ else rel['comment'] = "Discogs: #{r.id}" rel['imgurl'] = getimgurl r rel['tracklist'] = [] - # Populate track-list + # Populate tracklist tl.each do |s| trk = {} trk['pos'] = s.position @@ -187,6 +196,12 @@ end # Output release info puts rel.to_yaml +if cmd == 'dump' then + File.open(relfile, 'w') do |f| + f.puts rel.to_yaml + end + exit +end # Use smaller variable names ba = rel['artist']