diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2009-08-01 16:36:12 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2009-08-01 16:36:12 -0700 |
commit | c1dbf9e1e4f4aeac340494def5a528a964e549c0 (patch) | |
tree | 4b57cf0c7434e936bc15bbbd1115a78fff6ac3d7 | |
parent | af6101f5e39310445e831554a62c449148476e01 (diff) | |
download | ruby-libmpd-c1dbf9e1e4f4aeac340494def5a528a964e549c0.tar.gz ruby-libmpd-c1dbf9e1e4f4aeac340494def5a528a964e549c0.tar.xz |
Add files method.
-rw-r--r-- | libmpd/database.rb | 17 |
1 files changed, 16 insertions, 1 deletions
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. # |