Changeset c15f71a


Ignore:
Timestamp:
2007-09-04T16:59:28Z (17 years ago)
Author:
VMiklos <vmiklos@…>
Branches:
master
Children:
40d2dc4
Parents:
5d1b0774
Message:

skyped: use Skype4Py's X11 api
this solves all those weird freezes

Location:
skype
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • skype/README

    r5d1b0774 rc15f71a  
    6262make install
    6363----
     64
     65- Install http://skype4py.sourceforge.net/[Skype4Py].
     66
     67(You may remember that previous versions of `skyped` did not require this
     68package. This because it now uses the X11 interface of Skype (because the
     69previously used DBus interface had
     70http://forum.skype.com/index.php?s=&showtopic=94545&view=findpost&p=431710[known
     71problems]), but I wanted to prevent a large code duplication from that project.
     72In addition it then no longer requires the `dbus-python` package, just
     73`pygobject`.)
    6474
    6575- Start Skype and `skyped` (the tcp server):
     
    171181== Known bugs
    172182
    173 - Sometimes when you get a lot of messages in a short time, some of the
    174   messages are dropped. This is a known bug in Skype itself as of version
    175   1.4.0.99
    176   (http://forum.skype.com/index.php?s=&showtopic=94545&view=findpost&p=431710[link]).
     183- None at this time.
    177184
    178185== Screenshots
  • skype/skyped.py

    r5d1b0774 rc15f71a  
    3030import locale
    3131import time
    32 import dbus
    33 import dbus.service
    34 import dbus.mainloop.glib
    3532import gobject
    3633import socket
    3734import getopt
     35import Skype4Py
     36import threading
    3837
    3938__version__ = "0.1.1"
     
    4645conn = None
    4746
    48 def sig_handler(signum, frame):
    49         mainloop.quit()
    50 
    5147def input_handler(fd, io_condition):
    5248        input = fd.recv(1024)
    5349        for i in input.split("\n"):
    54                 if i:
    55                         for j in skype.send(i.strip()):
    56                                 fd.send((j + "\n").encode(locale.getdefaultlocale()[1]))
     50                skype.send(i.strip())
     51        return True
     52
     53def idle_handler(skype):
     54        skype.send("PING")
     55        try:
     56                time.sleep(10)
     57        except KeyboardInterrupt:
     58                sys.exit("Exiting.")
    5759        return True
    5860
     
    7779                print msg
    7880
    79 class SkypeApi(dbus.service.Object):
     81class SkypeApi():
    8082        def __init__(self):
    81                 bus = dbus.SessionBus()
    82                 try:
    83                         self.skype_api = bus.get_object(SKYPE_SERVICE, '/com/Skype')
    84                 except dbus.exceptions.DBusException:
    85                         sys.exit("Can't find any Skype instance. Are you sure you have started Skype?")
     83                self.skype = Skype4Py.Skype()
     84                self.skype._API.Handlers.append(Skype4Py.utils.WeakCallableRef(self.recv))
     85                self.skype._API._Handler = self.recv
     86                self.skype.Attach()
    8687
    87                 reply = self.send('NAME ' + CLIENT_NAME)
    88                 if reply[0] != 'OK':
    89                         sys.exit('Could not bind to Skype client')
     88        def recv(self, mode, msg_text):
     89                global conn
     90                if mode != "rece_api":
     91                        return
     92                if "\n" in msg_text:
     93                        # crappy skype prefixes only the first line for
     94                        # multiline messages so we need to do so for the other
     95                        # lines, too. this is something like:
     96                        # 'CHATMESSAGE id BODY first line\nsecond line' ->
     97                        # 'CHATMESSAGE id BODY first line\nCHATMESSAGE id BODY second line'
     98                        prefix = " ".join(msg_text.split(" ")[:3])
     99                        msg_text = ["%s %s" % (prefix, i) for i in " ".join(msg_text.split(" ")[3:]).split("\n")]
     100                else:
     101                        msg_text = [msg_text]
     102                for i in msg_text:
     103                        dprint('<< ' + i)
     104                        if conn:
     105                                conn.send(i + "\n")
    90106
    91                 reply = self.send('PROTOCOL 5')
    92                 try:
    93                         dbus.service.Object.__init__(self, bus, "/com/Skype/Client", bus_name='com.Skype.API')
    94                 except KeyError:
    95                         sys.exit()
    96 
    97         # skype -> client (async)
    98         @dbus.service.method(dbus_interface='com.Skype.API')
    99         def Notify(self, msg_text):
    100                 global conn
    101                 dprint('<< ' + msg_text)
    102                 if conn:
    103                         conn.send(msg_text + "\n")
    104 
    105         # client -> skype (sync, 5 sec timeout)
    106107        def send(self, msg_text):
    107108                if not len(msg_text):
     
    109110                dprint('>> ' + msg_text)
    110111                try:
    111                         reply = self.skype_api.Invoke(msg_text)
    112                 except dbus.exceptions.DBusException, s:
    113                         reply = str(s)
    114                         if(reply.startswith("org.freedesktop.DBus.Error.ServiceUnknown")):
    115                                 try:
    116                                         self.remove_from_connection(dbus.SessionBus(), "/com/Skype/Client")
    117                                 except LookupError:
    118                                         pass
    119                                 mainloop.quit()
    120                 if "\n" in reply:
    121                         # crappy skype prefixes only the first line for
    122                         # multiline messages so we need to do so for the other
    123                         # lines, too. this is something like:
    124                         # 'CHATMESSAGE id BODY first line\nsecond line' ->
    125                         # 'CHATMESSAGE id BODY first line\nCHATMESSAGE id BODY second line'
    126                         prefix = " ".join(reply.split(" ")[:3])
    127                         reply = ["%s %s" % (prefix, i) for i in " ".join(reply.split(" ")[3:]).split("\n")]
    128                 else:
    129                         reply = [reply]
    130                 for i in reply:
    131                         dprint('<< ' + i)
    132                 return reply
     112                        self.skype._DoCommand(msg_text)
     113                except Skype4Py.ISkypeError:
     114                        pass
    133115
    134116class Options:
     
    186168                        print 'skyped is started on port %s, pid: %d' % (options.port, pid)
    187169                        sys.exit(0)
    188         dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
    189         signal.signal(signal.SIGINT, sig_handler)
    190         mainloop = gobject.MainLoop()
    191170        server('0.0.0.0', options.port)
    192         while True:
     171        try:
    193172                skype = SkypeApi()
    194                 mainloop.run()
     173        except Skype4Py.errors.ISkypeAPIError, s:
     174                sys.exit("%s. Are you sure you have started Skype?" % s)
     175        gobject.idle_add(idle_handler, skype)
     176        gobject.MainLoop().run()
Note: See TracChangeset for help on using the changeset viewer.