I have a various streaming box (Apple TV, Roku, Fire TV, Nexus Player) because i prefer to watch video tutorials on TV rather than watching in laptop. However, we don’t have app for all the sites that provides video tutorials. For example, MSDN channel9 dont have app for any streaming boxes. So, i decided to use roku sample video player app to play channel 9 videos on my roku. This app expects the video content defined in certain XML format.So, I just have to build the web APIs to return the XML output dynamically. I also prefer not to host the Web APIs on the internet. I just want to host it in my home network. So, i need a web server that will be always on so, decided to use my existing Raspberry PI 3 as a web server.
I initially thought of using .Net Core on Windows IOT but then later decided to use Raspian OS and NodeJS becuase i wanted to try NodeJS with some real world application.
Setting up Raspian OS on Raspberry PI was pretty simple. I just followed this excellent article on how to setup Raspian on Raspberry PI. Also, configured the remote connection and shared the work folder to deploy the files so i no longer need my Raspberry PI connected to my TV. I just placed the raspberry PI along with my other stream boxes and connected through my laptop using remote desktop.
I started the Node JS Web API with the following Node Packages to parse the channel 9 feeds.
Express is one of the most famous nodejs web application framework to create Web APIs quick and easy. Cheerio is used for parsing the DOM elements. XMLBuilder is used for construct the xml output in easy way.
To start with, i created the web server with routing as follows
var express = require('express')
i created the parser library class and added the following code to parse the channel 9 RSS content to fetch the video URLs
Thats it. We have just implemented the web API using NodeJS with just few lines of code. if i run my application using http://localhost:4567/ch9, it responds back with xml output.
The deployment is super easy too. Just copy the folder excluding Node_Modules folder. You dont have to deploy the node_modules folder. You can run the NPM Update command to get the node_modules folder from PI Server after deploying it to save some deployment time.
To run the App Server, just open the terminal from Raspian and run using the following command Node APP.js and your personal web server is ready to serve.
I have modified the UrlCategoryFeed in categoryFeed.brs in the roku app before i deploy it. In order to deploy the roku dev app, just follow the roku official guide . Make sure You enable the development mode in roku before deploying it.
Update : Roku recently updated their video channel sample app and the new app can be found here.