ruby-mpd
ruby-mpd copied to clipboard
Command Lists
Command List support. In short:
# Do not parse response (for speed)
@mpd.command_list do
add song
volume 50
shuffle
end
# Array of values from each response line
ids = @mpd.command_list(:values) do
addid song1
addid song2
end
#=> [113,114]
# Single hash (with possible array values)
ids = @mpd.command_list(:hash) do
addid song3
addid song4
end
#=> { id:[115,116] }
# Array of hashes (split on first-value heuristic)
ids = @mpd.command_list(:hashes) do
addid song5
addid song6
end
#=> [ {id:117}, {id:118} ]
# Array of Songs (split on first-value heuristic)
ids = @mpd.command_list(:songs) do
where genre:'electronic'
where genre:'trance'
end
#=> [ <MPD::Song>, <MPD::Song>, ... ]
# Array of Playlists (split on first-value heuristic)
ids = @mpd.command_list(:playlists) do
clear
where({genre:'electronic'},{add:true})
save 'new-playlist'
playlists
end
#=> [ <MPD::Playlist>, <MPD::Playlist>, ... ]
Includes support for new playlist commands in the command list. These methods accept either a playlist name or a playlist as the identifier.
@archSeer Any thoughts on this?
@archSeer ping?
Sorry, I've been traveling and it's a big feature to look over; I'll allocate time on Monday to review this :)
On Saturday, 27 February 2016, Gavin Kistner [email protected] wrote:
@archSeer https://github.com/archSeer ping?
— Reply to this email directly or view it on GitHub https://github.com/archSeer/ruby-mpd/pull/73#issuecomment-189586007.
Short summary of all the above: I will create an alternate pull request for consideration that modifies MPD#send_command
to be aware of command-lists, to not grab the mutex and not handle any response in that mode, and to record the expected return type. This will allow playlists to be used in command lists directly, will even allow the same MPD instance to be used inside the command list, and will allow for the return value of command_list
to be robust and correct (when desired), without the programmer specifying how to parse the response.