Skip to content

Commit

Permalink
Got tivo command line app working for a few commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhuss committed Jun 12, 2009
1 parent 0bea098 commit 9a94180
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@
coverage
rdoc
pkg
.rake_tasks
34 changes: 29 additions & 5 deletions bin/tivo
@@ -1,8 +1,32 @@
#! ruby
require File.dirname(__FILE__) + '/../lib/dvrb'

require 'net/telnet'

tivo = Net::Telnet.new("Host" => '192.168.1.111', 'Port' => '31339', "Timeout" => 5, "Prompt" => /LOCAL/) { |str| print str }
puts "Channel Up"
tivo.cmd "IRCODE CHANNELUP"
tivo.close

if ARGV.size != 2
puts <<-EOS
Control you TiVo from the command line.
Usage:
tivo <host> <command>
where available commands are:
play
pause
EOS
else

tivo = DVRB::Tivo.new(ARGV[0])

case ARGV[1]
when "pause"
tivo.pause
when "play"
tivo.play
when "channelup"
tivo.channel_up
when "channeldown"
tivo.channel_down
end

end
4 changes: 4 additions & 0 deletions dvrb.gemspec
Expand Up @@ -22,7 +22,11 @@ Gem::Specification.new do |s|
"README.rdoc",
"Rakefile",
"VERSION",
"bin/tivo",
"dvrb.gemspec",
"lib/dvrb.rb",
"lib/dvrb/base.rb",
"lib/dvrb/tivo.rb",
"test/dvrb_test.rb",
"test/test_helper.rb"
]
Expand Down
6 changes: 3 additions & 3 deletions lib/dvrb.rb
@@ -1,5 +1,5 @@
module DVRB
end
module DVRB; end

require File.dirname(__FILE__) + '/dvrb/base.rb'
require 'net/telnet'
require 'dvrb/base'
require 'dvrb/tivo'
5 changes: 5 additions & 0 deletions lib/dvrb/base.rb
@@ -1,3 +1,8 @@
class DVRB::Base
attr_accessor :host, :port

def initialize(host, port)
@host = host
@port = port
end
end
30 changes: 30 additions & 0 deletions lib/dvrb/tivo.rb
@@ -1,3 +1,33 @@
class DVRB::Tivo < DVRB::Base

PORT = 31339

def initialize(host)
@host = host
end

def channel_up
send_to_tivo "CHANNELUP"
end

def channel_down
send_to_tivo "CHANNELDOWN"
end

def pause
send_to_tivo "PAUSE"
end

def play
send_to_tivo "PLAY"
end

private

def send_to_tivo(command)
tivo = Net::Telnet.new("Host" => @host, 'Port' => PORT, "Timeout" => 5, "Prompt" => /LOCAL/)
tivo.cmd "IRCODE #{command}"
tivo.close
end

end

0 comments on commit 9a94180

Please sign in to comment.