Changeset c15f71a
- Timestamp:
- 2007-09-04T16:59:28Z (17 years ago)
- Branches:
- master
- Children:
- 40d2dc4
- Parents:
- 5d1b0774
- Location:
- skype
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
skype/README
r5d1b0774 rc15f71a 62 62 make install 63 63 ---- 64 65 - Install http://skype4py.sourceforge.net/[Skype4Py]. 66 67 (You may remember that previous versions of `skyped` did not require this 68 package. This because it now uses the X11 interface of Skype (because the 69 previously used DBus interface had 70 http://forum.skype.com/index.php?s=&showtopic=94545&view=findpost&p=431710[known 71 problems]), but I wanted to prevent a large code duplication from that project. 72 In addition it then no longer requires the `dbus-python` package, just 73 `pygobject`.) 64 74 65 75 - Start Skype and `skyped` (the tcp server): … … 171 181 == Known bugs 172 182 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. 177 184 178 185 == Screenshots -
skype/skyped.py
r5d1b0774 rc15f71a 30 30 import locale 31 31 import time 32 import dbus33 import dbus.service34 import dbus.mainloop.glib35 32 import gobject 36 33 import socket 37 34 import getopt 35 import Skype4Py 36 import threading 38 37 39 38 __version__ = "0.1.1" … … 46 45 conn = None 47 46 48 def sig_handler(signum, frame):49 mainloop.quit()50 51 47 def input_handler(fd, io_condition): 52 48 input = fd.recv(1024) 53 49 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 53 def idle_handler(skype): 54 skype.send("PING") 55 try: 56 time.sleep(10) 57 except KeyboardInterrupt: 58 sys.exit("Exiting.") 57 59 return True 58 60 … … 77 79 print msg 78 80 79 class SkypeApi( dbus.service.Object):81 class SkypeApi(): 80 82 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() 86 87 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") 90 106 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 conn101 dprint('<< ' + msg_text)102 if conn:103 conn.send(msg_text + "\n")104 105 # client -> skype (sync, 5 sec timeout)106 107 def send(self, msg_text): 107 108 if not len(msg_text): … … 109 110 dprint('>> ' + msg_text) 110 111 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 133 115 134 116 class Options: … … 186 168 print 'skyped is started on port %s, pid: %d' % (options.port, pid) 187 169 sys.exit(0) 188 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)189 signal.signal(signal.SIGINT, sig_handler)190 mainloop = gobject.MainLoop()191 170 server('0.0.0.0', options.port) 192 while True:171 try: 193 172 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.