muzak 0.0.13 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/muzak-cmd +11 -9
- data/bin/muzak-dmenu +13 -7
- data/bin/muzakd +18 -11
- data/lib/muzak/cmd/config.rb +3 -5
- data/lib/muzak/cmd/index.rb +23 -14
- data/lib/muzak/cmd/meta.rb +9 -3
- data/lib/muzak/cmd/player.rb +49 -16
- data/lib/muzak/cmd/playlist.rb +41 -44
- data/lib/muzak/const.rb +1 -1
- data/lib/muzak/index.rb +11 -4
- data/lib/muzak/instance.rb +11 -6
- data/lib/muzak/utils.rb +10 -16
- metadata +2 -4
- data/bin/muzak +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efea3aab55cde7f64c4385e48873e81f89ba4b0f
|
4
|
+
data.tar.gz: ff90d394bdb2937280c31615f7ca84d9e1e7651f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e4182c5276d798c51cd282ba6b6f8d5524eee2577c3f5f3574cd7f96bdfcb18b2d3b12f8362c1adf21cf0e074491ada9944c64f56d9c1d9d245b34415d43346
|
7
|
+
data.tar.gz: 2827f75b69ecf2da6321ec3944647b0e9c64d2812d40b48bd76697dc999eb493e12c55b5b8e55149c3ec67e34565f310024873713a7d957e6d4a1b689c555452
|
data/bin/muzak-cmd
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "muzak"
|
4
|
+
require "socket"
|
4
5
|
|
5
6
|
def fatal(msg)
|
6
7
|
puts "Fatal: #{msg}"
|
7
8
|
exit 1
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
fatal "Unknown command." unless Muzak::Cmd.commands.include?(ARGV.first)
|
17
|
-
|
18
|
-
io.puts ARGV.join(" ")
|
11
|
+
begin
|
12
|
+
server_host = Muzak::Config.daemon_host
|
13
|
+
server_port = Muzak::Config.daemon_port
|
14
|
+
sock = TCPSocket.new server_host, server_port
|
15
|
+
rescue
|
16
|
+
fatal "Is muzakd running?"
|
19
17
|
end
|
18
|
+
|
19
|
+
sock.puts ARGV.join(" ")
|
20
|
+
puts sock.gets
|
21
|
+
sock.close
|
data/bin/muzak-dmenu
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "muzak"
|
4
|
+
require "socket"
|
4
5
|
|
5
6
|
def fatal(msg)
|
6
|
-
puts "Fatal: #{msg}"
|
7
|
+
STDERR.puts "Fatal: #{msg}"
|
7
8
|
exit 1
|
8
9
|
end
|
9
10
|
|
@@ -13,12 +14,17 @@ def dmenu(options)
|
|
13
14
|
`printf "#{opts}" | #{dmenu}`
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
begin
|
18
|
+
server_host = Muzak::Config.daemon_host
|
19
|
+
server_port = Muzak::Config.daemon_port
|
20
|
+
sock = TCPSocket.new server_host, server_port
|
21
|
+
rescue
|
22
|
+
fatal "Is muzakd running?"
|
23
|
+
end
|
19
24
|
|
20
25
|
command = dmenu Muzak::Cmd.commands
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
sock.puts command unless command.empty?
|
28
|
+
puts sock.gets
|
29
|
+
|
30
|
+
sock.close
|
data/bin/muzakd
CHANGED
@@ -2,24 +2,31 @@
|
|
2
2
|
|
3
3
|
require "muzak"
|
4
4
|
require "shellwords"
|
5
|
+
require "socket"
|
6
|
+
require "json"
|
7
|
+
require "thread"
|
5
8
|
|
6
9
|
Process.daemon unless Muzak::Config.debug || Muzak::Config.verbose
|
7
10
|
Thread.abort_on_exception = Muzak::Config.debug
|
8
11
|
|
9
12
|
muzak = Muzak::Instance.new
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
File.mkfifo(fifo_path)
|
14
|
+
server_port = Muzak::Config.daemon_port || 2669
|
15
|
+
server = TCPServer.new server_port
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
exiting = false
|
18
|
+
|
19
|
+
loop do
|
20
|
+
begin
|
21
|
+
client = server.accept
|
22
|
+
cmd_argv = Shellwords.split(client.readline)
|
18
23
|
next if cmd_argv.empty? || cmd_argv.any?(&:empty?)
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
+
raise e
|
29
|
+
ensure
|
30
|
+
client.close
|
22
31
|
end
|
23
32
|
end
|
24
|
-
|
25
|
-
File.delete(fifo_path) if File.exist?(fifo_path)
|
data/lib/muzak/cmd/config.rb
CHANGED
@@ -5,12 +5,10 @@ module Muzak
|
|
5
5
|
# Query the {Muzak::Config} for a given key.
|
6
6
|
# @command `config-get <key>`
|
7
7
|
# @cmdexample `muzak> config-get player`
|
8
|
-
def config_get(
|
9
|
-
|
10
|
-
key = args.shift
|
11
|
-
return if key.nil?
|
8
|
+
def config_get(key)
|
9
|
+
value = Config.send Utils.resolve_method(key)
|
12
10
|
|
13
|
-
|
11
|
+
build_response data: { key => value }
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
data/lib/muzak/cmd/index.rb
CHANGED
@@ -4,29 +4,32 @@ module Muzak
|
|
4
4
|
# @command `index-build`
|
5
5
|
# @cmdexample `muzak> index-build`
|
6
6
|
def index_build(*args)
|
7
|
-
warn_arity(args, 0)
|
8
|
-
|
9
7
|
verbose "building a new index, this may take a while"
|
10
8
|
|
11
9
|
index.build!
|
10
|
+
|
11
|
+
build_response data: {
|
12
|
+
artists: index.artists.size,
|
13
|
+
albums: index.albums.size
|
14
|
+
}
|
12
15
|
end
|
13
16
|
|
14
17
|
# List all artists in the index.
|
15
18
|
# @command `list-artists`
|
16
19
|
# @cmdexample `muzak> list-artists`
|
17
|
-
def list_artists
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
def list_artists
|
21
|
+
build_response data: {
|
22
|
+
artists: index.artists
|
23
|
+
}
|
21
24
|
end
|
22
25
|
|
23
26
|
# List all albums in the index.
|
24
27
|
# @command `list-albums`
|
25
28
|
# @cmdexample `muzak> list-albums`
|
26
|
-
def list_albums
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
def list_albums
|
30
|
+
build_response data: {
|
31
|
+
albums: index.album_names
|
32
|
+
}
|
30
33
|
end
|
31
34
|
|
32
35
|
# List all albums by the given artist in the index.
|
@@ -34,9 +37,12 @@ module Muzak
|
|
34
37
|
# @cmdexample `muzak> albums-by-artist Your Favorite Artist`
|
35
38
|
def albums_by_artist(*args)
|
36
39
|
artist = args.join(" ")
|
37
|
-
return if artist.nil?
|
38
40
|
|
39
|
-
|
41
|
+
albums = index.albums_by(artist).map(&:title)
|
42
|
+
|
43
|
+
build_response data: {
|
44
|
+
albums: albums
|
45
|
+
}
|
40
46
|
end
|
41
47
|
|
42
48
|
# List all songs by the given artist in the index.
|
@@ -44,9 +50,12 @@ module Muzak
|
|
44
50
|
# @cmdexample `muzak> songs-by-artist Your Next Favorite Artist`
|
45
51
|
def songs_by_artist(*args)
|
46
52
|
artist = args.join(" ")
|
47
|
-
return if artist.nil?
|
48
53
|
|
49
|
-
|
54
|
+
songs = index.songs_by(artist).map(&:title)
|
55
|
+
|
56
|
+
build_response data: {
|
57
|
+
songs: songs
|
58
|
+
}
|
50
59
|
end
|
51
60
|
end
|
52
61
|
end
|
data/lib/muzak/cmd/meta.rb
CHANGED
@@ -5,7 +5,10 @@ module Muzak
|
|
5
5
|
# @cmdexample `muzak> help`
|
6
6
|
def help(*args)
|
7
7
|
commands = Muzak::Cmd.commands.join(", ")
|
8
|
-
|
8
|
+
|
9
|
+
build_response data: {
|
10
|
+
commands: commands
|
11
|
+
}
|
9
12
|
end
|
10
13
|
|
11
14
|
# List all available plugins.
|
@@ -14,8 +17,9 @@ module Muzak
|
|
14
17
|
# @note This list will differ from loaded plugins, if not all available
|
15
18
|
# plugins are configured.
|
16
19
|
def list_plugins
|
17
|
-
|
18
|
-
|
20
|
+
build_response data: {
|
21
|
+
plugins: Plugin.plugin_names
|
22
|
+
}
|
19
23
|
end
|
20
24
|
|
21
25
|
# Terminates the muzak instance (**not** just the client).
|
@@ -24,6 +28,8 @@ module Muzak
|
|
24
28
|
def quit
|
25
29
|
verbose "muzak is quitting..."
|
26
30
|
player.deactivate!
|
31
|
+
|
32
|
+
build_response
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
data/lib/muzak/cmd/player.rb
CHANGED
@@ -11,6 +11,8 @@ module Muzak
|
|
11
11
|
end
|
12
12
|
|
13
13
|
player.activate!
|
14
|
+
|
15
|
+
build_response
|
14
16
|
end
|
15
17
|
|
16
18
|
# Deactivate the configured player.
|
@@ -22,6 +24,8 @@ module Muzak
|
|
22
24
|
|
23
25
|
# do cleanup even if the player isn't running, just in case
|
24
26
|
player.deactivate!
|
27
|
+
|
28
|
+
build_response
|
25
29
|
end
|
26
30
|
|
27
31
|
# Tell the player to begin playback.
|
@@ -29,6 +33,8 @@ module Muzak
|
|
29
33
|
# @cmdexample `muzak> play`
|
30
34
|
def play
|
31
35
|
player.play
|
36
|
+
|
37
|
+
build_response
|
32
38
|
end
|
33
39
|
|
34
40
|
# Tell the player to pause.
|
@@ -36,6 +42,8 @@ module Muzak
|
|
36
42
|
# @cmdexample `muzak> pause`
|
37
43
|
def pause
|
38
44
|
player.pause
|
45
|
+
|
46
|
+
build_response
|
39
47
|
end
|
40
48
|
|
41
49
|
# Tell the player to toggle its playback state.
|
@@ -47,6 +55,8 @@ module Muzak
|
|
47
55
|
else
|
48
56
|
player.play
|
49
57
|
end
|
58
|
+
|
59
|
+
build_response
|
50
60
|
end
|
51
61
|
|
52
62
|
# Tell the player to load the next song.
|
@@ -54,6 +64,8 @@ module Muzak
|
|
54
64
|
# @cmdexample `muzak> next`
|
55
65
|
def next
|
56
66
|
player.next_song
|
67
|
+
|
68
|
+
build_response
|
57
69
|
end
|
58
70
|
|
59
71
|
# Tell the player to load the previous song.
|
@@ -61,6 +73,8 @@ module Muzak
|
|
61
73
|
# @cmdexample `muzak> previous`
|
62
74
|
def previous
|
63
75
|
player.previous_song
|
76
|
+
|
77
|
+
build_response
|
64
78
|
end
|
65
79
|
|
66
80
|
# Tell the player to enqueue all songs by the given artist.
|
@@ -68,13 +82,15 @@ module Muzak
|
|
68
82
|
# @cmdexample `muzak> enqueue-artist Your Favorite Artist`
|
69
83
|
def enqueue_artist(*args)
|
70
84
|
artist = args.join(" ")
|
71
|
-
return if artist.nil?
|
72
|
-
|
73
85
|
albums = index.albums_by(artist)
|
74
|
-
return if albums.empty?
|
75
86
|
|
76
|
-
albums.
|
77
|
-
|
87
|
+
unless albums.empty?
|
88
|
+
albums.each do |album|
|
89
|
+
player.enqueue_album album
|
90
|
+
end
|
91
|
+
build_response
|
92
|
+
else
|
93
|
+
build_response error: "no albums by: '#{artist}'"
|
78
94
|
end
|
79
95
|
end
|
80
96
|
|
@@ -83,30 +99,39 @@ module Muzak
|
|
83
99
|
# @cmdexample `muzak> enqueue-album Your Favorite Album`
|
84
100
|
def enqueue_album(*args)
|
85
101
|
album_name = args.join(" ")
|
86
|
-
return if album_name.nil?
|
87
102
|
|
88
103
|
album = index.albums[album_name]
|
89
|
-
return if album.nil?
|
90
104
|
|
91
|
-
|
105
|
+
if album
|
106
|
+
player.enqueue_album album
|
107
|
+
build_response
|
108
|
+
else
|
109
|
+
build_response error: "no such album: '#{album_name}'"
|
110
|
+
end
|
92
111
|
end
|
93
112
|
|
94
113
|
# Tell the player to load the given number of random songs.
|
95
114
|
# @command `jukebox [count]`
|
96
115
|
# @cmdexample `muzak> jukebox 150`
|
97
|
-
def jukebox(
|
98
|
-
count = args.shift || Config.jukebox_size
|
99
|
-
|
116
|
+
def jukebox(count = Config.jukebox_size)
|
100
117
|
songs = index.jukebox(count.to_i)
|
101
118
|
|
102
|
-
|
119
|
+
Thread.new do
|
120
|
+
songs.each { |s| player.enqueue_song s }
|
121
|
+
end
|
122
|
+
|
123
|
+
build_response data: {
|
124
|
+
jukebox: songs.map(&:full_title)
|
125
|
+
}
|
103
126
|
end
|
104
127
|
|
105
128
|
# Tell the player to list its internal queue.
|
106
129
|
# @command `list-queue`
|
107
130
|
# @cmdexample `muzak> list-queue`
|
108
131
|
def list_queue
|
109
|
-
|
132
|
+
build_response data: {
|
133
|
+
queue: player.list_queue.map(&:title)
|
134
|
+
}
|
110
135
|
end
|
111
136
|
|
112
137
|
# Tell the player to shuffle its internal queue.
|
@@ -114,6 +139,8 @@ module Muzak
|
|
114
139
|
# @cmdexample `muzak> shuffle-queue`
|
115
140
|
def shuffle_queue
|
116
141
|
player.shuffle_queue
|
142
|
+
|
143
|
+
build_response
|
117
144
|
end
|
118
145
|
|
119
146
|
# Tell the player to clear its internal queue.
|
@@ -122,15 +149,21 @@ module Muzak
|
|
122
149
|
# @note This does not (usually) stop the current song.
|
123
150
|
def clear_queue
|
124
151
|
player.clear_queue
|
152
|
+
|
153
|
+
build_response
|
125
154
|
end
|
126
155
|
|
127
156
|
# Retrieve the currently playing song from the player and print it.
|
128
157
|
# @command `now-playing`
|
129
158
|
# @cmdexample `muzak> now-playing`
|
130
159
|
def now_playing
|
131
|
-
|
132
|
-
|
133
|
-
|
160
|
+
if player.playing?
|
161
|
+
build_response data: {
|
162
|
+
playing: player.now_playing.full_title
|
163
|
+
}
|
164
|
+
else
|
165
|
+
build_response error: "no currently playing song"
|
166
|
+
end
|
134
167
|
end
|
135
168
|
end
|
136
169
|
end
|
data/lib/muzak/cmd/playlist.rb
CHANGED
@@ -3,100 +3,97 @@ module Muzak
|
|
3
3
|
# List all currently available playlists.
|
4
4
|
# @command `list-playlists`
|
5
5
|
# @cmdexample `muzak> list-playlists`
|
6
|
-
def list_playlists
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def list_playlists
|
7
|
+
build_response data: {
|
8
|
+
playlists: Playlist.playlist_names
|
9
|
+
}
|
10
10
|
end
|
11
11
|
|
12
12
|
# Delete the given playlist.
|
13
13
|
# @command `playlist-delete <playlist>`
|
14
14
|
# @cmdexample `muzak> playlist-delete favorites`
|
15
|
-
def playlist_delete(
|
16
|
-
fail_arity(args, 1)
|
17
|
-
pname = args.shift
|
18
|
-
|
15
|
+
def playlist_delete(pname)
|
19
16
|
debug "deleting playist '#{pname}'"
|
20
17
|
|
21
18
|
Playlist.delete!(pname)
|
22
19
|
playlists[pname] = nil
|
20
|
+
|
21
|
+
build_response
|
23
22
|
end
|
24
23
|
|
25
24
|
# Add the given playlist to the player's queue.
|
26
25
|
# @command `enqueue-playlist <playlist>`
|
27
26
|
# @cmdexample `muzak> enqueue-playlist favorites`
|
28
|
-
def enqueue_playlist(
|
29
|
-
fail_arity(args, 1)
|
30
|
-
pname = args.shift
|
31
|
-
|
27
|
+
def enqueue_playlist(pname)
|
32
28
|
player.enqueue_playlist(playlists[pname])
|
33
29
|
event :playlist_enqueued, playlists[pname]
|
30
|
+
|
31
|
+
build_response
|
34
32
|
end
|
35
33
|
|
36
34
|
# Add the given album to the given playlist.
|
37
35
|
# @command `playlist-add-album <playlist> <album name>`
|
38
36
|
# @cmdexample `muzak> playlist-add-album favorites Your Favorite Album`
|
39
|
-
def playlist_add_album(*args)
|
40
|
-
pname = args.shift
|
41
|
-
return if pname.nil?
|
42
|
-
|
37
|
+
def playlist_add_album(pname, *args)
|
43
38
|
album_name = args.join(" ")
|
44
|
-
return if album_name.nil?
|
45
|
-
|
46
39
|
album = index.albums[album_name]
|
47
|
-
return if album.nil?
|
48
40
|
|
49
|
-
|
41
|
+
if album
|
42
|
+
playlists[pname].add(album.songs)
|
43
|
+
build_response
|
44
|
+
else
|
45
|
+
build_response error: "no such album: '#{album_name}'"
|
46
|
+
end
|
50
47
|
end
|
51
48
|
|
52
49
|
# Add the given artist to the given playlist.
|
53
50
|
# @command `playlist-add-artist <playlist> <artist name>`
|
54
51
|
# @cmdexample `muzak> playlist-add-artist dad-rock The Rolling Stones`
|
55
|
-
def playlist_add_artist(*args)
|
56
|
-
pname = args.shift
|
57
|
-
return if pname.nil?
|
58
|
-
|
52
|
+
def playlist_add_artist(pname, *args)
|
59
53
|
artist = args.join(" ")
|
60
|
-
|
54
|
+
songs = index.songs_by(artist)
|
61
55
|
|
62
|
-
|
56
|
+
unless songs.empty?
|
57
|
+
playlists[pname].add(songs)
|
58
|
+
build_response
|
59
|
+
else
|
60
|
+
build_response error: "no songs by artist: '#{artist}'"
|
61
|
+
end
|
63
62
|
end
|
64
63
|
|
65
64
|
# Add the currently playing song to the given playlist.
|
66
65
|
# @see Muzak::Player::StubPlayer#now_playing
|
67
66
|
# @command `playlist-add-current <playlist>`
|
68
67
|
# @cmdexample `muzak> playlist-add-current favorites`
|
69
|
-
def playlist_add_current(
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
def playlist_add_current(pname)
|
69
|
+
if player.running?
|
70
|
+
playlists[pname].add player.now_playing
|
71
|
+
build_response
|
72
|
+
else
|
73
|
+
build_response error: "the player is not running"
|
74
|
+
end
|
76
75
|
end
|
77
76
|
|
78
77
|
# Deletes the currently playing song from the given playlist.
|
79
78
|
# @see Muzak::Player::StubPlayer#now_playing
|
80
79
|
# @command `playlist-del-current <playlist>`
|
81
80
|
# @cmdexample `muzak> playlist-del-current favorites`
|
82
|
-
def playlist_del_current(
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
81
|
+
def playlist_del_current(pname)
|
82
|
+
if player.running?
|
83
|
+
playlists[pname].delete player.now_playing
|
84
|
+
build_response
|
85
|
+
else
|
86
|
+
build_response error: "the player is not running"
|
87
|
+
end
|
89
88
|
end
|
90
89
|
|
91
90
|
# Shuffle the given playlist.
|
92
91
|
# @see Muzak::Playlist#shuffle!
|
93
92
|
# @command `playlist-shuffle <playlist>`
|
94
93
|
# @cmdexample `muzak> playlist-shuffle dad-rock`
|
95
|
-
def playlist_shuffle(
|
96
|
-
pname = args.shift
|
97
|
-
return if pname.nil?
|
98
|
-
|
94
|
+
def playlist_shuffle(pname)
|
99
95
|
playlists[pname].shuffle!
|
96
|
+
build_response
|
100
97
|
end
|
101
98
|
end
|
102
99
|
end
|
data/lib/muzak/const.rb
CHANGED
data/lib/muzak/index.rb
CHANGED
@@ -18,10 +18,11 @@ module Muzak
|
|
18
18
|
|
19
19
|
# @param tree [String] the root to begin indexing from
|
20
20
|
# @param deep [Boolean] whether to build a "deep" index
|
21
|
+
# @param sync [Boolean] whether or not to save to {Muzak::INDEX_FILE}
|
21
22
|
# @note if the index ({Muzak::INDEX_FILE}) already exists and is not
|
22
23
|
# outdated, no building is performed.
|
23
24
|
# @see #build!
|
24
|
-
def initialize(tree, deep: false)
|
25
|
+
def initialize(tree, deep: false, sync: true)
|
25
26
|
@tree = tree
|
26
27
|
@deep = deep
|
27
28
|
|
@@ -31,17 +32,23 @@ module Muzak
|
|
31
32
|
return unless outdated?
|
32
33
|
end
|
33
34
|
|
34
|
-
build!
|
35
|
+
build!(sync)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Synchronize the in-memory index hash with {Muzak::INDEX_FILE}.
|
39
|
+
def sync!
|
40
|
+
File.open(INDEX_FILE, "w") { |io| io.write Marshal::dump @hash }
|
35
41
|
end
|
36
42
|
|
37
43
|
# (Re)builds and saves the index ({Muzak::INDEX_FILE}) to disk.
|
44
|
+
# @param sync [Boolean] whether or not to save to {Muzak::INDEX_FILE}
|
38
45
|
# @note This method can be expensive.
|
39
|
-
def build!
|
46
|
+
def build!(sync: true)
|
40
47
|
@hash = build_index_hash!
|
41
48
|
|
42
49
|
debug "indexed #{albums.length} albums by #{artists.length} artists"
|
43
50
|
|
44
|
-
|
51
|
+
sync! if sync
|
45
52
|
end
|
46
53
|
|
47
54
|
# @return [Boolean] whether or not the current index is deep
|
data/lib/muzak/instance.rb
CHANGED
@@ -11,12 +11,17 @@ module Muzak
|
|
11
11
|
# instance.command "enqueue-playlist", "favorites"
|
12
12
|
# instance.command "pause"
|
13
13
|
def command(cmd, *args)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
if Cmd.commands.include?(cmd)
|
15
|
+
meth = method(Utils.resolve_command(cmd))
|
16
|
+
if meth.arity == args.size || meth.arity <= -1
|
17
|
+
meth.call *args
|
18
|
+
else
|
19
|
+
build_response error: "got #{args.size} args, needed #{meth.arity}"
|
20
|
+
end
|
21
|
+
else
|
22
|
+
warn "unknown command: '#{cmd}'"
|
23
|
+
build_response error: "unknown command '#{cmd}'"
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
# @return [Index] the instance's music index
|
data/lib/muzak/utils.rb
CHANGED
@@ -115,22 +115,16 @@ module Muzak
|
|
115
115
|
output pretty(:blue, "verbose"), args
|
116
116
|
end
|
117
117
|
|
118
|
-
#
|
119
|
-
#
|
120
|
-
# @param
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
# equals the expected arity.
|
129
|
-
# @param args [Array<String>] the arguments
|
130
|
-
# @param arity [Integer] the expected arity
|
131
|
-
# @return [void]
|
132
|
-
def fail_arity(args, arity)
|
133
|
-
error "needed #{arity} arguments, got #{args.length}" unless args.length == arity
|
118
|
+
# Returns a response hash containing the given data and error.
|
119
|
+
# @param error [String] the error string, if needed
|
120
|
+
# @param data [String, Hash] the data, if needed
|
121
|
+
def build_response(error: nil, data: nil)
|
122
|
+
{ response: {
|
123
|
+
error: error,
|
124
|
+
data: data,
|
125
|
+
method: caller_locations.first.label
|
126
|
+
}
|
127
|
+
}
|
134
128
|
end
|
135
129
|
end
|
136
130
|
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.0
|
4
|
+
version: 0.1.0
|
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-
|
11
|
+
date: 2016-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: taglib-ruby
|
@@ -27,7 +27,6 @@ dependencies:
|
|
27
27
|
description: A library for controlling playlists and media players.
|
28
28
|
email: william@tuffbizz.com
|
29
29
|
executables:
|
30
|
-
- muzak
|
31
30
|
- muzakd
|
32
31
|
- muzak-cmd
|
33
32
|
- muzak-dmenu
|
@@ -37,7 +36,6 @@ files:
|
|
37
36
|
- ".yardopts"
|
38
37
|
- LICENSE
|
39
38
|
- README.md
|
40
|
-
- bin/muzak
|
41
39
|
- bin/muzak-cmd
|
42
40
|
- bin/muzak-dmenu
|
43
41
|
- bin/muzakd
|
data/bin/muzak
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "muzak"
|
4
|
-
require "readline"
|
5
|
-
require "shellwords"
|
6
|
-
|
7
|
-
Thread.abort_on_exception = Muzak::Config.debug
|
8
|
-
|
9
|
-
muzak = Muzak::Instance.new
|
10
|
-
|
11
|
-
COMMANDS = Muzak::Cmd.commands
|
12
|
-
|
13
|
-
CONFIG_REGEX = /^config-(get)|(set)|(del)/
|
14
|
-
ARTIST_REGEX = Regexp.union COMMANDS.select{ |c| c =~ /artist/ }.map { |c| /^#{c}/ }
|
15
|
-
ALBUM_REGEX = Regexp.union COMMANDS.select{ |c| c =~ /album/ }.map { |c| /^#{c}/ }
|
16
|
-
PLAYLIST_REGEX = /^playlist-delete/
|
17
|
-
|
18
|
-
comp = proc do |s|
|
19
|
-
case Readline.line_buffer
|
20
|
-
when CONFIG_REGEX
|
21
|
-
muzak.config.keys.grep(Regexp.new(Regexp.escape(s)))
|
22
|
-
when ARTIST_REGEX
|
23
|
-
ss = Readline.line_buffer.split(" ")
|
24
|
-
muzak.index.artists.grep(Regexp.new(Regexp.escape(ss[1..-1].join(" "))))
|
25
|
-
when ALBUM_REGEX
|
26
|
-
muzak.index.album_names.grep(Regexp.new(Regexp.escape(s)))
|
27
|
-
when PLAYLIST_REGEX
|
28
|
-
Muzak::Playlist.playlist_names.grep(Regexp.new(Regexp.escape(s)))
|
29
|
-
else
|
30
|
-
COMMANDS.grep(Regexp.new(Regexp.escape(s)))
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
Readline.completion_append_character = " "
|
35
|
-
Readline.completion_proc = comp
|
36
|
-
|
37
|
-
# ignore interrupts
|
38
|
-
trap("INT", "SIG_IGN")
|
39
|
-
|
40
|
-
while line = Readline.readline("muzak> ", true)
|
41
|
-
cmd_argv = Shellwords.split(line) rescue next
|
42
|
-
next if cmd_argv.empty? || cmd_argv.any?(&:empty?)
|
43
|
-
cmd = cmd_argv.shift
|
44
|
-
muzak.command cmd, *cmd_argv
|
45
|
-
break if cmd == "quit"
|
46
|
-
end
|