Javascript API for Netflix Instant Player (silverlight)?
Asked Answered
R

6

9

Is there a Javascript API for the Netflix Instant player (silverlight)? Preferably a supported, documented one, but an unsupported, undocumented one might be okay too; this is for a personal project.

I'd like to be able to play/pause and seek to a given time.

Recollected answered 22/5, 2011 at 5:14 Comment(1)
See also #9195837 and for controlling the HTML5 player, see https://mcmap.net/q/1146623/-controlling-netflix-html5-playback-with-tampermonkey-javascript/32453Aparejo
T
13

I had fun digging into this, and I think I found your answer.

To start, I found an (admittedly old) post from someone at Netflix stating that their licensing requirements prohibited them from providing ways to control the player externally (everything needed to be wrapped up in a netflix-branded application, and providing ways to interact with the player externally would allow you to embed the netflix player in places it shouldn't go.) You can find that reply here (although it's four years old, I'd imagine not much has changed.)

http://developer.netflix.com/forum/read/54172

I tried snooping around on the 'watch instantly' page myself, and there are objects like netflix.SilverLight and netflix.SilverLight.MoviePlayer (which has a getPlugin() method that returns some details about the plugin, and hookable events, but no methods for control,) but they mostly have to do with exposing the size of the player viewport, among other things necessary to place it on the page. I couldn't really find anything in any of the objects that suggested they interacted with the movie player that would seem to allow me access to it.

I also snagged the player binaries, and snooping through them I've found a ScriptInterface object internally with [ScriptableMember]-decorated methods in it called PlayMovie(), StopMovie(), ShowCurtain(), HideCurtain().

Then, I noticed there's another namespace in the player binaries called Netflix.Silverlight.CBPApp.HostedPlayer, which has its own interface - HostedPlayerScriptInterface. This has everything you want in it - data on play position, controls for increasing and decreasing play speed, pausing, playing, setting the play position, querying play state, etc. All of these are decorated as [ScriptableMember]s.

Now I break your heart - it looks like (for whatever reason) this interface is not exposed as a [ScriptableType], which to my understanding is a requirement for being able to access it from javascript. In fact, the only things that seem to be exposed this way are events that the player fires. My guess is that this code is for integrating with other partners, or left over from someone they inherited the original code for the video player from, but it seems intentionally that this [ScriptableType] parameter is left out. There may be a way to request a binary that's built to be 'Hosted', though I'm not sure what that means, and I also suspect it will be transparently obvious to the people watching what you're trying to do and have a stop put to it quickly.

Sorry for the long-winded response that ends in disappointment, but it appears as of right now there's not really a way to do this. I've seen some suggestions that basically amount to sending keystrokes to the browser window that emulate the keyboard controls, but this clearly isn't what you're looking for, so I'm going to go with 'no' as an answer here. :)

Edit:

Further research is showing this is not the dead end that I thought it was. I'll update this once I'm done digging.

Edit 2:

So, looks like you need to trick the Netflix player into thinking it's running in hosted player mode. There's some configuration options that can be passed in, but I'm not sure how, specifically, you would do that. It looks like that's all set up on player initialization - maybe some sort of bookmarklet could reload the page and inject a change? Or maybe just reload the player and change the settings.

this.PlayerViewModel = (applicationConfiguration.PlayerConfiguration.EnableHostedPlayerControl ? new HostedPlayerViewModel() : new GenesisPlayerViewModel());

Is where I figured that out. When the HostedPlayerViewModel is used, this code gets run:

HtmlPage.RegisterScriptableObject("HostedPlayerControlScriptInterface_1", this.b)

which if I'm reading correctly will let you access this registered object by getting the DOM object containing the netflix silverlight player and calling

silverlightPlayer.content.findName('HostedPlayerControlScriptInterface_1').WhateverMethod()

Bear in mind I haven't done much of this javascript interop stuff so much of this is inferred from the documentation, but it does seem as if there is a javascript control API in there, it's just a matter of tricking the player into working in Hosted mode.

Going to have to stop here, but hopefully this gives you a good start. I've dumped the contents of that hosted player Javascript API file so you can see the methods that will be exposed once you manage to get the player in Hosted mode.

http://pastebin.com/UeN3NFMg

Good luck!

Tropology answered 28/2, 2013 at 20:52 Comment(1)
Great write up. I tried to follow what you provided by setting the hosted player configuration with the following tampermonkey script in chrome, paste.kde.org/734150. Unfortunately it seems that the options that most likely properly turn it on cause the player not to load (see comments in paste). After loading with other option (or none) the following never works. var player = document.getElementById('SLPlayer'); player.content.findName('HostedPlayerControlScriptInterface_1'); // null player.content // seems right I am not familiar with Silverlight, but any thoughts?Yuyuan
S
4

I'm way late to the party and I'm sure much has changed to how netflix handles it's clientside code, but I suggest you look at the object returned by netflix.cadmium.objects.videoPlayer().

This will change eventually but hey it might be useful.

Stellular answered 25/2, 2015 at 9:36 Comment(1)
Oh, I should add that this doesn't work in firefox, presumably because for firefox netflix renders the player controls in Silverlight rather than JS.Stellular
H
3

Since you mentioned undocumented...

In Silverlight for a method to be exposed to JavaScript directly, it needs attributes [ScriptableType] on its class and [ScriptableMember] on itself. You could try opening up the XAP file for the Netflix player, disassembling the main assembly, and searching for any methods with [ScriptableMember] attached to them. This may not turn up anything useful at all, but it is something you can try nonetheless.

Hidrosis answered 22/5, 2011 at 7:27 Comment(1)
Anyone end up doing this? I am on a mac, so I don't have a way to dissect Netflix's silverlight app. I too am looking to control video playing on netflix using javascript.Cerallua
D
1

Perhaps the Netflix official webpage is a place to start looking?

http://developer.netflix.com/docs/JavaScript_APIs

Discontinuation answered 22/5, 2011 at 5:22 Comment(1)
I started there before asking the question; unfortunately, this API seems to be for finding/queueing/playing instant movies, not controlling the player. (Tbf, my original question was vague about what I wanted to do.)Recollected
A
1

Boxee might have been able to control it at some point: http://dir.boxee.tv/apps/helper2/netflix.js

(a few other forks of that may be around as well).

I also wonder if netflix transferring to an HTML5 implementation would somehow allow a plugin to control playback. GL!

Aparejo answered 27/11, 2014 at 3:6 Comment(3)
It seems like Boxee's script is based on HostedPlayer, which Max's post below indicates is a deadend. You can double check that with netflix.Silverlight.MoviePlayer.getPlugin().settings.hostedPlayer which is false, and netflix.Silverlight.MoviePlayer.get_hosted_player_control() doesn't work. In chrome, my videos are using HTML5 though so you're right that maybe it'll work there!Mamey
@DerekDahmer maybe it is possible these days, ex: https://mcmap.net/q/1146623/-controlling-netflix-html5-playback-with-tampermonkey-javascriptAparejo
@DerekDahmer I added my latest to that post (for the HTML5 version which is actually almost controllable LOL)Aparejo
G
-3

<iframe src="https://www.netflix.com/watch"></iframe>
Gridiron answered 3/6, 2020 at 18:58 Comment(1)
Welcome to Stack Overflow. Code only answers can almost always be improved by adding some explanation of how and why they work. For older questions with existing answers it is very important to also point out what new aspect of the question your answer addresses. In this case you are providing an answer that works now by bypassing what was asked in the question, as your answer does not respond to the silverlight portion of the question.Lemuelah

© 2022 - 2024 — McMap. All rights reserved.