web video should be working.
authorJason Michalski <armooo@armooo.net>
Sun, 6 Apr 2008 07:56:37 +0000 (6 02:56 -0500)
committerJason Michalski <armooo@armooo.net>
Sun, 6 Apr 2008 07:56:37 +0000 (6 02:56 -0500)
The xmpp libary was changed so we should now have windows support

plugins/webvideo/webvideo.py

index e07f009..0610210 100644 (file)
@@ -2,34 +2,65 @@ from plugins.video.video import Video, VideoDetails
 import mind
 import config
 
-import pyxmpp.jabber.client
-from pyxmpp.all import *
-from pyxmpp.streamtls import TLSSettings
+import xmpp
 
 import threading
 import xml.etree.ElementTree as ElementTree
 
 CLASS_NAME = 'WebVideo'
 
-sem = threading.Semaphore(1)
-
-
 
 class WebVideo(Video):
-    
+
     CONTENT_TYPE = 'x-not-for/tivo'
 
     def init(self):
-        c = XmppListener(self)
-        c.connect()
-        
-        t = threading.Thread(target=c.loop)
+        self.sem = threading.Semaphore(1)
+
+        self.startXMPP()
+        self.xmpp_cdsupdate()
+
+    def startXMPP(self):
+        m = mind.getMind()
+        xmpp_info = m.getXMPPLoginInfo()
+
+        jid=xmpp.protocol.JID(xmpp_info['username'] + '/pyTivo')
+        cl=xmpp.Client(
+            server=xmpp_info['server'],
+            port=xmpp_info['port'],
+        )
+
+        cl.connect()
+        cl.RegisterHandler('message', self.processMessage)
+        cl.auth(user=jid.getNode(), password=config.getTivoPassword(), resource='pyTivo')
+
+        cl.sendInitPresence(requestRoster=0)
+
+        for user_name in xmpp_info['presence_list']:
+            jid=xmpp.protocol.JID(user_name)
+            cl.sendPresence(jid)
+
+
+        t = threading.Thread(target=self.processXMPP, args=(cl,))
         t.setDaemon(True)
         t.start()
-        self.xmppCdsupdate()
+
+    def processXMPP(self, client):
+        while client.Process():
+            pass
+
+    def processMessage(self, sess,mess):
+        xmpp_action = ElementTree.fromstring(mess.getBody())
+
+        method_name = 'xmpp_' + xmpp_action.findtext('action').lower()
+        if not hasattr(self, method_name):
+            return False
+
+        method = getattr(self, method_name)
+        method(xmpp_action)
 
 
-    def xmppCdsupdate(self):
+    def xmpp_cdsupdate(self, xml=None):
         m = mind.getMind()
         for request in m.getDownloadRequests():
             t = threading.Thread(target=self.processDlRequest, args=(request,))
@@ -42,10 +73,13 @@ class WebVideo(Video):
         import urllib2
         import urllib
 
-        sem.acquire()
+        for share_name, settings in config.getShares():
+            if settings['type'] == 'webvideo':
+                break
 
-        path = '/home/armooo/Videos/web'
+        self.sem.acquire()
 
+        path = settings['path']
         file_name = os.path.join(path, '%s-%s' % (data['bodyOfferId'] ,data['url'].split('/')[-1]))
 
         print 'downloading %s to %s' % (data['url'], file_name)
@@ -61,7 +95,13 @@ class WebVideo(Video):
         file_info = VideoDetails()
         file_info.update(self.metadata_full(file_name, tsn))
 
-        data['url'] = 'http://10.0.1.51:9032' + urllib.quote('/WebVideo/%s' % os.path.split(file_name)[-1])
+        import socket
+        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+        s.connect(('tivo.com',123))
+        ip = s.getsockname()[0]
+        port = config.getPort()
+
+        data['url'] = 'http://%s:%s' % (ip, port) + urllib.quote('/%s/%s' % (share_name, os.path.split(file_name)[-1]))
         data['duration'] = file_info['duration'] / 1000
         data['size'] = file_info['size']
 
@@ -70,47 +110,5 @@ class WebVideo(Video):
         m = mind.getMind()
         m.completeDownloadRequest(data)
 
-        sem.release()
-
-        
-class XmppListener(Client):
-    def __init__(self, web_video):
-        m = mind.getMind()
-        xmpp_info = m.getXMPPLoginInfo()
-
-        Client.__init__(self,
-            jid=JID(xmpp_info['username'] + '/pyTivo'), 
-            password=config.getTivoPassword(), 
-            server=xmpp_info['server'],
-            port=xmpp_info['port'], 
-            tls_settings=TLSSettings(verify_peer=False), 
-            auth_methods = ('sasl:plain',),
-        )
-
-        self.web_video = web_video
-        self.presence_list = xmpp_info['presence_list']
-
-    def session_started(self):
-        self.stream.set_message_handler(None, self.message)
-
-        p = Presence()
-        self.stream.send(p)
-        for p in self.presence_list:
-            print p
-            p = Presence(to_jid=JID(p))
-            self.stream.send(p)
-
-    def message(self,stanza):
-        xmpp_action = ElementTree.fromstring(stanza.get_body())
-
-        method_name = 'xmpp_' + xmpp_action.findtext('action').lower()
-        if not hasattr(self, method_name):
-            return False
-        
-        method = getattr(self, method_name)
-        method(xmpp_action)
-        return True
-
-    def xmpp_cdsupdate(self, xml):
-        self.web_video.xmppCdsupdate()
+        self.sem.release()