Saving the state for Home Media Server
Home Media Server is a Roku application for streaming video from a http server. I started the project in 2009 after Roku released the SDK for their devices . Originally it was a server and a client, but I rewrote it in 2010 as just a client so that the only external dependency was a http server that could handle partial file requests.
In 2013 I rewrote the client to use the gridScreen layout which lets you display more content at the same time and makes it easier to split things into categories. Currently it only supports video streaming, I never have gotten around to adding audio support or photo albums like I had originally planned.
One thing that has been missing has been the ability to save the state between reboots of the app. When you exit from the app the contents of the tmp:/ filesystem are recycled so it would only save the last played position until you left the app. This results in ‘feedback’ from family members, and since I’m the one who wrote it the usual response of “well I didn’t write it” doesn’t fly. Roku’s Netflix app is where this response is often used – its ability to anticipate the selection of a movie and then to totally refresh the interface is uncanny.
Instead of going back to a client/server model I decided to add an optional service to use for storing arbitrary key/value pairs. I called it clortho and wrote about deploying it in this blog post . HMS will still run without it, but with clortho installed it will now remember the last played selection in each of the categories and the last played position for each video.
Your webserver will need to proxy requests for the /keystore/ path to the clortho service. I’m using lighttpd myself, so my configuration file now looks like this:
$HTTP["host"] =~ "^movies\.home$" {
server.document-root = "/Movies/"
dir-listing.activate = "enable"
$HTTP["url"] =~ "(^/keystore/)" {
proxy.debug = 1
proxy.balance = "fair"
proxy.server = ( "" =>
(( "host" => "127.0.0.1", "port" => 9001))
)
}
}
This points requests to the directory /Movies, generating a listing for them so that HMS can interpret it. And requests for /keystore/ go to the clortho service running on localhost.
At startup HMS will try to request /keystore/version to see if the service is active. If it gets a status code of 200 it will use the keystore, if not it will only save things to the tmp:/ filesystem as before.
With all of that in place HMS is easier to use. Not having to scroll through all the episodes trying to remember the last one you watched is really nice. I also made HMS auto-advance to the next episode when the current one has been played in full – which means we now have to un-learn the habit of advancing to the next one.