nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added setup files.
[nit.git]
/
lib
/
mpd.nit
diff --git
a/lib/mpd.nit
b/lib/mpd.nit
index
9ed7784
..
9a56b95
100644
(file)
--- a/
lib/mpd.nit
+++ b/
lib/mpd.nit
@@
-34,12
+34,11
@@
class MPDConnection
do
var p: nullable Socket = null
do
var p: nullable Socket = null
- p = new Socket.stream_with_host(host, port)
- p.connect
+ p = new Socket.client(host, port)
sys.nanosleep(0,5000)
sys.nanosleep(0,5000)
- var rep = p.read
+ var rep = p.read(1024)
assert not rep.is_empty
if not rep.has_prefix("OK") then
print "MPD responded {rep}"
assert not rep.is_empty
if not rep.has_prefix("OK") then
print "MPD responded {rep}"
@@
-61,7
+60,7
@@
class MPDConnection
socket.write(msg)
sys.nanosleep(0,5000)
socket.write(msg)
sys.nanosleep(0,5000)
- var rep = socket.read
+ var rep = socket.read(1024)
if not rep.has_prefix("OK") then
print "Error: MPD responded {rep}"
socket.close
if not rep.has_prefix("OK") then
print "Error: MPD responded {rep}"
socket.close
@@
-82,12
+81,12
@@
class MPDConnection
# get current status
socket.write("status\n")
# get current status
socket.write("status\n")
- var rep = socket.read
+ var rep = socket.read(1024)
for l in rep.split_with("\n") do
var words = l.split_with(" ")
if words.length > 1 then
var key = words[0].to_lower
for l in rep.split_with("\n") do
var words = l.split_with(" ")
if words.length > 1 then
var key = words[0].to_lower
- var first_space = l.index_of(' ')
+ var first_space = l.chars.index_of(' ')
var rest = l.substring_from(first_space+1)
if key == "volume:" then
volume = rest.to_i
var rest = l.substring_from(first_space+1)
if key == "volume:" then
volume = rest.to_i
@@
-153,12
+152,12
@@
class MPDConnection
var time: nullable Int = null
socket.write("currentsong\n")
var time: nullable Int = null
socket.write("currentsong\n")
- var rep = socket.read
+ var rep = socket.read(1024)
for l in rep.split_with("\n") do
var words = l.split_with(" ")
if words.length > 1 then
var key = words[0].to_lower
for l in rep.split_with("\n") do
var words = l.split_with(" ")
if words.length > 1 then
var key = words[0].to_lower
- var first_space = l.index_of(' ')
+ var first_space = l.chars.index_of(' ')
var rest = l.substring_from(first_space+1)
if key == "album:" then
album = rest
var rest = l.substring_from(first_space+1)
if key == "album:" then
album = rest
@@
-179,6
+178,11
@@
class MPDConnection
return null
end
end
return null
end
end
+
+ fun load_playlist(name: String)
+ do
+ write_and_check "load \"{name}\""
+ end
end
# MPD song info
end
# MPD song info