class RemoteVlc2019

Attributes

info[R]

Public Class Methods

new(host: nil, port: '8080', password: 'password', verbose: false) click to toggle source
# File lib/remote_vlc2019.rb, line 14
def initialize(host: nil, port: '8080', password: 'password', verbose: false)

  @host, @port, @password, verbose = host, port, password, verbose

end

Public Instance Methods

now_playing() click to toggle source
# File lib/remote_vlc2019.rb, line 20
def now_playing() @info[:now_playing]           end
pause() click to toggle source
# File lib/remote_vlc2019.rb, line 23
def pause()       req 'pl_pause'                end
play() click to toggle source
# File lib/remote_vlc2019.rb, line 21
def play()        req 'pl_play'                 end
playing?() click to toggle source
# File lib/remote_vlc2019.rb, line 22
def playing?()    state() == :playing           end
req(command='') click to toggle source
# File lib/remote_vlc2019.rb, line 35
def req(command='')

  url = "http://%s:%s/requests/status.xml?command=%s" \
    % [@host, @port, command]
  s = open(url + '', http_basic_authentication: ["", @password]).read
  doc = Rexle.new(s)
  @state = %w(state).map {|x| doc.root.text(x) }
  @vol = doc.root.text('volume').to_i

  @info = doc.root.xpath('information/category/info').map do |x|
    [x.attributes[:name].downcase.to_sym, x.text]
  end.to_h

  @verbose ? s : command.to_sym
end
Also aliased as: status
state() click to toggle source
# File lib/remote_vlc2019.rb, line 24
def state()       status(); @state.to_sym       end
status(command='')
Alias for: req
stop() click to toggle source
# File lib/remote_vlc2019.rb, line 25
def stop()        req 'pl_stop'                 end
vol() click to toggle source
# File lib/remote_vlc2019.rb, line 26
def vol()         @vol                          end
Also aliased as: volume
vol=(val) click to toggle source
# File lib/remote_vlc2019.rb, line 29
def vol=(val)     setvol val  end
Also aliased as: volume=
vol_down() click to toggle source
# File lib/remote_vlc2019.rb, line 27
def vol_down()    setvol(offset: -50)           end
vol_up() click to toggle source
# File lib/remote_vlc2019.rb, line 28
def vol_up()      setvol(offset: 50)            end
volume()
Alias for: vol
volume=(val)
Alias for: vol=

Private Instance Methods

setvol(raw_val) click to toggle source
# File lib/remote_vlc2019.rb, line 55
def setvol(raw_val)

  offset = raw_val.is_a?(Hash) ? raw_val[:offset] : nil
  val = offset ? @vol + offset : raw_val.to_i
  val = MAX_VOL if val > MAX_VOL and offset
  return status() unless val >= 0 and val <= MAX_VOL
  req 'volume&val=' + val.to_s
  vol()
end