Back in April I mentioned adding some Roku remote control. At this point I’m thinking more javascript than Python.
Roku has a good External Control Protocol reference online.
Sending commands
Unfortunately, the Roku API will not accept Cross Origin Request. This is not an issue if communicating from Node or Python but from the browser using xhr or fetch() you will get CORS errors. When sending POST for button presses you don’t care about the response for a “mode:’no-cors’ ” will work.
let resp = await fetch("http://roku-ip:8060/keypress/play", {method:'POST', mode:'no-cors'})
For the GET for status from the browser one option is a “proxy” add the “Access-Control-Allow-Origin” header. Borrowing the idea from https://medium.com/gitignore/building-a-roku-remote-web-app-1c0db0056be4 we set our Apache web server.
sudo pico /etc/apache2/apache2.conf
to edit the config file and add the following lines:
<Location /roku> ProxyPass "http://roku-ip:8060/" ProxyPassReverse "/" Header add "Access-Control-Allow-Origin" "*" </Location>
You will need to have several modules loaded in Apache for this to work: headers and proxy_http. This can be done with:
sudo a2enmod proxy_http sudo a2enmod headers sudo systemctl restart apache2
Deep Links
A very important link for launching directly into netflix content is https://unogs.com/search/. From this site you can find the contentid for much of the netflix content.
This allows for directly linking to content with something like:
curl -d '' "http://roku-ip:8060/launch/12?contentid=70136120&mediatype=series"
This is a simple POST to the URL with no body.
The folks at unofficial Netflix online Global Search also provide an API.