muzak 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77ec08814fbae77829d95ec84d85548eaac56e8f
4
- data.tar.gz: c2fd8434c2c313cd9260c9f4a9f6ce6cd1208bb5
3
+ metadata.gz: faf36636905a8835a68aaa8ec30165784542ee9f
4
+ data.tar.gz: a70897b4fb5b8531bb218345e7d10c535e9e1531
5
5
  SHA512:
6
- metadata.gz: 91eaf44a796913f92e3dc0a2f9d98b3e934492ace722bc240216d4918ff5ee1d26f814a589e49b08214d4593c6a165da8a328abeab069447fa40d1759030be33
7
- data.tar.gz: be43e3eaba0dbf5891923054602fbcc2cc0c4dabcd4f609990c6e144de946a059a3b46a025014aec6acfc8649f7014ac996114d4a54ae345c5b8a3034adf6f25
6
+ metadata.gz: afb580f66f98918d8cf11f2732e5b73614288c8f1a3b189b73280d0410b993665b518837f40f3c5624ae3a4442027664b8d8d3faf254581203a8425469ddc396
7
+ data.tar.gz: 7380f4e9d0433443acbf791e5b99461d597a9a57900ea4cb9bfd471db5c4c61c51f5e7da86bd1d71dd0db6691de9a26afaf27461b797367f348e5ded00164702
data/.yardopts CHANGED
@@ -1 +1 @@
1
- --tag command:"muzak command" --tag cmdexample:"example invocation" --no-private --markup-provider=redcarpet --markup=markdown - README.md LICENSE
1
+ --tag command:"muzak command" --tag cmdexample:"example invocation" --no-private --markup-provider=redcarpet --markup=markdown - README.md COMMANDS.md LICENSE
data/README.md CHANGED
@@ -15,19 +15,9 @@ and the state of the player.
15
15
 
16
16
  Muzak is still a work in process. Don't expect stability or pleasant output.
17
17
 
18
- On the command-line:
19
-
20
- ```shell
21
- $ ruby -Ilib bin/muzak.rb
22
- muzak> help
23
- ```
24
-
25
- Daemonized:
26
-
27
18
  ```shell
28
19
  $ ruby -Ilib bin/muzakd.rb
29
- $ echo "command" > ~/.config/muzak/muzak.fifo
30
- $ ruby -Ilib bin/muzak-cmd "command"
20
+ $ ruby -Ilib bin/muzak-cmd enqueue-artist "The Beatles"
31
21
  ```
32
22
 
33
23
  ### TODO
@@ -35,5 +25,3 @@ $ ruby -Ilib bin/muzak-cmd "command"
35
25
  * GUI "frontend"?
36
26
  * isolation of art and music output (`Muzak::ArtProvider`?)
37
27
  * current indexing/sorting logic is terrible
38
- * all the documentation
39
- * readline's tab complete is terrible with spaces (maybe use `bond`?)
@@ -3,6 +3,7 @@
3
3
  require "muzak"
4
4
  require "socket"
5
5
  require "json"
6
+ require "shellwords"
6
7
 
7
8
  begin
8
9
  server_host = Muzak::Config.daemon_host
@@ -14,6 +15,6 @@ rescue
14
15
  exit 1
15
16
  end
16
17
 
17
- sock.puts ARGV.join(" ")
18
+ sock.puts Shellwords.shelljoin ARGV
18
19
  puts sock.gets
19
20
  sock.close
data/bin/muzakd CHANGED
@@ -14,18 +14,16 @@ muzak = Muzak::Instance.new
14
14
  server_port = Muzak::Config.daemon_port || 2669
15
15
  server = TCPServer.new server_port
16
16
 
17
- exiting = false
18
-
19
17
  loop do
20
- begin
21
- client = server.accept
22
- cmd_argv = Shellwords.split(client.readline)
23
- next if cmd_argv.empty? || cmd_argv.any?(&:empty?)
24
- client.puts(muzak.command(*cmd_argv).to_json)
25
- break if cmd_argv.first == "quit"
26
- rescue Exception => e
27
- client.puts({ error: e.to_s }.to_json)
28
- ensure
29
- client.close if client
18
+ Thread.new(server.accept) do |client|
19
+ begin
20
+ cmd_argv = Shellwords.split(client.readline)
21
+ client.puts(muzak.command(*cmd_argv).to_json)
22
+ exit! 0 if cmd_argv.first == "quit"
23
+ rescue Exception => e
24
+ client.puts({ response: { error: e.to_s } }.to_json)
25
+ ensure
26
+ client.close if client
27
+ end
30
28
  end
31
29
  end
@@ -1,6 +1,8 @@
1
1
  Dir.glob(File.join(__dir__, "cmd/*")) { |f| require_relative f }
2
2
 
3
3
  module Muzak
4
+ # The namespace for all commands exposed by muzak.
5
+ # @see file:COMMANDS.md User Commands
4
6
  module Cmd
5
7
  # load commands included by the user
6
8
  Dir.glob(File.join(USER_COMMAND_DIR, "*")) { |file| require file }
@@ -6,7 +6,7 @@ module Muzak
6
6
  # @command `config-get <key>`
7
7
  # @cmdexample `muzak> config-get player`
8
8
  def config_get(key)
9
- value = Config.send Utils.resolve_method(key)
9
+ value = Config.send Utils.resolve_command(key)
10
10
 
11
11
  build_response data: { key => value }
12
12
  end
@@ -1,13 +1,23 @@
1
1
  module Muzak
2
2
  module Cmd
3
- # Print a "helpful" listing of commands.
3
+ # Return a simple heartbeat message.
4
+ # @command `ping`
5
+ # @cmdexample `muzak> ping`
6
+ def ping
7
+ timestamp = Time.now.to_i
8
+ debug "pong: #{timestamp}"
9
+
10
+ build_response data: {
11
+ pong: timestamp
12
+ }
13
+ end
14
+
15
+ # Return a "helpful" listing of commands.
4
16
  # @command `help`
5
17
  # @cmdexample `muzak> help`
6
18
  def help(*args)
7
- commands = Muzak::Cmd.commands.join(", ")
8
-
9
19
  build_response data: {
10
- commands: commands
20
+ commands: Muzak::Cmd.commands
11
21
  }
12
22
  end
13
23
 
@@ -29,7 +39,7 @@ module Muzak
29
39
  verbose "muzak is quitting..."
30
40
  player.deactivate!
31
41
 
32
- build_response
42
+ build_response data: "quitting"
33
43
  end
34
44
  end
35
45
  end
@@ -7,12 +7,13 @@ module Muzak
7
7
  def player_activate
8
8
  if player.running?
9
9
  warn "player is already running"
10
- return
10
+ else
11
+ player.activate!
11
12
  end
12
13
 
13
- player.activate!
14
-
15
- build_response
14
+ build_response data: {
15
+ player: player.class.name
16
+ }
16
17
  end
17
18
 
18
19
  # Deactivate the configured player.
@@ -25,7 +26,9 @@ module Muzak
25
26
  # do cleanup even if the player isn't running, just in case
26
27
  player.deactivate!
27
28
 
28
- build_response
29
+ build_response data: {
30
+ player: player.class.name
31
+ }
29
32
  end
30
33
 
31
34
  # Tell the player to begin playback.
@@ -1,6 +1,6 @@
1
1
  module Muzak
2
2
  # Muzak's current version
3
- VERSION = "0.1.1".freeze
3
+ VERSION = "0.1.2".freeze
4
4
 
5
5
  # The root directory for all user configuration, data, etc
6
6
  CONFIG_DIR = File.expand_path("~/.config/muzak").freeze
@@ -161,6 +161,9 @@ module Muzak
161
161
  playlist = []
162
162
 
163
163
  entries.times do |i|
164
+ # TODO: this is slow and should be avoided at all costs,
165
+ # since we have access to these Song instances earlier
166
+ # in the object's lifecycle.
164
167
  playlist << Song.new(get_property("playlist/#{i}/filename"))
165
168
  end
166
169
 
@@ -184,11 +187,11 @@ module Muzak
184
187
  end
185
188
 
186
189
  # Get mpv's currently playing song.
187
- # @return [Song] the currently playing song
190
+ # @return [Song, nil] the currently playing song
188
191
  def now_playing
189
- return unless running? && playing?
192
+ return unless playing?
190
193
 
191
- Song.new(get_property "path")
194
+ @_now_playing ||= Song.new(get_property "path")
192
195
  end
193
196
 
194
197
  private
@@ -232,17 +235,10 @@ module Muzak
232
235
  Thread.new do
233
236
  case event
234
237
  when "file-loaded"
235
- # this really isn't ideal, since we already have access
236
- # to Song objects earlier in the object's lifetime.
237
- # the "correct" way to do this would be to sync an external
238
- # playlist with mpv's internal one and access that instead
239
- # of re-creating the Song from mpv properties.
240
- # another idea: serialize Song objects into mpv's properties
241
- # somehow.
242
- song = Song.new(get_property "path")
243
- instance.event :song_loaded, song
238
+ instance.event :song_loaded, now_playing
244
239
  when "end-file"
245
240
  instance.event :song_unloaded
241
+ @_now_playing = nil
246
242
  end
247
243
  end
248
244
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muzak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-31 00:00:00.000000000 Z
11
+ date: 2017-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby