musicfix

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

commit 8a9ddca84edf1f71db93070d3e6f8f80f2f7399a
parent 7dbca2ee65ee2720723a739a6cb99930c01913bf
Author: lostd <lostd@2f30.org>
Date:   Tue, 14 Aug 2012 10:38:02 +0000

Add support for track filtering

Diffstat:
Mbin/musicfix | 29++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/bin/musicfix b/bin/musicfix @@ -91,8 +91,29 @@ def getimgurl rel img.uri.gsub 'api.discogs.com', 's.dsimg.com' end +# Construct position list from tracks filter +# The string "1-3,5,8" becomes ["1", "2", "3", "5", "8"] +# The string "A2-A4,B3" becomes ["A2", "A3", "A4", "B3"] +# Returns nil on error +def mkposlist tracks + pl = tracks.split(",").map do |r| + r = r.split("-") + return nil if r.include? "" + r = case r.length + when 1 then r + when 2 then (r[0] .. r[1]).map {|i| i} + else return nil + end + return nil if r.empty? + r + end + pl.flatten +end + # Parse command line -relid = ARGV[0] || (puts "Usage: musicfix release_id"; exit) +usage = "Usage: musicfix relid [tracks]" +relid = ARGV[0] || (puts usage; exit) +tracks = ARGV[1] || nil # Construct file list fl = Dir['*'].select {|f| File.extname(f).match /mp3|ogg|mpc|flac|wv/i}.sort @@ -114,6 +135,12 @@ r = discogs.get_release(relid) mr = if r.master_id then discogs.get_master_release(r.master_id) end # Tracklist can contain dummy header tracks, strip them tl = r.tracklist.select {|t| t.position} +# Apply tracks filter if given +if tracks then + pl = mkposlist tracks + puts "Invalid tracks filter: #{tracks}" unless pl + tl = tl.select {|t| pl.include? t.position} +end # Sanity checks if tl.length != fl.length then