run rubocop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
diff --git a/lib/mpd_client.rb b/lib/mpd_client.rb
index fe45c2a..0cf86d5 100644
--- a/lib/mpd_client.rb
+++ b/lib/mpd_client.rb
@@ -14,118 +14,118 @@ module MPD
# http://git.musicpd.org/cgit/cirrus/mpd.git/plain/doc/protocol.xml
COMMANDS = {
# Status Commands
- 'clearerror' => 'fetch_nothing',
- 'currentsong' => 'fetch_object',
- 'idle' => 'fetch_list',
- 'noidle' => '',
- 'status' => 'fetch_object',
- 'stats' => 'fetch_object',
+ 'clearerror' => 'fetch_nothing',
+ 'currentsong' => 'fetch_object',
+ 'idle' => 'fetch_list',
+ 'noidle' => '',
+ 'status' => 'fetch_object',
+ 'stats' => 'fetch_object',
# Playback Option Commands
- 'consume' => 'fetch_nothing',
- 'crossfade' => 'fetch_nothing',
- 'mixrampdb' => 'fetch_nothing',
- 'mixrampdelay' => 'fetch_nothing',
- 'random' => 'fetch_nothing',
- 'repeat' => 'fetch_nothing',
- 'setvol' => 'fetch_nothing',
- 'single' => 'fetch_nothing',
- 'replay_gain_mode' => 'fetch_nothing',
+ 'consume' => 'fetch_nothing',
+ 'crossfade' => 'fetch_nothing',
+ 'mixrampdb' => 'fetch_nothing',
+ 'mixrampdelay' => 'fetch_nothing',
+ 'random' => 'fetch_nothing',
+ 'repeat' => 'fetch_nothing',
+ 'setvol' => 'fetch_nothing',
+ 'single' => 'fetch_nothing',
+ 'replay_gain_mode' => 'fetch_nothing',
'replay_gain_status' => 'fetch_item',
- 'volume' => 'fetch_nothing',
+ 'volume' => 'fetch_nothing',
# Playback Control Commands
- 'next' => 'fetch_nothing',
- 'pause' => 'fetch_nothing',
- 'play' => 'fetch_nothing',
- 'playid' => 'fetch_nothing',
- 'previous' => 'fetch_nothing',
- 'seek' => 'fetch_nothing',
- 'seekid' => 'fetch_nothing',
- 'seekcur' => 'fetch_nothing',
- 'stop' => 'fetch_nothing',
+ 'next' => 'fetch_nothing',
+ 'pause' => 'fetch_nothing',
+ 'play' => 'fetch_nothing',
+ 'playid' => 'fetch_nothing',
+ 'previous' => 'fetch_nothing',
+ 'seek' => 'fetch_nothing',
+ 'seekid' => 'fetch_nothing',
+ 'seekcur' => 'fetch_nothing',
+ 'stop' => 'fetch_nothing',
# Playlist Commands
- 'add' => 'fetch_nothing',
- 'addid' => 'fetch_item',
- 'addtagid' => 'fetch_nothing',
- 'cleartagid' => 'fetch_nothing',
- 'clear' => 'fetch_nothing',
- 'delete' => 'fetch_nothing',
- 'deleteid' => 'fetch_nothing',
- 'move' => 'fetch_nothing',
- 'moveid' => 'fetch_nothing',
- 'playlist' => 'fetch_playlist',
- 'playlistfind' => 'fetch_songs',
- 'playlistid' => 'fetch_songs',
- 'playlistinfo' => 'fetch_songs',
- 'playlistsearch' => 'fetch_songs',
- 'plchanges' => 'fetch_songs',
- 'plchangesposid' => 'fetch_changes',
- 'prio' => 'fetch_nothing',
- 'prioid' => 'fetch_nothing',
- 'rangeid' => 'fetch_nothing',
- 'shuffle' => 'fetch_nothing',
- 'swap' => 'fetch_nothing',
- 'swapid' => 'fetch_nothing',
+ 'add' => 'fetch_nothing',
+ 'addid' => 'fetch_item',
+ 'addtagid' => 'fetch_nothing',
+ 'cleartagid' => 'fetch_nothing',
+ 'clear' => 'fetch_nothing',
+ 'delete' => 'fetch_nothing',
+ 'deleteid' => 'fetch_nothing',
+ 'move' => 'fetch_nothing',
+ 'moveid' => 'fetch_nothing',
+ 'playlist' => 'fetch_playlist',
+ 'playlistfind' => 'fetch_songs',
+ 'playlistid' => 'fetch_songs',
+ 'playlistinfo' => 'fetch_songs',
+ 'playlistsearch' => 'fetch_songs',
+ 'plchanges' => 'fetch_songs',
+ 'plchangesposid' => 'fetch_changes',
+ 'prio' => 'fetch_nothing',
+ 'prioid' => 'fetch_nothing',
+ 'rangeid' => 'fetch_nothing',
+ 'shuffle' => 'fetch_nothing',
+ 'swap' => 'fetch_nothing',
+ 'swapid' => 'fetch_nothing',
# Stored Playlist Commands
- 'listplaylist' => 'fetch_list',
- 'listplaylistinfo' => 'fetch_songs',
- 'listplaylists' => 'fetch_playlists',
- 'load' => 'fetch_nothing',
- 'playlistadd' => 'fetch_nothing',
- 'playlistclear' => 'fetch_nothing',
- 'playlistdelete' => 'fetch_nothing',
- 'playlistmove' => 'fetch_nothing',
- 'rename' => 'fetch_nothing',
- 'rm' => 'fetch_nothing',
- 'save' => 'fetch_nothing',
+ 'listplaylist' => 'fetch_list',
+ 'listplaylistinfo' => 'fetch_songs',
+ 'listplaylists' => 'fetch_playlists',
+ 'load' => 'fetch_nothing',
+ 'playlistadd' => 'fetch_nothing',
+ 'playlistclear' => 'fetch_nothing',
+ 'playlistdelete' => 'fetch_nothing',
+ 'playlistmove' => 'fetch_nothing',
+ 'rename' => 'fetch_nothing',
+ 'rm' => 'fetch_nothing',
+ 'save' => 'fetch_nothing',
# Database Commands
- 'count' => 'fetch_object',
- 'find' => 'fetch_songs',
- 'findadd' => 'fetch_nothing',
- 'list' => 'fetch_list',
- 'listall' => 'fetch_database',
- 'listallinfo' => 'fetch_database',
- 'listfiles' => 'fetch_database',
- 'lsinfo' => 'fetch_database',
- 'search' => 'fetch_songs',
- 'searchadd' => 'fetch_nothing',
- 'searchaddp1' => 'fetch_nothing',
- 'update' => 'fetch_item',
- 'rescan' => 'fetch_item',
- 'readcomments' => 'fetch_object',
+ 'count' => 'fetch_object',
+ 'find' => 'fetch_songs',
+ 'findadd' => 'fetch_nothing',
+ 'list' => 'fetch_list',
+ 'listall' => 'fetch_database',
+ 'listallinfo' => 'fetch_database',
+ 'listfiles' => 'fetch_database',
+ 'lsinfo' => 'fetch_database',
+ 'search' => 'fetch_songs',
+ 'searchadd' => 'fetch_nothing',
+ 'searchaddp1' => 'fetch_nothing',
+ 'update' => 'fetch_item',
+ 'rescan' => 'fetch_item',
+ 'readcomments' => 'fetch_object',
# Mounts and neighbors
- 'mount' => 'fetch_nothing',
- 'unmount' => 'fetch_nothing',
- 'listmounts' => 'fetch_mounts',
- 'listneighbors' => 'fetch_neighbors',
+ 'mount' => 'fetch_nothing',
+ 'unmount' => 'fetch_nothing',
+ 'listmounts' => 'fetch_mounts',
+ 'listneighbors' => 'fetch_neighbors',
# Sticker Commands
- 'sticker get' => 'fetch_sticker',
- 'sticker set' => 'fetch_nothing',
- 'sticker delete' => 'fetch_nothing',
- 'sticker list' => 'fetch_stickers',
- 'sticker find' => 'fetch_songs',
+ 'sticker get' => 'fetch_sticker',
+ 'sticker set' => 'fetch_nothing',
+ 'sticker delete' => 'fetch_nothing',
+ 'sticker list' => 'fetch_stickers',
+ 'sticker find' => 'fetch_songs',
# Connection Commands
- 'close' => '',
- 'kill' => '',
- 'password' => 'fetch_nothing',
- 'ping' => 'fetch_nothing',
+ 'close' => '',
+ 'kill' => '',
+ 'password' => 'fetch_nothing',
+ 'ping' => 'fetch_nothing',
# Audio Output Commands
- 'disableoutput' => 'fetch_nothing',
- 'enableoutput' => 'fetch_nothing',
- 'outputs' => 'fetch_outputs',
- 'toggleoutput' => 'fetch_nothing',
+ 'disableoutput' => 'fetch_nothing',
+ 'enableoutput' => 'fetch_nothing',
+ 'outputs' => 'fetch_outputs',
+ 'toggleoutput' => 'fetch_nothing',
# Reflection Commands
- 'config' => 'fetch_item',
- 'commands' => 'fetch_list',
- 'notcommands' => 'fetch_list',
- 'tagtypes' => 'fetch_list',
- 'urlhandlers' => 'fetch_list',
- 'decoders' => 'fetch_plugins',
+ 'config' => 'fetch_item',
+ 'commands' => 'fetch_list',
+ 'notcommands' => 'fetch_list',
+ 'tagtypes' => 'fetch_list',
+ 'urlhandlers' => 'fetch_list',
+ 'decoders' => 'fetch_plugins',
# Client To Client
- 'subscribe' => 'fetch_nothing',
- 'unsubscribe' => 'fetch_nothing',
- 'channels' => 'fetch_list',
- 'readmessages' => 'fetch_messages',
- 'sendmessage' => 'fetch_nothing'
+ 'subscribe' => 'fetch_nothing',
+ 'unsubscribe' => 'fetch_nothing',
+ 'channels' => 'fetch_list',
+ 'readmessages' => 'fetch_messages',
+ 'sendmessage' => 'fetch_nothing'
}.freeze
# The `MPD::Client` is used for interactions with a MPD server.
@@ -169,6 +169,7 @@ module MPD
def remove_command(name)
raise "Can't remove not existent '#{name}' command" unless method_defined? name.to_sym
+
remove_method name.to_sym
end
end
@@ -219,12 +220,14 @@ module MPD
# https://www.musicpd.org/doc/protocol/command_lists.html
def command_list_ok_begin
raise 'Already in command list' unless @command_list.nil?
+
write_command('command_list_ok_begin')
@command_list = []
end
def command_list_end
raise 'Not in command list' if @command_list.nil?
+
write_command('command_list_end')
fetch_command_list
@@ -285,6 +288,7 @@ module MPD
def read_line
line = @socket.gets.force_encoding('utf-8')
raise 'Connection lost while reading line' unless line.end_with?("\n")
+
line.chomp!
if line.start_with?(ERROR_PREFIX)
error = line[/#{ERROR_PREFIX}(.*)/, 1].strip
@@ -304,6 +308,7 @@ module MPD
def read_pair(separator)
line = read_line
return if line.nil?
+
pair = line.split(separator, 2)
raise "Could now parse pair: '#{line}'" if pair.size < 2
@@ -340,6 +345,7 @@ module MPD
read_pairs.each do |key, value|
if key != seen
raise "Expected key '#{seen}', got '#{key}'" unless seen.nil?
+
seen = key
end
@@ -424,6 +430,7 @@ module MPD
read_pairs.each do |_key, sticker|
value = sticker.split('=', 2)
raise "Could now parse sticker: #{sticker}" if value.size < 2
+
result << Hash[*value]
end
@@ -450,8 +457,10 @@ module MPD
def hello
line = @socket.gets
raise 'Connection lost while reading MPD hello' unless line.end_with?("\n")
+
line.chomp!
raise "Got invalid MPD hello: #{line}" unless line.start_with?(HELLO_PREFIX)
+
@mpd_version = line[/#{HELLO_PREFIX}(.*)/, 1]
end