Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jcarbaugh
Level 7

Roku control client for Python

Hi everyone,

I posted this earlier on the general forum because I wasn't sure if this one was dedicated to channel development or not. Someone suggested I post here, so here it is...

I just published a Roku control client for Python. It's registered with PyPI and the source is available on GitHub. It supports a bunch of stuff including all the basic commands, discovery, and helpers for the input command.

Hope this will be useful and I'd love to get you feedback.
0 Kudos
4 REPLIES 4\
thetick
Level 12

Re: Roku control client for Python

Awsome!

I got all the Roku controls working from the python command line. I could not find what I needed to build on Windows.. I'm a Windows user, but a Unix dev guy. Anyway loaded a base CentOS VM and installed gcc, python-devel, libxslt-devel, libxml2-devel and it works fine.

I'm going to work on some personal automation scripts for launching on my Roku and then see if I can get them to work on Windows. When I'm finish setting up my Roku I'll try and package a windows zip with python, basic scripts, and a lightweight Roku launchpad (maybe just a Roku folder with icons if I'm lazy).
TheTick (aka "Moose Twit" affectionately called by chht)
Roku 3 for Pokémon TV / YouTube / Animal Planet GO / HBO GO. Chromecast for most other media because Roku Mirroring sucks , how many clicks in Wndows 10 (about a dozen) to Miracast on Roku vs 2 with Chromecast.
Verizon FIOS TV and Internet Service
0 Kudos
EnTerr
Level 11

Re: Roku control client for Python

"jcarbaugh" wrote:
I just published a Roku control client for Python. It's registered with PyPI and the source is available on GitHub. It supports a bunch of stuff including all the basic commands, discovery, and helpers for the input command.


Interesting - does this part ever work?
SENSORS = ('acceleration', 'magnetic', 'orientation', 'rotation')

My understanding was that there is no working functionality to emulate motion/game remote.
0 Kudos
EnTerr
Level 11

Re: Roku control client for Python

"thetick" wrote:
I got all the Roku controls working from the python command line. I could not find what I needed to build on Windows.. I'm a Windows user, but a Unix dev guy. Anyway loaded a base CentOS VM and installed gcc, python-devel, libxslt-devel, libxml2-devel and it works fine.

There shouldn't be a problem to run that thing on Windows - i have not tried but i don't think anything advanced will be needed. I used something simpler in my tinkering and know it to work in Windows:
import httplib
import urllib

def ecp_invoke(op, path):
conn = httplib.HTTPConnection(ROKU_IP, 8060)
conn.request(op, path)
r = conn.getresponse()
res = r.read() if r.status==200 else '%d[%s]=' % (r.status, r.reason)
conn.close()
return res

get_app_list = lambda: ecp_invoke('GET', '/query/apps')
keypress = lambda key: ecp_invoke('POST', '/keypress/' + key)
keydown = lambda key: ecp_invoke('POST', '/keydown/' + key)
keyup = lambda key: ecp_invoke('POST', '/keyup/' + key)
launch = lambda appID: ecp_invoke('POST', '/launch/' + appID)
send_input = lambda dict: ecp_invoke('POST', '/input?' + '&'.join(map('='.join, dict.items())))
0 Kudos
jcarbaugh
Level 7

Re: Roku control client for Python

It's probably the lxml requirement that's causing a problem on Windows. I'm going to get rid of that dependency in the next version because the amount of XML being parsed is really really small. Doesn't make sense to have that whole package installed for such a simple thing.

I actually haven't tried any of the sensor stuff yet. I was just following what was written in the Roku External Control Guide. It would mostly depend on the running app to know what to do with those messages anyway. I might try to install Angry Birds or something and see if I can get the controls to do anything weird by sending sensor calls.
0 Kudos