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.
13 14 15 16 |
# File 'lib/muzak/cmd.rb', line 13 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.
49 50 51 52 53 54 55 56 57 |
# File 'lib/muzak/cmd/index.rb', line 49 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.
152 153 154 155 156 |
# File 'lib/muzak/cmd/player.rb', line 152 def clear_queue player.clear_queue build_response end |
#config_get(key) ⇒ Object
Query the Muzak::Config for a given key.
10 11 12 13 14 |
# File 'lib/muzak/cmd/config.rb', line 10 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.
22 23 24 25 26 |
# File 'lib/muzak/cmd/index.rb', line 22 def dump_index build_response data: { index: index.hash, } end |
#enqueue_album(*args) ⇒ Object
Tell the player to enqueue the given album.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/muzak/cmd/player.rb', line 105 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.
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/muzak/cmd/player.rb', line 88 def enqueue_artist(*args) artist = args.join(" ") albums = index.albums_by(artist) if albums.any? 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.
29 30 31 32 33 34 |
# File 'lib/muzak/cmd/playlist.rb', line 29 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.
20 21 22 23 24 |
# File 'lib/muzak/cmd/meta.rb', line 20 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.
120 121 122 123 124 125 126 127 128 |
# File 'lib/muzak/cmd/player.rb', line 120 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.
40 41 42 43 44 |
# File 'lib/muzak/cmd/index.rb', line 40 def list_albums build_response data: { albums: index.album_names, } end |
#list_artists ⇒ Object
List all artists in the index.
31 32 33 34 35 |
# File 'lib/muzak/cmd/index.rb', line 31 def list_artists build_response data: { artists: index.artists, } end |
#list_playlists ⇒ Object
List all currently available playlists.
8 9 10 11 12 |
# File 'lib/muzak/cmd/playlist.rb', line 8 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.
31 32 33 34 35 |
# File 'lib/muzak/cmd/meta.rb', line 31 def list_plugins build_response data: { plugins: Plugin.plugin_names, } end |
#list_queue ⇒ Object
Tell the player to list its internal queue.
133 134 135 136 137 |
# File 'lib/muzak/cmd/player.rb', line 133 def list_queue build_response data: { queue: player.list_queue.map(&:title), } end |
#next ⇒ Object
Tell the player to load the next song.
70 71 72 73 74 |
# File 'lib/muzak/cmd/player.rb', line 70 def next player.next_song build_response end |
#now_playing ⇒ Object
Retrieve the currently playing song from the player and print it.
161 162 163 164 165 166 167 168 169 |
# File 'lib/muzak/cmd/player.rb', line 161 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.
48 49 50 51 52 |
# File 'lib/muzak/cmd/player.rb', line 48 def pause player.pause build_response end |
#ping ⇒ Object
Return a simple heartbeat message.
8 9 10 11 12 13 14 15 |
# File 'lib/muzak/cmd/meta.rb', line 8 def ping = Time.now.to_i debug "pong: #{}" build_response data: { pong: , } end |
#play ⇒ Object
Tell the player to begin playback.
39 40 41 42 43 |
# File 'lib/muzak/cmd/player.rb', line 39 def play player.play build_response end |
#player_activate ⇒ Object
Many playback commands will automatically activate the player.
Activate the configured player.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/muzak/cmd/player.rb', line 9 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.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/muzak/cmd/player.rb', line 25 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.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/muzak/cmd/playlist.rb', line 39 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.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/muzak/cmd/playlist.rb', line 54 def playlist_add_artist(pname, *args) artist = args.join(" ") songs = index.songs_by(artist) if songs.any? 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.
70 71 72 73 74 75 76 77 |
# File 'lib/muzak/cmd/playlist.rb', line 70 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.
83 84 85 86 87 88 89 90 |
# File 'lib/muzak/cmd/playlist.rb', line 83 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.
17 18 19 20 21 22 23 24 |
# File 'lib/muzak/cmd/playlist.rb', line 17 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.
96 97 98 99 |
# File 'lib/muzak/cmd/playlist.rb', line 96 def playlist_shuffle(pname) playlists[pname].shuffle! build_response end |
#previous ⇒ Object
Tell the player to load the previous song.
79 80 81 82 83 |
# File 'lib/muzak/cmd/player.rb', line 79 def previous player.previous_song build_response end |
#quit ⇒ Object
Terminates the muzak instance (not just the client).
40 41 42 43 44 45 46 |
# File 'lib/muzak/cmd/meta.rb', line 40 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.
9 10 11 12 13 14 15 16 17 |
# File 'lib/muzak/cmd/index.rb', line 9 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.
142 143 144 145 146 |
# File 'lib/muzak/cmd/player.rb', line 142 def shuffle_queue player.shuffle_queue build_response end |
#songs_by_artist(*args) ⇒ Object
List all songs by the given artist in the index.
62 63 64 65 66 67 68 69 70 |
# File 'lib/muzak/cmd/index.rb', line 62 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.
57 58 59 60 61 62 63 64 65 |
# File 'lib/muzak/cmd/player.rb', line 57 def toggle if player. player.pause else player.play end build_response end |