Class: XBMC

Inherits:
Object
  • Object
show all
Defined in:
lib/xbmc.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 80, playlist = 0) ⇒ XBMC

Creates a new instance using the hostname or IP address, port, and



13
14
15
16
17
18
19
20
# File 'lib/xbmc.rb', line 13

def initialize(host,port = 80, playlist = 0)
  @host     = host
  @port     = port
  @paused   = false
  @playlist = playlist
  
  set_playlist
end

Instance Method Details

#clear_playlistObject



66
67
68
# File 'lib/xbmc.rb', line 66

def clear_playlist
  send_command('ClearPlaylist',0)
end

#currently_playingObject

returns a hash with details on the currently_playing track xbox.currently_playing #=> “La Vida Loca”



24
25
26
27
28
29
30
31
# File 'lib/xbmc.rb', line 24

def currently_playing
  returning(Hash.new) do |result|
    send_command('getCurrentlyPlaying').search("//li").each do |item|
      key,*value = item.inner_html.split(':')
      result[key.downcase.to_sym] = value.join(':').chomp
    end
  end
end

#pauseObject Also known as: unpause

Pause or unpause the player. This is a simple toggle, it doesn’t check current state.



60
61
62
63
# File 'lib/xbmc.rb', line 60

def pause
  send_command('Pause')
  @paused = !@paused
end

#paused?Boolean

Whether or not xbmc is paused

Returns:

  • (Boolean)


39
40
41
# File 'lib/xbmc.rb', line 39

def paused?
  @paused
end

#play_nextObject

Play the next track



54
55
56
# File 'lib/xbmc.rb', line 54

def play_next
  send_command('PlayNext')
end

#playing?Boolean

Whether or not a track is in progress

Returns:

  • (Boolean)


34
35
36
# File 'lib/xbmc.rb', line 34

def playing?
  currently_playing[:filename] == "[Nothing Playing]" ? false : (true && !paused?)
end

#playlistObject

An array of the currently loaded tracks



44
45
46
# File 'lib/xbmc.rb', line 44

def playlist
  send_command('getPlaylistContents',0).search("//li").map{|i| i.inner_html.chomp}.reject{|i| i == "[Empty]"}
end

#queue(song) ⇒ Object

Add a file to the queue. Specify the path to the file as xbmc would access it.



49
50
51
# File 'lib/xbmc.rb', line 49

def queue(song)
  send_command('addToPlaylist',song,0)
end

#set_playlist(type = @playlist) ⇒ Object

0 = Music 1 = Video



72
73
74
# File 'lib/xbmc.rb', line 72

def set_playlist(type=@playlist)
  send_command('SetCurrentPlaylist',type)
end