Module: MPD::Plugins::Database
- Included in:
- MPD
- Defined in:
- lib/ruby-mpd/plugins/database.rb
Overview
Commands for interacting with the music database.
Instance Method Summary collapse
-
#albums(artist = nil) ⇒ Array<String>
Lists all of the albums in the database.
-
#artists ⇒ Array<String>
Lists all of the artists in the database.
-
#count(type, what) ⇒ Hash
Counts the number of songs and their total playtime in the db matching, matching the searched tag exactly.
-
#directories(path = nil) ⇒ Array<String>
List all of the directories in the database, starting at path.
-
#files(path = nil) ⇒ Hash<String>
List all of the files in the database, starting at path.
-
#list(type, arg = nil) ⇒ Array<String>
List all tags of the specified type.
-
#rescan(path = nil) ⇒ Integer
Same as #update, but also rescans unmodified files.
-
#search(type, what, options = {}) ⇒ Array<MPD::Song>, true
deprecated
Deprecated.
Use #where instead.
-
#songs(path = nil) ⇒ Array<MPD::Song>
List all of the songs in the database starting at path.
-
#songs_by_artist(artist) ⇒ Array<MPD::Song>
List all of the songs by an artist.
-
#update(path = nil) ⇒ Integer
Tell the server to update the database.
-
#where(params, options = {}) ⇒ Array<MPD::Song>, true
Searches the database for any songs that match the specified parameters.
Instance Method Details
#albums(artist = nil) ⇒ Array<String>
Lists all of the albums in the database. The optional argument is for specifying an artist to list the albums for
133 134 135 |
# File 'lib/ruby-mpd/plugins/database.rb', line 133 def albums(artist = nil) list :album, artist end |
#artists ⇒ Array<String>
Lists all of the artists in the database.
140 141 142 |
# File 'lib/ruby-mpd/plugins/database.rb', line 140 def artists list :artist end |
#count(type, what) ⇒ Hash
Counts the number of songs and their total playtime in the db matching, matching the searched tag exactly.
If you need a count on the entire database, look at #stats.
12 13 14 |
# File 'lib/ruby-mpd/plugins/database.rb', line 12 def count(type, what) send_command :count, type, what end |
#directories(path = nil) ⇒ Array<String>
List all of the directories in the database, starting at path. If path isn’t specified, the root of the database is used.
124 125 126 |
# File 'lib/ruby-mpd/plugins/database.rb', line 124 def directories(path = nil) return files(path)[:directory] end |
#files(path = nil) ⇒ Hash<String>
List all of the files in the database, starting at path. If path isn’t specified, the root of the database is used.
29 30 31 |
# File 'lib/ruby-mpd/plugins/database.rb', line 29 def files(path = nil) send_command :listall, path end |
#list(type, arg = nil) ⇒ Array<String>
List all tags of the specified type. Type can be any tag supported by MPD or :file
. If type is ‘album’ then arg can be a specific artist to list the albums for
21 22 23 |
# File 'lib/ruby-mpd/plugins/database.rb', line 21 def list(type, arg = nil) send_command :list, type, arg end |
#rescan(path = nil) ⇒ Integer
Same as #update, but also rescans unmodified files.
114 115 116 |
# File 'lib/ruby-mpd/plugins/database.rb', line 114 def rescan(path = nil) send_command :rescan, path end |
#search(type, what, options = {}) ⇒ Array<MPD::Song>, true
Use #where instead.
Searches for any song that contains what
in the type
field. Searches are case insensitive by default, however you can enable it using the third argument.
Options:
-
add: Add the search results to the queue.
-
case_sensitive: Make the query case sensitive.
60 61 62 63 64 |
# File 'lib/ruby-mpd/plugins/database.rb', line 60 def search(type, what, = {}) warn "MPD#search is deprecated! Use MPD#where instead." [:strict] = [:case_sensitive] # transparently upgrade renamed option where({type => what}, ) end |
#songs(path = nil) ⇒ Array<MPD::Song>
List all of the songs in the database starting at path. If path isn’t specified, the root of the database is used
37 38 39 |
# File 'lib/ruby-mpd/plugins/database.rb', line 37 def songs(path = nil) build_songs_list send_command(:listallinfo, path) end |
#songs_by_artist(artist) ⇒ Array<MPD::Song>
List all of the songs by an artist.
147 148 149 |
# File 'lib/ruby-mpd/plugins/database.rb', line 147 def songs_by_artist(artist) where(artist: artist) end |
#update(path = nil) ⇒ Integer
Tell the server to update the database. Optionally, specify the path to update.
107 108 109 |
# File 'lib/ruby-mpd/plugins/database.rb', line 107 def update(path = nil) send_command :update, path end |
#where(params, options = {}) ⇒ Array<MPD::Song>, true
Searches the database for any songs that match the specified parameters. Searching is loose (case insensitive and allow partial matching) by default.
The search keys can be any of the tags supported by MPD, or one of the two special parameters: :file
to search by full path (relative to database root), and :any
to match against all available tags.
mpd.where(artist: "DJ Shadow", album: "Endtroducing.....")
A hash of options can be passed as a last parameter:
mpd.where({artist: "Nujabes", album: "Modal Soul"}, {add: true})
Options:
-
add: Add search results to the queue.
-
strict: Search will be *case sensitive* and allow only *full matches*.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ruby-mpd/plugins/database.rb', line 88 def where(params, = {}) if [:add] command = [:strict] ? :findadd : :searchadd else command = [:strict] ? :find : :search end response = send_command(command, params) if response == true return true else build_songs_list response end end |