• 470 words

How the Popcorn Time's API works

I developed this little library to let developers create their own remote controller for PopcornTime.

Bags of Popcorn
Photo by Corina Rainer / Unsplash

The only people who don’t love Popcorn Time are the people who still don’t know it… and the cops of course!

I think this is the truest thing I’ve ever said, and it also seems a famous movie quote. So today we’re going to talk about Popcorn Time’s API that allows developers to execute actions without using the desktop application. For those who don’t know what I’m talking about, Popcorn Time (PT from now on) is an application born some time ago that gives you the possibility of watching tons of Tv Shows, Movies, and Anime using the p2p protocol. Given its simplicity with its user-friendly interface, you can consider it as “the illegal Netflix”*.

The great thing actually is that we also have the possibility to control PT remotely and so wherever we are, we can choose the movie, turn down the volume, toggle the fullscreen mode, search for a TV show and do everything you normally do directly on the desktop app.
We’re able to communicate remotely thanks to the JSON-RPC server inside PT which allows websites and apps to control the player.
So I decided to create a website and a library to handle the underlying protocol and API’s methods.

But how does the Popcorn Time API’s work? First of all, you need to know how the JSON-RPC works, so if you don’t know it here is some information, it’s actually very simple. The following is an example of a general call with its response:

--> {"jsonrpc": "2.0", "method": "methodname", "params": ["p1", "p2"], "id": 1}
<-- {"jsonrpc": "2.0", "result": 19, "id": 1}

So now that we have a general idea, we’re ready to discover what methods PT lets us use. Luckily we have this documentation hosted on GitLab that tells us all the methods and their parameters. Generally, you just need to make the JSON string and then perform a simple POST call to the local IP of the computer that is running PT and to the right port (which you can set on the desktop application).
It should be something like “http://192.168.1.5:8008/.
So if we would like to call the method “enter”, that simulates the press of the enter button, we just need to compose the string in this way:

{"jsonrpc": "2.0", "method": "enter", "params": [], "id": 1}

If we want to set the volume to 50%:

{"jsonrpc": "2.0", "method": "enter", "params": ["0.5"], "id": 1}

There are some other slightly complex things to take care of with other methods, but this is exactly the reason why I’ve created a library: so that you don’t need to know all these things too. Instead, you can just focus on the application you want to build and nothing else.

In fact, honestly, to use my library you don’t need to know anything about JSON-RPC or ajax calls at all, you just need to call methods and get responses (if there is a response).