Skip to content

Commit

Permalink
allow to specify MPD server host and port
Browse files Browse the repository at this point in the history
  • Loading branch information
mamantoha committed Oct 31, 2023
1 parent cee010a commit 17963d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/crympd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@ end

SOCKETS = [] of HTTP::WebSocket

mpd_client = MPDClient.new(SOCKETS)
mpd_host = "localhost"
mpd_port = 6600

Kemal.config do |config|
config.extra_options do |parser|
parser.on("--mpd_host MPD_HOST", "MPD Host") do |opt|
mpd_host = opt
end

parser.on("--mpd_port MPD_PORT", "MPD Port") do |opt|
mpd_port = opt.to_i? || mpd_port
end
end
end

mpd_client = MPDClient.new(SOCKETS, mpd_host, mpd_port)

before_get ["/current_song", "/status", "/stats", "/playlist"] do |env|
env.response.content_type = "application/json"
Expand Down Expand Up @@ -90,7 +105,6 @@ get "/albumart" do |env|
send_file env, binary.to_slice, data["type"]
end
else

send_file env, Filesystem.get("images/record_placeholder.jpg").gets_to_end.to_slice, "image/jpeg"
end
rescue
Expand Down
4 changes: 2 additions & 2 deletions src/mpd_client.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class MPDClient
getter client

def initialize(@sockets : Array(HTTP::WebSocket))
def initialize(@sockets : Array(HTTP::WebSocket), mpd_host : String, mpd_port : Int32)
MPD::Log.level = :error
MPD::Log.backend = ::Log::IOBackend.new

@client = MPD::Client.new("localhost", 6600, with_callbacks: true)
@client = MPD::Client.new(mpd_host, mpd_port, with_callbacks: true)
# @client = MPD::Client.new("/run/mpd/socket", with_callbacks: true)
@client.callbacks_timeout = 100.milliseconds

Expand Down

0 comments on commit 17963d3

Please sign in to comment.