[Solved] Improve Existing Python Addon (Newbie)
#1
Hi Gang,

I have been struggling trying to improve the YAC Listener addon, but have not been able to contact the developer.

YAC Listener basically displays Caller ID on your XBMC machine when a phone call comes in. I have it working great on my home network.

But I want to add the ability to ALSO pause the playback on the XBMC machines when a call is received, so someone can go answer the phone.

The whole addon is this code:

Code:
import socket, threading, thread, sys, asyncore, xbmc, xbmcgui
from time import *
from string import *

PORT = 10629

class Server(asyncore.dispatcher):
    def __init__(self, host, port):
        asyncore.dispatcher.__init__(self)
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.bind((host, port))
        self.listen(1)

    def handle_accept(self):
        socket, address = self.accept()
        ConnectionHandler(socket)

    def handle_close(self):
        self.close()

class ConnectionHandler(asyncore.dispatcher_with_send):
    def handle_read(self):
        self.buffer = self.recv(1024)
        self.buffer = split(self.buffer[5:], "~")
        self.close()
        global data
        if len(self.buffer) > 1:
            name = self.buffer[0]
            number = self.buffer[1]
            xbmc.executebuiltin("XBMC.Notification("+name+","+number+",7000,special://home/addons/script.yaclistener/phone.png)")
        else:
            data = self.buffer

s = Server('', PORT)

while not xbmc.abortRequested:
    asyncore.loop(timeout=1)

s.close()
sys.exit()

You can see towards the bottom there is a line that reads:

Code:
xbmc.executebuiltin("XBMC.Notification("+name+","+number+",7000,special://home/addons/script.yaclistener/phone.png)")


Below that line, I added a line that reads:
Code:
xbmc.executebuiltin("XBMC.Action(Pause)")

BUT, I got a Python error when rebooting my XBMC. Then I tried replacing the Notification line with the Pause line; a phone call properly paused playback on XBMC.

So either line works independently, but when use together, it does not work.

Can someone please help me solve this... any advice or guidance is greatly appreciated.

Thanks,

Hernando
Image
Reply
#2
Whats the error?

Try putting some time between the two requests with:
Code:
xbmc.sleep(100)
Reply
#3
Thank you Karnagious... the error comes up the minute I boot up XBMC (Openelec). In other words, the error happens I guess when the system tries to load the service... not when it activates it....

I tried adding the line above right below the notification line and wen I start the computer, I get "addon Error" addon.py. And when I try a phone call, XBMC does nothing.

Any ideas?

Thanks,

H.
Image
Reply
#4
Can you post the error message from the log file as well as the code that triggers the error.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#5
Thank you Paraguayo...

II believe the error log is this:

Code:
11:15:35 T:139824354793216   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.IndentationError'>
                                            Error Contents: ('unexpected indent', ('/storage/.xbmc/addons/script.yaclistener/addon.py', 31, 3, '\t\t\txbmc.executebuiltin("XBMC.Action(Pause)")\n'))
                                            IndentationError: ('unexpected indent', ('/storage/.xbmc/addons/script.yaclistener/addon.py', 31, 3, '\t\t\txbmc.executebuiltin("XBMC.Action(Pause)")\n'))
                                            -->End of Python script error report<--

The complete code pf addon.py is:

Code:
import socket, threading, thread, sys, asyncore, xbmc, xbmcgui
from time import *
from string import *

PORT = 10629

class Server(asyncore.dispatcher):
    def __init__(self, host, port):
        asyncore.dispatcher.__init__(self)
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.bind((host, port))
        self.listen(1)

    def handle_accept(self):
        socket, address = self.accept()
        ConnectionHandler(socket)

    def handle_close(self):
        self.close()

class ConnectionHandler(asyncore.dispatcher_with_send):
    def handle_read(self):
        self.buffer = self.recv(1024)
        self.buffer = split(self.buffer[5:], "~")
        self.close()
        global data
        if len(self.buffer) > 1:
            name = self.buffer[0]
            number = self.buffer[1]
            xbmc.executebuiltin("XBMC.Notification("+name+","+number+",7000,special://home/addons/script.yaclistener/phone.png)")
            xbmc.executebuiltin("XBMC.Action(Pause)")
        else:
            data = self.buffer

s = Server('', PORT)

while not xbmc.abortRequested:
    asyncore.loop(timeout=1)

s.close()
sys.exit()

I read in the error about indentation.... I think my indents look consistent... I am sure I am missing something obvious...
Image
Reply
#6
SOLVED IT!!!!

I think I was using the wrong text editor... I opened the file cleanly with Sublime and it works....

Sorry for the dumb mistake and thank you for all the help!!
Image
Reply

Logout Mark Read Team Forum Stats Members Help
[Solved] Improve Existing Python Addon (Newbie)0