blob: f903d9ea9a731c27f9df4d059afce3d232836f2a (
plain)
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
|
# TODO: Write documentation for `WialtDaemon`
require "crystal_mpd"
require "concurrent"
require "crest"
module WialtDaemon
VERSION = "0.1.0"
client = MPD::Client.new(with_callbacks: true)
client.callbacks_timeout = 2.seconds
# status : Concurrent::Hash(String, String) = Concurrent::Hash(String, String).new
# status = client.stats
if(client.connected?)
# puts "#{status["uptime"]}"
if(currentsong=client.currentsong)
puts "#{currentsong["Title"]}"
Crest.post(
"http://0.0.0.0:3000/music_changed",
{:title => currentsong["Title"]},
json: true
)
end
end
client.on :state do |state|
puts "[#{Time.local}] State was change to #{state}"
end
client.on :nextsong do
puts "#{client}"
end
client.on :song do
if (current_song = client.currentsong)
puts "[#{Time.local}] 🎵 #{current_song["Artist"]} - #{current_song["Title"]}"
end
end
loop { sleep 1 }
end
|