Module: Muzak::Cmd
- Included in:
- Instance
- Defined in:
- lib/muzak/cmd.rb,
lib/muzak/cmd/meta.rb,
lib/muzak/cmd/index.rb,
lib/muzak/cmd/config.rb,
lib/muzak/cmd/player.rb,
lib/muzak/cmd/playlist.rb
Overview
The namespace for all commands exposed by muzak.
Class Method Summary collapse
-
.commands ⇒ Array<String>
All valid muzak commands.
Instance Method Summary collapse
-
#albums_by_artist(*args) ⇒ Object
List all albums by the given artist in the index.
-
#clear_queue ⇒ Object
Tell the player to clear its internal queue.
-
#config_get(key) ⇒ Object
Query the Config for a given key.
-
#dump_index ⇒ Object
Dump a hash representation of the index.
-
#enqueue_album(*args) ⇒ Object
Tell the player to enqueue the given album.
-
#enqueue_artist(*args) ⇒ Object
Tell the player to enqueue all songs by the given artist.
-
#enqueue_playlist(pname) ⇒ Object
Add the given playlist to the player's queue.
-
#help(*args) ⇒ Object
Return a "helpful" listing of commands.
-
#jukebox(count = Config.jukebox_size) ⇒ Object
Tell the player to load the given number of random songs.
-
#list_albums ⇒ Object
List all albums in the index.
-
#list_artists ⇒ Object
List all artists in the index.
-
#list_playlists ⇒ Object
List all currently available playlists.
-
#list_plugins ⇒ Object
List all available plugins.
-
#list_queue ⇒ Object
Tell the player to list its internal queue.
-
#next ⇒ Object
Tell the player to load the next song.
-
#now_playing ⇒ Object
Retrieve the currently playing song from the player and print it.
-
#pause ⇒ Object
Tell the player to pause.
-
#ping ⇒ Object
Return a simple heartbeat message.
-
#play ⇒ Object
Tell the player to begin playback.
-
#player_activate ⇒ Object
Activate the configured player.
-
#player_deactivate ⇒ Object
Deactivate the configured player.
-
#playlist_add_album(pname, *args) ⇒ Object
Add the given album to the given playlist.
-
#playlist_add_artist(pname, *args) ⇒ Object
Add the given artist to the given playlist.
-
#playlist_add_current(pname) ⇒ Object
Add the currently playing song to the given playlist.
-
#playlist_del_current(pname) ⇒ Object
Deletes the currently playing song from the given playlist.
-
#playlist_delete(pname) ⇒ Object
Delete the given playlist.
-
#playlist_shuffle(pname) ⇒ Object
Shuffle the given playlist.
-
#previous ⇒ Object
Tell the player to load the previous song.
-
#quit ⇒ Object
Terminates the muzak instance (not just the client).
-
#reload_index ⇒ Object
Reload the active index from the index file.
-
#shuffle_queue ⇒ Object
Tell the player to shuffle its internal queue.
-
#songs_by_artist(*args) ⇒ Object
List all songs by the given artist in the index.
-
#toggle ⇒ Object
Tell the player to toggle its playback state.
Class Method Details
.commands ⇒ Array<String>
Returns all valid muzak commands.
11 12 13 14 |
# File 'lib/muzak/cmd.rb', line 11 def self.commands commands = instance_methods.map(&:to_s).reject { |m| m.start_with?("_") } commands.map { |c| Config.resolve_method c } end |
Instance Method Details
#albums_by_artist(*args) ⇒ Object
List all albums by the given artist in the index.
47 48 49 50 51 52 53 54 55 |
# File 'lib/muzak/cmd/index.rb', line 47 def albums_by_artist(*args) artist = args.join(" ") albums = index.albums_by(artist).map(&:title) build_response data: { albums: albums } end |
#clear_queue ⇒ Object
This does not (usually) stop the current song.
Tell the player to clear its internal queue.
151 152 153 154 155 |
# File 'lib/muzak/cmd/player.rb', line 151 def clear_queue player.clear_queue build_response end |
#config_get(key) ⇒ Object
Query the Muzak::Config for a given key.
8 9 10 11 12 |
# File 'lib/muzak/cmd/config.rb', line 8 def config_get(key) value = Config.send Config.resolve_command(key) build_response data: { key => value } end |
#dump_index ⇒ Object
Dump a hash representation of the index.
20 21 22 23 24 |
# File 'lib/muzak/cmd/index.rb', line 20 def dump_index build_response data: { index: index.hash } end |
#enqueue_album(*args) ⇒ Object
Tell the player to enqueue the given album.
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/muzak/cmd/player.rb', line 103 def enqueue_album(*args) album_name = args.join(" ") album = index.albums[album_name] if album player.enqueue_album album build_response else build_response error: "no such album: '#{album_name}'" end end |
#enqueue_artist(*args) ⇒ Object
Tell the player to enqueue all songs by the given artist.
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/muzak/cmd/player.rb', line 86 def enqueue_artist(*args) artist = args.join(" ") albums = index.albums_by(artist) unless albums.empty? albums.each do |album| player.enqueue_album album end build_response else build_response error: "no albums by: '#{artist}'" end end |
#enqueue_playlist(pname) ⇒ Object
Add the given playlist to the player's queue.
27 28 29 30 31 32 |
# File 'lib/muzak/cmd/playlist.rb', line 27 def enqueue_playlist(pname) player.enqueue_playlist(playlists[pname]) event :playlist_enqueued, playlists[pname] build_response end |
#help(*args) ⇒ Object
Return a "helpful" listing of commands.
18 19 20 21 22 |
# File 'lib/muzak/cmd/meta.rb', line 18 def help(*args) build_response data: { commands: Muzak::Cmd.commands } end |
#jukebox(count = Config.jukebox_size) ⇒ Object
Tell the player to load the given number of random songs.
119 120 121 122 123 124 125 126 127 |
# File 'lib/muzak/cmd/player.rb', line 119 def jukebox(count = Config.jukebox_size) songs = index.jukebox(count.to_i) songs.each { |s| player.enqueue_song s } build_response data: { jukebox: songs.map(&:full_title) } end |
#list_albums ⇒ Object
List all albums in the index.
38 39 40 41 42 |
# File 'lib/muzak/cmd/index.rb', line 38 def list_albums build_response data: { albums: index.album_names } end |
#list_artists ⇒ Object
List all artists in the index.
29 30 31 32 33 |
# File 'lib/muzak/cmd/index.rb', line 29 def list_artists build_response data: { artists: index.artists } end |
#list_playlists ⇒ Object
List all currently available playlists.
6 7 8 9 10 |
# File 'lib/muzak/cmd/playlist.rb', line 6 def list_playlists build_response data: { playlists: Playlist.playlist_names } end |
#list_plugins ⇒ Object
This list will differ from loaded plugins, if not all available plugins are configured.
List all available plugins.
29 30 31 32 33 |
# File 'lib/muzak/cmd/meta.rb', line 29 def list_plugins build_response data: { plugins: Plugin.plugin_names } end |
#list_queue ⇒ Object
Tell the player to list its internal queue.
132 133 134 135 136 |
# File 'lib/muzak/cmd/player.rb', line 132 def list_queue build_response data: { queue: player.list_queue.map(&:title) } end |
#next ⇒ Object
Tell the player to load the next song.
68 69 70 71 72 |
# File 'lib/muzak/cmd/player.rb', line 68 def next player.next_song build_response end |
#now_playing ⇒ Object
Retrieve the currently playing song from the player and print it.
160 161 162 163 164 165 166 167 168 |
# File 'lib/muzak/cmd/player.rb', line 160 def if player. build_response data: { playing: player.&.full_title } else build_response error: "no currently playing song" end end |
#pause ⇒ Object
Tell the player to pause.
46 47 48 49 50 |
# File 'lib/muzak/cmd/player.rb', line 46 def pause player.pause build_response end |
#ping ⇒ Object
Return a simple heartbeat message.
6 7 8 9 10 11 12 13 |
# File 'lib/muzak/cmd/meta.rb', line 6 def ping = Time.now.to_i debug "pong: #{}" build_response data: { pong: } end |
#play ⇒ Object
Tell the player to begin playback.
37 38 39 40 41 |
# File 'lib/muzak/cmd/player.rb', line 37 def play player.play build_response end |
#player_activate ⇒ Object
Many playback commands will automatically activate the player.
Activate the configured player.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/muzak/cmd/player.rb', line 7 def player_activate if player.running? danger "player is already running" else player.activate! end build_response data: { player: player.class.name } end |
#player_deactivate ⇒ Object
Deactivating the player (usually) ends playback immediately.
Deactivate the configured player.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/muzak/cmd/player.rb', line 23 def player_deactivate danger "player is not running" unless player.running? # do cleanup even if the player isn't running, just in case player.deactivate! build_response data: { player: player.class.name } end |
#playlist_add_album(pname, *args) ⇒ Object
Add the given album to the given playlist.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/muzak/cmd/playlist.rb', line 37 def playlist_add_album(pname, *args) album_name = args.join(" ") album = index.albums[album_name] if album playlists[pname].add(album.songs) build_response else build_response error: "no such album: '#{album_name}'" end end |
#playlist_add_artist(pname, *args) ⇒ Object
Add the given artist to the given playlist.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/muzak/cmd/playlist.rb', line 52 def playlist_add_artist(pname, *args) artist = args.join(" ") songs = index.songs_by(artist) unless songs.empty? playlists[pname].add(songs) build_response else build_response error: "no songs by artist: '#{artist}'" end end |
#playlist_add_current(pname) ⇒ Object
Add the currently playing song to the given playlist.
68 69 70 71 72 73 74 75 |
# File 'lib/muzak/cmd/playlist.rb', line 68 def playlist_add_current(pname) if player.running? playlists[pname].add player. build_response else build_response error: "the player is not running" end end |
#playlist_del_current(pname) ⇒ Object
Deletes the currently playing song from the given playlist.
81 82 83 84 85 86 87 88 |
# File 'lib/muzak/cmd/playlist.rb', line 81 def playlist_del_current(pname) if player.running? playlists[pname].delete player. build_response else build_response error: "the player is not running" end end |
#playlist_delete(pname) ⇒ Object
Delete the given playlist.
15 16 17 18 19 20 21 22 |
# File 'lib/muzak/cmd/playlist.rb', line 15 def playlist_delete(pname) debug "deleting playist '#{pname}'" Playlist.delete!(pname) playlists[pname] = nil build_response end |
#playlist_shuffle(pname) ⇒ Object
Shuffle the given playlist.
94 95 96 97 |
# File 'lib/muzak/cmd/playlist.rb', line 94 def playlist_shuffle(pname) playlists[pname].shuffle! build_response end |
#previous ⇒ Object
Tell the player to load the previous song.
77 78 79 80 81 |
# File 'lib/muzak/cmd/player.rb', line 77 def previous player.previous_song build_response end |
#quit ⇒ Object
Terminates the muzak instance (not just the client).
38 39 40 41 42 43 44 |
# File 'lib/muzak/cmd/meta.rb', line 38 def quit verbose "muzak is quitting..." player.deactivate! event :instance_quitting build_response data: "quitting" end |
#reload_index ⇒ Object
This does not rebuild the index.
Reload the active index from the index file.
7 8 9 10 11 12 13 14 15 |
# File 'lib/muzak/cmd/index.rb', line 7 def reload_index index.reload! build_response data: { artist_count: index.artists.size, album_count: index.albums.size, deep: index.deep?, } end |
#shuffle_queue ⇒ Object
Tell the player to shuffle its internal queue.
141 142 143 144 145 |
# File 'lib/muzak/cmd/player.rb', line 141 def shuffle_queue player.shuffle_queue build_response end |
#songs_by_artist(*args) ⇒ Object
List all songs by the given artist in the index.
60 61 62 63 64 65 66 67 68 |
# File 'lib/muzak/cmd/index.rb', line 60 def songs_by_artist(*args) artist = args.join(" ") songs = index.songs_by(artist).map(&:title) build_response data: { songs: songs } end |
#toggle ⇒ Object
Tell the player to toggle its playback state.
55 56 57 58 59 60 61 62 63 |
# File 'lib/muzak/cmd/player.rb', line 55 def toggle if player. player.pause else player.play end build_response end |