Win iOS remote for controlling XMBC Flicks (Netflix plugin)
#1
Hello everyone, first post here so I apologize if this is in the wrong place.

I had a quick look and didn't find any place that this was addressed all the way.

I've basically about a week ago installed XMBC on an old laptop to use as my main interface to my existing movie library, and to play Netflix, etc... (Tired of switching between components to access my videos from different places).

I also wanted to control my stuff from an iPhone app over the network instead of IR.

So, install went smoothly, and everything seems to be working great with the official XBMC iOS remote.

Until I got to Netflix. So the XBMC Flicks add-on basically runs Netflix in a browser window for you, and works fine if you are using a keyboard to control things. Not so much with the iPhone app.

So I figured I would fix it.

I've basically written an AutoIT script to handle rudimentary functions when using XMBC Flicks to play Netflix in a browser.

What Works
Right now, starting a Netflix stream will open in a browser (as per the XBMC Flicks add-on).
Once started, focus is given to the window properly - the mouse cursor is moved to the far right center of the screen.
On the iOS remote, the following buttons/gestures will work:
Up, Down, Right, Left, Play/Pause, Stop.

Up/Down will turn the volume up/down on the Silverlight player for Netflix (same as keyboard) - in 5% increments.

Right/Left will start continuous seeking in the stream (just like Shift+R/L on the keyboard). Subsequent swipes/presses will speed up the seeking (in 10s, 20s, 30s increments - again just like the keyboard).

Play/Pause will do just that.

Stop will kill all running iexplore.exe windows on your system (essentially killing Netflix windows and returning you to XBMC).

These basic functions were enough to get me to a usable state for me using XBMC Flicks.

What Doesn't Work
Select will cause problems. It will basically select whatever is highlighted in the XBMC window under the Netflix window (if you just streamed something it will open another IE window and try to stream Netflix again - which will fail).

If you do accidentally hit "Select" and another window pops up, hitting Stop will kill all the windows so you are back to a clean interface again, and can start over.

Also, due to some weirdness with iexplore.exe, I found it easiest just to kill all running iexplore.exe processes to kill the Netflix window. So if you use IE as a browser also, all browser processes will be killed. This isn't really an issue for me as I normally don't use IE as a main browser.

How it Works
I couldn't find any elegant way to control an external browser from within XBMC (I am pretty new to this) - so I approached it in a dirty way. I basically load up winpcap in the AutoIT script, and monitor all network traffic on your network card, looking specifically for tcp packets (PSH) destined for your XBMC machine on port 80 (basically sending commands to the internal webserver for control).

Then I just mapped which commands were being passed in the packets, and let AutoIT handle them from there - passing control keys to the Netflix window.

What You'll Need
You'll need to install WinPcap to be able to capture your network packets.

If you want to run the script, you'll need AutoIT (not needed for executable), and...
you'll need to put the Winpcap.au3 file in the same location as the script (it's included in both downloads below).

Download the .exe here: XBMC Flicks iOS Remote

Now, I have a compiled AutoIT .exe of this script for ease of use, but the compiled version will default to using interface #0 on your machine. I may update later if needed.

Download the AutoIT scripts here: XMBC Flicks iOS Remote Scripts

If you want the code to run it yourself, here it is:


Code:
#include <Winpcap.au3>
#include <String.au3>

; These are hex strings from captured packets to the server from iOS remote
; ==========================================================================
Local Const $INPUT_LEFT = "496E7075742E4C656674"
Local Const $INPUT_RIGHT = "496E7075742E5269676874"
Local Const $INPUT_UP = "496E7075742E5570"
Local Const $INPUT_DOWN = "496E7075742E446F776E"
Local Const $INPUT_SELECT = "496E7075742E53656C656374"

Local Const $PLAYER_PLAYPAUSE = "506c617965722e506c61795061757365"
Local Const $PLAYER_STOP = "506C617965722E53746F70"

; ==========================================================================


while (True)
   ConsoleWrite(@CRLF & "Waiting for a Netflix window..." & @CRLF)
  
   ; Wait for Netflix window to show up
   $iehandle = WinWait( "http://movies.netflix.com/?" )
   ConsoleWrite("The window 'http://movies.netflix.com/?' was opened" & @CRLF)
  
   $winpcap=_PcapSetup() ; initialise the Library
   $pcap_devices=_PcapGetDeviceList() ; Get the interfaces list for which a capture is possible

   ; Start a capture on interface #0, in promiscuous mode, for tcp packets, port 80 with PSH flag
   ; This is setup to capture on device #0 right now, change the first index to a different number for a different interface
   ; [1][0] for device #1...
   $pcap=_PcapStartCapture($pcap_devices[0][0],"tcp and dst port 80 and tcp[tcpflags] & tcp-push != 0",0)
  
   ; Get the PID of the netflix window
   $iepid = WinGetProcess("http://movies.netflix.com/?")
  
   ConsoleWrite("WinActivate: " & WinActivate( $iehandle ) &@CRLF)
  
   ; Click in the bottom right corner to truly "activate" the IE window...
   ConsoleWrite("MouseClick: " & MouseClick( "left", @DesktopWidth, @DesktopHeight/2, 1, 0) & @CRLF)

   $ieopen = True
  
   While ( $ieopen ) ; This should loop based on test for Netflix window? (implement much later!)
      
      Sleep( 5 ) ; This makes a huge difference in CPU usage
      
       $packet=_PcapGetPacket($pcap) ; Get the packet
       If IsArray($packet) Then
          
          ; Test for input and send/do appropriate actions...
          $data = string($packet[3])
          If  stringinstr( $data, $INPUT_LEFT) <> 0  Then ; Captured Input.Left
            ConsoleWrite("Input.Left" & @CRLF)
            WinActivate( $iehandle )
            Send("+{LEFT}") ; Send Shift+LEFT for continuous seeking
         ElseIf StringInStr( $data, $INPUT_RIGHT ) <> 0 Then ; Captured Input.Right
            ConsoleWrite("Input.Right" & @CRLF)
            WinActivate( $iehandle )
            Send("+{RIGHT}") ; Send Shift+RIGHT for continuous seeking
         ElseIf stringinstr( $data, $PLAYER_PLAYPAUSE ) <> 0 Then ; Captured Player.PlayPause
            ConsoleWrite("Player.PlayPause" & @CRLF)
            WinActivate( $iehandle )
            send("{SPACE}")
         ElseIf stringinstr( $data, $INPUT_UP ) <> 0 Then ; Captured Input.Up
            ConsoleWrite("Input.Up" & @CRLF)
            WinActivate( $iehandle )
            send("{UP}")
         ElseIf stringinstr( $data, $INPUT_DOWN ) <> 0 Then ; Captured Input.Down
            ConsoleWrite("Input.Down" & @CRLF)
            WinActivate( $iehandle )
            Send("{DOWN}")
         ElseIf stringinstr( $data, $PLAYER_STOP ) <> 0 Then ; Captured Player.Stop
            ConsoleWrite("Player.Stop" & @CRLF)
            
            ; This will recursively kill all open iexplore.exe.  maybe not the cleanest thing to do...
            ; Too lazy to track down the window handles or PIDs for iexplore.exe - so just killing them all
             $iestill = True
             $i = 1
             ConsoleWrite("Trying to kill iexplore.exe..." & @CRLF)
             While( $iestill )
                $pid = ProcessExists("iexplore.exe")
                ConsoleWrite( "Attempt "& $i & " PID: "& $pid & @CRLF)
                $i = $i + 1
                if ProcessClose( $pid ) == 0 Then $iestill = False
                   Sleep(50)
             WEnd
          
           ; This will kill the IE Netflix window (though there are some weird leftover iexplore.exe floating around)
           ; I've tried WinKill, WinClose, and ProcessClose - none of them exit cleanly, but this does...
            ;Run(@ComSpec & " /c taskkill /F /PID " & $iepid & " /T", @SystemDir, @SW_HIDE)
            
            ; Too lazy to track down why there's spurious iexplore.exe showing up, so...
            ; just killing all of them that correspond to http://movies.netflix.com
;~             Local $iewins = WinList( "http://movies.netflix.com" )
;~             for $i = 1 to $iewins[0][0]
;~                WinKill( $iewins[$i][1] )
;~             Next
            
            $ieopen = False
            ConsoleWrite("Just finished closing them up..." & @CRLF)
          EndIf
       EndIf
    Wend
      _PcapStopCapture($pcap) ; Stop capture
      _PcapFree() ; release resources
    Sleep(1000)
WEnd

Hopefully someone else will get some use out of this. It's not really super fancy the way the rest of xbmc and the remote work together, but it's serviceable for 99.9% of my netflix needs (using the iOS remote).
Reply
#2
This looks great! Once I get xbmcflicks actually working, this will be my next project! Thanks
Reply
#3
Pat, both of your downloads are not working. I copied the script, and was going to use it.. but then I saw the requirement for the winpcap.au3.. Please make that available for me when you can.

Thanks for all your help with xbmcflicks! I had given up on it, but all your work on the other thread allowed me to get it functioning at last! This script here sounds like something that will make it so even my wife is able to use it!

Thanks!
Jon
Reply
#4
(2012-11-08, 02:24)jbeige Wrote: Pat, both of your downloads are not working. I copied the script, and was going to use it.. but then I saw the requirement for the winpcap.au3.. Please make that available for me when you can.

Thanks for all your help with xbmcflicks! I had given up on it, but all your work on the other thread allowed me to get it functioning at last! This script here sounds like something that will make it so even my wife is able to use it!

Thanks!
Jon

The download for wincap.au3 is here: http://opensource.grisambre.net/pcapau3/

HTH
Reply

Logout Mark Read Team Forum Stats Members Help
iOS remote for controlling XMBC Flicks (Netflix plugin)1