diff options
-rwxr-xr-x | bin/dtas-mlib | 23 | ||||
-rw-r--r-- | lib/dtas/mlib.rb | 8 |
2 files changed, 27 insertions, 4 deletions
diff --git a/bin/dtas-mlib b/bin/dtas-mlib index 16876a2..e85c950 100755 --- a/bin/dtas-mlib +++ b/bin/dtas-mlib @@ -39,9 +39,30 @@ case action = ARGV.shift when 'update', 'up' directory = ARGV.shift or abort "DIRECTORY required\n#{usage}" mlib(db, migrate = true).update(directory) +when 'stats' + s = mlib(db, true).stats + %w(artists albums songs db_playtime).each { |k| puts "#{k}: #{s[k.to_sym]}" } when 'dump' # mainly for debugging directory = ARGV.shift || '/' - mlib(db).dump(directory) + mlib(db).dump(directory, {}, lambda do |parent, node, comments| + puts "Path: #{parent[:dirname]}/#{node[:name]}" + puts "Length: #{node[:tlen]}" + return if comments.empty? + puts 'Comments:' + comments.each do |k,v| + if v.size == 1 + puts "\t#{k}: #{v[0]}" + else + v << '' + puts "\t#{k}:\n\t\t#{v.join("\t\t\n")}" + end + end + puts + end) +when 'find', 'search' + m = mlib(db) + cache = {} + m.__send__(action, *ARGV) { |node| puts m.path_of(node, cache) } else abort usage end diff --git a/lib/dtas/mlib.rb b/lib/dtas/mlib.rb index b81ec54..0d2f70c 100644 --- a/lib/dtas/mlib.rb +++ b/lib/dtas/mlib.rb @@ -212,6 +212,7 @@ class DTAS::Mlib # :nodoc: q = { parent_id: 1, # self name: '', + dirname: '', } node = @db[:nodes][q] and return (@root_node = node) begin @@ -378,10 +379,10 @@ class DTAS::Mlib # :nodoc: def path_of(node, cache) base = node[:name] - return '/' if base == '' + return '/' if base == '' # root_node parent_id = node[:parent_id] base += '/' unless node[:tlen] >= 0 - ppath = cache[parent_id] and return "#{ppath}#{base}" + ppath = cache[parent_id] and return "#{ppath}/#{base}" parts = [] begin node = @db[:nodes][id: node[:parent_id]] @@ -389,8 +390,9 @@ class DTAS::Mlib # :nodoc: parts.unshift node[:name] end while true parts.unshift('') - parts << base cache[parent_id] = parts.join('/') + parts << base + parts.join('/') end def emit_recurse(node, cache, cb) |