Class: Mpc
- Inherits:
-
Object
- Object
- Mpc
- Defined in:
- lib/Mpc.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
Instance Method Summary collapse
-
#add(song, insert = false) ⇒ Object
insert: whether to add the song after the currently playing one instead of the end of the queue.
-
#clear ⇒ Object
stops the player and clears the playlist.
-
#current(info = :url) ⇒ Object
returns info about the currently playing file.
-
#initialize ⇒ Mpc
constructor
A new instance of Mpc.
- #mpccall(cmd, quiet = true) ⇒ Object
- #play ⇒ Object
Constructor Details
#initialize ⇒ Mpc
Returns a new instance of Mpc.
5 6 7 |
# File 'lib/Mpc.rb', line 5 def initialize @debug = false end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
3 4 5 |
# File 'lib/Mpc.rb', line 3 def debug @debug end |
Instance Method Details
#add(song, insert = false) ⇒ Object
insert: whether to add the song after the currently playing one instead of the end of the queue
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/Mpc.rb', line 21 def add(song, insert = false) unless song.respond_to? 'url' p song raise ArgumentError, "parameter does not have an #url method" end if @debug action = insert ? "insert" : "add" puts "would #{action} #{song['title']}: #{song.url}" else if insert then mpccall("insert '#{song.url}'") else mpccall("add '#{song.url}'") end end end |
#clear ⇒ Object
stops the player and clears the playlist
47 48 49 50 51 52 53 54 |
# File 'lib/Mpc.rb', line 47 def clear if @debug puts "would clear" else mpccall("stop") mpccall("clear") end end |
#current(info = :url) ⇒ Object
returns info about the currently playing file
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/Mpc.rb', line 57 def current(info = :url) filter =case info when :url '%file%' when :album '%album%' when :artist '%artist%' end `mpc --format '#{filter}' current` end |
#mpccall(cmd, quiet = true) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/Mpc.rb', line 9 def mpccall(cmd, quiet = true) call = "mpc #{cmd}" call << " > /dev/null" if quiet unless system(call) $stderr.puts "MPC call error: #{$?}" end end |
#play ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/Mpc.rb', line 38 def play if @debug puts "would play" else mpccall("play") end end |