aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.editorconfig9
-rw-r--r--.gitignore5
-rw-r--r--LICENSE21
-rw-r--r--README.md16
-rw-r--r--shard.lock18
-rw-r--r--shard.yml19
-rw-r--r--spec/spec_helper.cr2
-rw-r--r--spec/wialt_daemon_spec.cr9
-rw-r--r--src/wialt_daemon.cr40
9 files changed, 139 insertions, 0 deletions
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..163eb75
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,9 @@
+root = true
+
+[*.cr]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 2
+trim_trailing_whitespace = true
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0bb75ea
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+/docs/
+/lib/
+/bin/
+/.shards/
+*.dwarf
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..6f1ec5f
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 Indrajith K L <indrajith@indrajith.dev>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a6b3a54
--- /dev/null
+++ b/README.md
@@ -0,0 +1,16 @@
+# [W]hat [I] [A]m [L]istening [T]o Daemon
+
+A Daemon written in Crystal Lang which is part of WIALT Project. This is a daemon which should be installed in the system where mpc player is running. This will send music data and mpc state to server to display music data in indrajith.dev website.
+
+## Installation
+
+* Install Crystal
+* `shards install`
+
+## Usage
+
+* `crystal run src/wialt_daemon.cr`
+
+## Contributors
+
+- [Indrajith K L](https://github.com/cooljith91112) - creator and maintainer
diff --git a/shard.lock b/shard.lock
new file mode 100644
index 0000000..56fb9c2
--- /dev/null
+++ b/shard.lock
@@ -0,0 +1,18 @@
+version: 2.0
+shards:
+ crest:
+ git: https://github.com/mamantoha/crest.git
+ version: 1.3.12
+
+ crystal_mpd:
+ git: https://github.com/mamantoha/crystal_mpd.git
+ version: 0.15.1
+
+ http-client-digest_auth:
+ git: https://github.com/mamantoha/http-client-digest_auth.git
+ version: 0.6.0
+
+ http_proxy:
+ git: https://github.com/mamantoha/http_proxy.git
+ version: 0.10.1
+
diff --git a/shard.yml b/shard.yml
new file mode 100644
index 0000000..249c50d
--- /dev/null
+++ b/shard.yml
@@ -0,0 +1,19 @@
+name: wialt_daemon
+version: 0.1.0
+
+authors:
+ - Indrajith K L <indrajith@indrajith.dev>
+
+dependencies:
+ crystal_mpd:
+ github: mamantoha/crystal_mpd
+ crest:
+ github: mamantoha/crest
+
+targets:
+ wialt_daemon:
+ main: src/wialt_daemon.cr
+
+crystal: '>= 1.10.1'
+
+license: MIT
diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr
new file mode 100644
index 0000000..164f802
--- /dev/null
+++ b/spec/spec_helper.cr
@@ -0,0 +1,2 @@
+require "spec"
+require "../src/wialt_daemon"
diff --git a/spec/wialt_daemon_spec.cr b/spec/wialt_daemon_spec.cr
new file mode 100644
index 0000000..41d2a80
--- /dev/null
+++ b/spec/wialt_daemon_spec.cr
@@ -0,0 +1,9 @@
+require "./spec_helper"
+
+describe WialtDaemon do
+ # TODO: Write tests
+
+ it "works" do
+ false.should eq(true)
+ end
+end
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