Kodi Community Forum
[LINUX] Simple Python help needed to open / close Hulu Desktop? - 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: [LINUX] Simple Python help needed to open / close Hulu Desktop? (/showthread.php?tid=69061)



[LINUX] Simple Python help needed to open / close Hulu Desktop? - Zoon0n - 2010-01-31

Hey all -

After several days of frustration, I'm finally throwing in the towel and reaching out to the XBMC forum for a bit of programming help.

Basically, I'm hoping to recreate SophT's mod (which I was successfully able to do on my Windows 7 machine) using only Python scripts. As you can see, he used AHK files which aren't available in Linux.

What I need is a Python script that does the following:

- Upon click, launches Hulu Desktop
- After Hulu Desktop is opened, closes XBMC
- Waits until it recognizes Hulu Desktop is closed
- When Hulu Desktop is closed, runs XBMC

I have already modified my favorite skin (Alaska) to change "Programs" to read "Hulu Desktop" and successfully launch the following Python script:

Quote:import os
os.system("huludesktop")

The problem is, this only opens Hulu Desktop and leaves XBMC running in the background. Not only does this hog CPU cycles on my little Acer Aspire Revo 1600, but it means that the remote button presses are being registered in XBMC, causing all kinds of havoc. And sadly, I don't know enough Python to be able to perform the tasks I want and my search throughout the internet has gotten me no where.

Any solutions and/or a nicely written script I can copy/paste? Big Grin


- DDM123 - 2010-01-31

I'm sure there's a better solution out there, but I use irexec to kill xbmc and launch huludesktop. I'm pretty sure you'll need a window manager for this, and I use fluxbox. So with irexec running, I use the color buttons of my MCE style remote to run scripts like /usr/local/bin/yellowHulu
Code:
#!/bin/bash
killall xbmc.bin
killall Boxee
killall firefox
killall huludesktop
killall npviewer.bin
sleep 1
huludesktop -f &

And I added this section to ~/.lircrc
Code:
begin
        remote = mceusb
        button = Yellow
        prog   = irexec
        repeat = 0
        config = yellowHulu
    end

I edited ~/.fluxbox/startup to launch a program called irexecstart which contains
Code:
#!/bin/bash

#test to see if an instance of irxevent is already running


if ps -ef|grep -v grep|grep irexec
then
# do nothing
echo IRexec is running

else
# start irexec
irexec -d &

fi


And of course there is a similar set which kills huludesktop and starts XBMC.


- Zoon0n - 2010-01-31

Forgot to mention that I'm running XBMC on top of Ubuntu 9.10 Wink So the window manager aspect is covered.

And while this is a great way to launch Hulu Desktop and kill XBMC using a dedicated button on the remote, the goal is to modify the skin so that upon click it will automatically run a script (aka seamless integration with XBMC).

I decided to change my approach and write a Python script which then calls an executable Bash code:

hululauncher.py
Code:
#!/usr/local/bin/python

import subprocess
def app():
    subprocess.call("/home/xbmc/.xbmc/huluscript.sh", executable="bash", shell=True)

if __name__ == '__main__':
    app()

^^ This calls huluscript.sh which I made executable by chmod +x

Code:
#!/bin/bash
fuction func1
{
    killall xbmc.bin
    sleep 1
    huludesktop &
}

func1

This successfully kills XBMC, waits 1 second, then launches Hulu Desktop (halfway there!). Now does anyone know the how I can get the Bash script to wait for Hulu Desktop to close and relaunch XBMC?


- whyisthisopen - 2010-02-01

Code:
#!/bin/bash

killall xbmc.bin
sleep 2
huludesktop
xbmc &

Here, just do this to wait for hulu to finish and then launch xbmc. This script works fine if launched from the command line.


I'm having problems launching the bash script from a plugin. I have put the python, bash script and a .tbn file into a folder to make a plugin but when it is launched the xbmc plugin screen stays visible and I can't see hulu. (Hulu does work and xbmc isn't running, but the display is frozen.)

I will report back if I find out what is causing this, until then input is welcomed.


- aeiah - 2010-02-01

is there a crash log telling you anything?

how are you launching the initial python script? as far as i know, xbmc launches python plugins using its own internal python.

so maybe the bash script is getting killed because it kills its parent, your plugin, by killing xbmc. does that make sense? if not already, it might be worth launching the bash script using the program launcher so it won't die when xbmc's python engine dies.


- JackieBrown - 2010-02-02

I use the instructions here
http://forum.xbmc.org/showpost.php?p=476403&postcount=21
It even works without a desktop loaded (I autolaunch xbmc using startx and a modified .xiniitc)