Android and Linux

Thursday, July 7, 2011

Final Roku bash shell script

I played around a little more and cleaned up the Roku remote control script. There's not much else to put in it, but I tweaked how it can be ran and found a few uses for it already.

I don't like the names of some of the options. Who wants to type "roku instantreplay" in a terminal to rewind a few seconds? Not me, but those can all be customized to suit a person's needs. I threw in a few shortcuts. They are:

re = instantreplay
sel = select
del = backspace
wake = backspace (I thought this may be the safest button to use to wake the roku.)

There are three ways to use the script.

1) on the command line with the Roku command you want to run.

roku up
roku home
roku play

2) in "live mode". This is where you type roku live and it waits for you to input commands. This is a bit of a pain to use but it is useful when navigating through menus.

3) in "string mode" with the "str" argument and a bunch of other arguments roku str. I stole string mode from my IP camera script. To use it, just type the commands you want carried out and they will be carried out with a .5 second wait in between.

Example: roku str home right right select down select will go to the home screen, right two channels, select that channel, go down and select again. I find this useful because when my daughter finds a SpongeBob episode that she likes, she wants to watch it 2-3 times. But at the end of every episode, it goes to the next one and waits for you to hit play. To rewatch an episode, you have to move down one spot to "play different episode", hit select, go left to the episode before it, then hit select twice to play it. With my script, I can set up a shortcut to the command roku str down select left select select and replay the episode with a single touch.

Well that's about it, hope someone gets some use out of it.

#! /bin/sh

mainroku ()
{ case "$input" in

# will list all installed apps in this format: 12 Netflix
wget -q -O - "http://${ip}:8060/query/apps" | sed -e 's/<app id=\"//g' -e 's#<[^>]*>##g' -e 's/\".*>/ /g';;

# from the above list, use go plus the number to select channel.
# e.g. "go 12" to go to netflix
wget -q -O - --post-data "" "http://${ip}:8060/launch/${goto#* }"; shift;;

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

wget -q -O - --post-data "" "http://${ip}:8060/keydown/${input}"
wget -q -O - --post-data "" "http://${ip}:8060/keyup/${input}";;

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

## customized
wget -q -O - --post-data "" "http://${ip}:8060/keypress/backspace";;
wget -q -O - --post-data "" "http://${ip}:8060/keypress/backspace";;
wget -q -O - --post-data "" "http://${ip}:8060/keydown/instantreplay"
wget -q -O - --post-data "" "http://${ip}:8060/keyup/instantreplay";;
wget -q -O - --post-data "" "http://${ip}:8060/keydown/select"

esac }

if [ "$1" = "live" ]
echo "Type your command and hit enter. Type exit to end"
while [ "$input" != "exit" ]
do read input; goto=${input#* }; mainroku

elif [ "$1" = "str" ]
arg=$(($# - 1))
while [ "$arg" -ne "0" ]
do shift; arg=$(($arg - 1))
goto="$1 $2"
sleep .5

else input="$1"; goto="$1 $2"; mainroku