From c1dbf9e1e4f4aeac340494def5a528a964e549c0 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 1 Aug 2009 16:36:12 -0700 Subject: Add files method. --- libmpd/database.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'libmpd/database.rb') diff --git a/libmpd/database.rb b/libmpd/database.rb index 4f08f5c..27efa93 100644 --- a/libmpd/database.rb +++ b/libmpd/database.rb @@ -23,7 +23,7 @@ module MPDDatabase path = String.new end - return send_request(command).scan(/^directory: #{path}([^\/]+)\n/).flatten + return send_request(command).scan(/^directory: #{path}([^\/]+?)\n/).flatten end # Counts the number of songs in the database where _field_ is _value_, as @@ -39,6 +39,21 @@ module MPDDatabase return split_and_hash(send_request('find %s "%s"' % [field, value])) end + # Returns all files. + # If an argument is specified, list all files in that directory. + def files(uri=nil) + command = 'listall' + command << ' "%s"' % uri if uri + + if uri + path = Regexp.escape(uri + '/') + else + path = String.new + end + + return send_request(command).scan(/^file: #{path}([^\/]+?)\n/).flatten + end + # Finds all songs in the database where _field_ contains _value_. # Matching is not case-sensitive. # -- cgit v1.2.3-70-g09d2