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

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

Returns:

  • (Array<String>)

    An array of album names.



99
100
101
# File 'lib/ruby-mpd/plugins/database.rb', line 99

def albums(artist = nil)
  list :album, artist
end

#artistsArray<String>

Lists all of the artists in the database.

Returns:

  • (Array<String>)

    An array of artist names.



106
107
108
# File 'lib/ruby-mpd/plugins/database.rb', line 106

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.

Returns:

  • (Hash)

    a hash with songs and playtime keys.



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.

Returns:

  • (Array<String>)

    Array of directory names



89
90
91
92
# File 'lib/ruby-mpd/plugins/database.rb', line 89

def directories(path = nil)
  response = send_command(:listall, path)
  return response[: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.

Returns:

  • (Hash<String>)

    hash with array keys :file, :directory and :playlist.



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

Returns:

  • (Array<String>)


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.

Returns:

  • (Integer)

    Update job ID



79
80
81
# File 'lib/ruby-mpd/plugins/database.rb', line 79

def rescan(path = nil)
  send_command :rescan, path
end

#search(type, what, options = {}) ⇒ Array<MPD::Song>, true

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.

Parameters:

  • type (Symbol)

    Can be any tag 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.

  • options (Hash) (defaults to: {})

    A hash of options.

Returns:

  • (Array<MPD::Song>)

    Songs that matched.

  • (true)

    if :add is enabled.



58
59
60
61
62
63
64
65
66
# File 'lib/ruby-mpd/plugins/database.rb', line 58

def search(type, what, options = {})
  if options[:add]
    command = options[:case_sensitive] ? :findadd : :searchadd
  else
    command = options[:case_sensitive] ? :find : :search
  end

  build_songs_list send_command(command, 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

Returns:



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.

Returns:



113
114
115
# File 'lib/ruby-mpd/plugins/database.rb', line 113

def songs_by_artist(artist)
  search :artist, artist
end

#update(path = nil) ⇒ Integer

Tell the server to update the database. Optionally, specify the path to update.

Returns:

  • (Integer)

    Update job ID



72
73
74
# File 'lib/ruby-mpd/plugins/database.rb', line 72

def update(path = nil)
  send_command :update, path
end