[WIP] XBMC Flicks (Netflix Addon) Development Thread - Developers Only! - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +--- Thread: [WIP] XBMC Flicks (Netflix Addon) Development Thread - Developers Only! (/showthread.php?tid=86575) |
[WIP] XBMC Flicks (Netflix Addon) Development Thread - Developers Only! - fekker - 2010-12-01 I tried the option of opening the netflix via the external player, there's just too much on the screen to navigate with a controller (i use the xbox 360 controller as my xbmc controller, the keyboard is tucked away and only used when i need to do something else on the machine). So I started digging abit into how to interact with the netflix api. So i've come up with a way to display the instant queue, and open the movie via the external app (IE), but there's gotta be some cool scripting options that i can use to make it seem more like something that's meant for xbmc. I have the basic netflix api parts working, i can retrieve the instant queue and provide the url that can be used to play the movie. I can write out, in any format, the movie url that will play the movie, the title, the poster URL (Or just write the image to a local file moviename.tbn) The POC for that is just a simple windows form that has a picture box that onclick opens the url in the browser. This is done using the c# oauth base class and the wrapnetflix .net code From the user perspective in XBMC, i'd like to have it display the poster and when clicked it would play the movie This could be done with the following A MOVIE_NAME.htm file is created for each item in instant queue by the .net app (this is done by a .net app that runs in the background, updating on a user specified inteval) It could also just have a REFRESH_QUEUE.htm, with a listener in the .net app that would tell it to recreate those items. source added to video sources where those .htm files are located on disc it would be c:\xbmc\netflix - this is the source we add to the video section of xbmc in there there is a file, Refresh_Queue.htm in there is also a folder, Netflix_Instant_Queue in the folder (Netflix_Instant_Queue) are the Movie_Name.htm files that the .net app creates, that link to movie on netflix when one of those Movie_Name.htm are clicked on, the external player opens ie in full screen and plays the movie. Thoughts?? Ideas? Right now i'm just opening up my windows form in full screen and can click on the image using my remote to play the movie, but when it's done i have to close the browser window, then exit the windows form. To interact with the queue, it must stay in my windows app, there's a bunch of oauth stuff and hashes that must be done for each item in order to add/delete/modify/list the queue (dev key, user key, secrets, and a hash in sha1 of the requested resource). Also, I have to auth the user before I make a bunch of requests so that I dont hit the limits per day, 4 per second (app limit) 5,000 per day (that are not authenticated, this would be app level), 5,000 per day authenticated (i.e. that counter is at the user level, this is where those requests need to be, otherwise the daily limit for the app would be hit after only a few users) The Movie_Name.htm is just a redirect to the real URL of the movie in the browser. - jmarshall - 2010-12-02 What do you need to access the netflix queue? Could you do all that part of it in XBMC itself (i.e. from python)? - fekker - 2010-12-02 jmarshall Wrote:What do you need to access the netflix queue? Could you do all that part of it in XBMC itself (i.e. from python)? oauth - i'm sure there's a python script for it out there somewhere already netflix api calls - there is a python example out there for it pass app key and secret to netflix, user enter's login info and approves it (add's device to approved list), this returns the users key and secret, those are stored for additional calls and won't change as long as the user doesn't remove it from the approved list of devices in netflix to get the queue, we pass the app key, app secret, user key, user secret, and a hash of the requested resource uri that combines the keys & secrets with the uri data into a 20 char ascii string that is the oauth_secret, we also send a unique id per request (noonce).. sending all that junk to the netflix api via http post makes it an authorized connection (all the keys and the oauth secret make up the required token) and will return XML that contains the user's instant queue. To play the movie, we only need the app's key and the id of the movie to change it in the queue (add/delete/remove) we need the token info (as described above) searching adding to instant queue if available, are all just calls to different parts of the netflix api I'll post up some details (that includes the library i used for oauth which is not that complicated), the netflix api wrapper i used isn't needed as all the calls can be re-written, it's a nice reference to see what the calls are doing. - jmarshall - 2010-12-02 Right, so it sounds like all that side of it could be done by a python plugin in XBMC. On playback, the python plugin would then evoke an external player to through up the browser and tear it down afterward. - fekker - 2010-12-02 jmarshall Wrote:Right, so it sounds like all that side of it could be done by a python plugin in XBMC.Correct, it can all be done in python and that would be the best user experience with it by far. Now that i've got it working in c# code, i think i understand it enough to use python, but haven't done anything with it before. I'll see about some pseudo code, with the c# version of that code, that goes through the process of pulling the instant queue. I'm skipping the initial user part as there's a nice example in netflix's api on that one, i'll get that link tonight as well. - fekker - 2010-12-02 Update: I found a c# to python converter and popped in the oauth.cs (from oauth's base class (google code) http://oauth.googlecode.com/svn/code/csharp/OAuthBase.cs) and then cleaned up the comments. I'll see about converting over the calls and other items in the next few days. It should be fairly easy to convert over now that I found a tool to do most of the conversion from code i understand to py The post below contains the converted oauth.py class that will allow the tokens to be created and other common functions needed with the api calls (Update: it's currently a mixed bag of calls that I'll need to re-write) - fekker - 2010-12-02 Code: from System import * - fekker - 2010-12-03 You need the following items to make the request string ConsumerKey = "gnexy7jajjtmspegrux7c3dj"; //the key is xbmcflix key for Netflix API, it is the actual key for the app i've titled xbmcflix (Is that name ok to use?) string ConsumerSecret = THIS_IS_A_SECRET; //the secret is a secret and needs to be hashed and not displayed in text form, this is provided by netflix for the developer string UserId = THIS_IS_RETRIEVED_FROM_NETFLIX; string AccessToken = THIS_IS_RETRIEVED_FROM_NETFLIX; string AccessTokenSecret = THIS_IS_RETRIEVED_FROM_NETFLIX; The UserId, AccessToken, and AccessTokenSecret parts are not yet converted to python. Here is the instant queue in python, returned in XML format, some parts of this might still need translated from c# to py Code: def getInstantQueueXML(self): Playing the movie //the videoid can be grabbed from the id in the xml for the item example: - <queue_item> <id>http://api.netflix.com/users/%USERID%/queues/instant/available/1/70135754</id> 70135754 is the VideoID To play the movie, the url is string playmovieUrl = "http://www.netflix.com/WiPlayerCommunityAPI?lnkctr=apiwn&nbb=y&devKey=" + ConsumerKey +"&movieid=" + curInstantQueueItem.VideoID; oauth library - galvanash - 2010-12-03 https://github.com/simplegeo/python-oauth2 Using this as a starting point for oauth would probably be better than trying to port ironPython code, as it tends to rely heavily on the .net framework. - fekker - 2010-12-03 galvanash Wrote:https://github.com/simplegeo/python-oauth2thanks for the link after looking at how that one is done, and actually looking up some of the py calls, i noticed the oauth code i posted is a mix of stuff.. i'm going to rewrite it as I need to lookup how the calls are done in py anyway to understand how to get it into xbmc - fekker - 2010-12-03 or instead of re-inventing the wheel, there's already a netflix api in py done http://code.google.com/p/pyflix/source/browse/ ok, after figuring out how that works, i can pull the instant queue data with the python netflix api (linked above), basically i just modified the netflixapi from that one to add a function that just grabs the instant queue (based off the one that pulls the rental history) there's a few requirements, simplejson, and oauth, both of which where already done and required no changes (also GPL'd so we are good there too) The script has to be run 3 times, and modified with the user information and dev information as it's being processed. So that will need some tweaking there. first run will create the link out to the netflix page to authorize the app second run will get the user id, user token and user token secret third time is the charm as we have all the required keys, now it pulls the instant queue So assuming we are already past the user id/token parts, we now have a string of all the values of the instant queue Here's where i'll need some assistance, getting that into the xbmc ui anyone got a simple Hello World on that or willing to help out? Edit: found the xbmc hello world type example i'll test things out tonight, if it works, i'll post it - jmarshall - 2010-12-03 Does oauth contain binary bits? If not, great - we can push that into the repo as a separate script lib. If it does then things are a bit trickier as we need to build it (or grab it) and distribute with XBMC itself (until binary addons come along) Cheers, Jonathan - fekker - 2010-12-03 jmarshall Wrote:Does oauth contain binary bits? If not, great - we can push that into the repo as a separate script lib. It's actually the MIT license, not GPL, don't think that'll be a problem No binary as far as i can tell source: https://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py - jmarshall - 2010-12-03 That's fine then - we can pull it in as a lib and all addons will benefit Cheers, Jonathan - fekker - 2010-12-04 Ok, i'm getting closer but am missing something with actually displaying the links in the UI Update: i've got it to load the script, but it keeps loading it over and over again so there's still something missing. here's the pastebin of xbmc's debug log http://pastebin.com/8TNC94BT Update #2: the loop error only occurs in dharma rc1 and in rc2.. however it doesn't happen with an older build (28078) .. very odd, but hey I have the basic info in there now That means there is 2 things I still need to determine 1) if that loop error occurs with RC2 (i'll test that next)--Update: issue occurs in RC2 as well 2) how to tell it to play the video url link via the external player (iexplorer) .. guessing that needs configured in playercorefactory.xml and then there must be a way to tell it to use that player to play the links If anyone has an idea for #2, that's a key one for sure |