diff options
author | Indrajith K L | 2023-11-06 06:02:00 +0530 |
---|---|---|
committer | Indrajith K L | 2023-11-06 06:02:00 +0530 |
commit | 2d0be9bd77c47f5d9cb2a179ae706c9f74d201ec (patch) | |
tree | 31bf740d78078d8fd67faec284f5d30aaf82a83c /src/wialt_daemon.cr | |
download | wialt_daemon-2d0be9bd77c47f5d9cb2a179ae706c9f74d201ec.tar.gz wialt_daemon-2d0be9bd77c47f5d9cb2a179ae706c9f74d201ec.tar.bz2 wialt_daemon-2d0be9bd77c47f5d9cb2a179ae706c9f74d201ec.zip |
* Daemon Implementation - In-Progress
* Initial MPC Event Captures
* POST music title on daemon is loaded
* POST music title on song change - TODO
Diffstat (limited to 'src/wialt_daemon.cr')
-rw-r--r-- | src/wialt_daemon.cr | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/wialt_daemon.cr b/src/wialt_daemon.cr new file mode 100644 index 0000000..f903d9e --- /dev/null +++ b/src/wialt_daemon.cr @@ -0,0 +1,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 |