Android and Linux

Monday, July 4, 2011

bash script to control Roku

This is a very rough draft that I threw together in a few minutes so I'd have something working to play with.

A couple notes:

Assuming you call this script "roku", you can run it two ways, either by sending a command or by running in interactive mode. To send a command, just type the command as an argument. Example, to play a movie, type roku play.

To run in interactive mode, type roku live. In interactive mode, it waits for commands and you can repeat as many as you like until you type exit.

Here is an example of an interactive mode with my comments in italics.

# ./roku live
home goes to main screen
apps lists channels

5127 Roku Spotlight
11 Roku Channel Store
12 Netflix
2016 Movies on Demand
2285 Hulu Plus
28 Pandora
1688 Roku Newscaster
1756 Funny Videos and Pics by Break
2115 SHOUTcast Internet Radio
27 Mediafly
2898 Weather Underground
2963 My Damn Channel
4070 TEDTalks
45 Revision3
4687 Inmoo
6117 SnagFilms
5415 Instant Watch Browser for Netflix

go 12 selects Netflix
search goes to Netflix search screen
l
i
n
u
x these 5 type out "linux"
enter searches for linux
right
select
down
down
select these 5 go to the right one space, select the movie, go down to "add to instant queue and hit select to add it"
exit
#
(and no there aren't any linux movies)

Here are the available commands:

apps- lists all your channels

go x- goes to the number for the channel you want

space - enters a space in search boxes

del - deletes one character in search boxes. same as "backspace" but easier to type

home - goes home

rev/fwd/play/left/right/select/up/down/back/instantreplay/backspace - self explanatory.

info - seems to only work on home screen. allows you to change channel position, see rating, description and remove channel

search - goes directly to search screens if the channel supports it. works in Netflix

enter - when in a search box, this carries out the search. may have a use in other text boxes.

a-z and 0-9 - self explanatory.

And here's the script.

#! /bin/sh 
## put your Roku IP address below ##
ip=

infunc ()
{
read input
case "$input" in

apps)
wget -q -O - "http://${ip}:8060/query/apps" | sed -e 's/<app id=\"//g' -e 's#<[^>]*>##g' -e 's/\".*>/ /g'
;;

go*)
wget -q -O - --post-data "" "http://${ip}:8060/launch/${input#* }"
;;

space)
wget -q -O - --post-data "" "http://${ip}:8060/keypress/lit_ "
;;

del)
wget -q -O - --post-data "" "http://${ip}:8060/keypress/backspace"
;;

home|rev|fwd|play|select|left|right|down|up|back|instantreplay|info|backspace|search|enter)
wget -q -O - --post-data "" "http://${ip}:8060/keydown/${input}"
wget -q -O - --post-data "" "http://${ip}:8060/keyup/${input}"
;;

a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|1|2|3|4|5|6|7|8|9|0)
wget -q -O - --post-data "" "http://${ip}:8060/keypress/lit_${input}"
;;
esac
if [ "$input" != "exit" ]; then infunc; fi
}

if [ "$1" = "live" ]; then infunc; fi


case "$1" in

apps)
wget -q -O - "http://${ip}:8060/query/apps" | sed -e 's/<app id=\"//g' -e 's#<[^>]*>##g' -e 's/\".*>/ /g'
;;

go)
wget -q -O - --post-data "" "http://${ip}:8060/launch/${2}"
;;

space)
wget -q -O - --post-data "" "http://${ip}:8060/keypress/lit_ "
;;

del)
wget -q -O - --post-data "" "http://${ip}:8060/keypress/backspace"
;;

home|rev|fwd|play|select|left|right|down|up|back|instantreplay|info|backspace|search|enter)
wget -q -O - --post-data "" "http://${ip}:8060/keydown/${1}"
wget -q -O - --post-data "" "http://${ip}:8060/keyup/${1}"
;;

a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|1|2|3|4|5|6|7|8|9|0)
wget -q -O - --post-data "" "http://${ip}:8060/keypress/lit_${1}"
;;

esac

Followers