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
128 129 130 |
# File 'lib/ruby-mpd/plugins/database.rb', line 128 def albums(artist = nil) list :album, artist end |
#artists ⇒ Array<String>
Lists all of the artists in the database.
135 136 137 |
# File 'lib/ruby-mpd/plugins/database.rb', line 135 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.
119 120 121 |
# File 'lib/ruby-mpd/plugins/database.rb', line 119 def directories(path = nil) return files[: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.
109 110 111 |
# File 'lib/ruby-mpd/plugins/database.rb', line 109 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.
142 143 144 |
# File 'lib/ruby-mpd/plugins/database.rb', line 142 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.
102 103 104 |
# File 'lib/ruby-mpd/plugins/database.rb', line 102 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 |
# File 'lib/ruby-mpd/plugins/database.rb', line 88 def where(params, = {}) if [:add] command = [:strict] ? :findadd : :searchadd else command = [:strict] ? :find : :search end build_songs_list send_command(command, params) end |