DEV Community

Mike Grant
Mike Grant

Posted on • Originally published at mikegrant.org.uk on

Controlling Streaming Services with Alexa - Part 1

One of the biggest problems that I’ve found with the sheer amount of streaming services is which one has what? Sometimes I’ll miss great content on Amazon Prime because I get frustrated browsing their app on my TV, or I want to watch a certain film, can’t find it on Netflix, and just assume that it’s not available to be streamed from anywhere. Why can’t I just ask my voice assistant (Alexa) to play a TV show or film and it plays on my TV irrespective of which streaming service it is on?

I currently use Alexa to control a lot of things in my house through Home Assistant and a custom skill for some of the more complicated tasks, so I set about creating a custom Alexa skill that will allow me to play content from the streaming services that I’ve subscribed to, on my TV. (Think “Okay Google, play Stranger Things on TV”)

What do I need?

Before starting working on this project, I sat down and thought about what I needed to make this work, and the list was surprisingly small.

  • Control of my TVs (via ADB)
  • Intent information for each streaming service
  • Data about what content is available on each service
  • Alexa Skill

Controlling the TV

Before we can play anything on the TV, we need to find a way to open the content that we want on the TV. As I have Android based devices, this is relatively easy for me. I can use ADB and intents. As part of my home automation system, I already have an ADB server running in a container, which is connected to my TVs. This saves me having to open and close connections to each of my TVs everytime I want to control them.

To open content on the TV, I’ve used the intent URL scheme so that everything is uniform and easier to work with. After trawling the internet I compiled this list of intents for the three main streaming services that I use.

Netflix - intent://www.netflix.com/watch/CONTENTID#Intent;launchFlags=0x00800000;scheme=https;package=com.netflix.ninja;S.source=30;end Amazon Prime - intent://com.amazon.tv.launcher/detail?provider=aiv&providerId=ASIN#Intent;package=com.amazon.tv.launcher;scheme=amzn;end Disney+ - intent://disneyplus.com/VIDEOID#Intent;launchFlags=0x00800000;scheme=https;package=com.disney.disneyplus;end 
Enter fullscreen mode Exit fullscreen mode

We can validate these intents are working by using an adb shell that is connected to one of the TVs.

am start intent://www.netflix.com/watch/CONTENTID#Intent;launchFlags=0x00800000;scheme=https;package=com.netflix.ninja;S.source=30;end 
Enter fullscreen mode Exit fullscreen mode

This will start Netflix on the device and the content will beging playing within a couple of seconds.

Playing content on the TV

Now that we can control our TV using ADB, we can build upon this by creating a simple script that takes a Netflix video link and sends the command to my TV via the ADB server.

var adb = require('@devicefarmer/adbkit') var client = adb.createClient({ host: '127.0.0.1', port: '5037' }) contentIntent = 'intent://www.netflix.com/watch/80126025#Intent;launchFlags=0x00800000;scheme=https;package=com.netflix.ninja;S.source=30;end' client.shell('192.168.1.1', `am start "${contentIntent}"`).then(function (response) { console.log(response) }).catch(function (err) { console.log(err); }) 
Enter fullscreen mode Exit fullscreen mode

Running this script will open Star Trek: Discovery on the TV and we’ve validated that the idea will work.

Seeing it in action

Check back soon for more details on this project.

Top comments (0)