Changeset 81d4220ba0feab8bdd6f39101f7bea2f451b9a98
- Timestamp:
- 04/06/08 02:56:37
(8 months ago)
- Author:
- Jason Michalski <armooo@armooo.net>
- git-committer:
- Jason Michalski <armooo@armooo.net> 1207468597 -0500
- git-parent:
[89e245b95b5b8d87474ac0fc936cbfc82ab9c158]
- git-author:
- Jason Michalski <armooo@armooo.net> 1207468597 -0500
- Message:
web video should be working.
The xmpp libary was changed so we should now have windows support
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r89e245b |
r81d4220 |
|
| 3 | 3 | import config |
|---|
| 4 | 4 | |
|---|
| 5 | | import pyxmpp.jabber.client |
|---|
| 6 | | from pyxmpp.all import * |
|---|
| 7 | | from pyxmpp.streamtls import TLSSettings |
|---|
| | 5 | import xmpp |
|---|
| 8 | 6 | |
|---|
| 9 | 7 | import threading |
|---|
| … | … | |
| 12 | 10 | CLASS_NAME = 'WebVideo' |
|---|
| 13 | 11 | |
|---|
| 14 | | sem = threading.Semaphore(1) |
|---|
| 15 | | |
|---|
| 16 | | |
|---|
| 17 | 12 | |
|---|
| 18 | 13 | class WebVideo(Video): |
|---|
| 19 | | |
|---|
| | 14 | |
|---|
| 20 | 15 | CONTENT_TYPE = 'x-not-for/tivo' |
|---|
| 21 | 16 | |
|---|
| 22 | 17 | def init(self): |
|---|
| 23 | | c = XmppListener(self) |
|---|
| 24 | | c.connect() |
|---|
| 25 | | |
|---|
| 26 | | t = threading.Thread(target=c.loop) |
|---|
| | 18 | self.sem = threading.Semaphore(1) |
|---|
| | 19 | |
|---|
| | 20 | self.startXMPP() |
|---|
| | 21 | self.xmpp_cdsupdate() |
|---|
| | 22 | |
|---|
| | 23 | def startXMPP(self): |
|---|
| | 24 | m = mind.getMind() |
|---|
| | 25 | xmpp_info = m.getXMPPLoginInfo() |
|---|
| | 26 | |
|---|
| | 27 | jid=xmpp.protocol.JID(xmpp_info['username'] + '/pyTivo') |
|---|
| | 28 | cl=xmpp.Client( |
|---|
| | 29 | server=xmpp_info['server'], |
|---|
| | 30 | port=xmpp_info['port'], |
|---|
| | 31 | ) |
|---|
| | 32 | |
|---|
| | 33 | cl.connect() |
|---|
| | 34 | cl.RegisterHandler('message', self.processMessage) |
|---|
| | 35 | cl.auth(user=jid.getNode(), password=config.getTivoPassword(), resource='pyTivo') |
|---|
| | 36 | |
|---|
| | 37 | cl.sendInitPresence(requestRoster=0) |
|---|
| | 38 | |
|---|
| | 39 | for user_name in xmpp_info['presence_list']: |
|---|
| | 40 | jid=xmpp.protocol.JID(user_name) |
|---|
| | 41 | cl.sendPresence(jid) |
|---|
| | 42 | |
|---|
| | 43 | |
|---|
| | 44 | t = threading.Thread(target=self.processXMPP, args=(cl,)) |
|---|
| 27 | 45 | t.setDaemon(True) |
|---|
| 28 | 46 | t.start() |
|---|
| 29 | | self.xmppCdsupdate() |
|---|
| | 47 | |
|---|
| | 48 | def processXMPP(self, client): |
|---|
| | 49 | while client.Process(): |
|---|
| | 50 | pass |
|---|
| | 51 | |
|---|
| | 52 | def processMessage(self, sess,mess): |
|---|
| | 53 | xmpp_action = ElementTree.fromstring(mess.getBody()) |
|---|
| | 54 | |
|---|
| | 55 | method_name = 'xmpp_' + xmpp_action.findtext('action').lower() |
|---|
| | 56 | if not hasattr(self, method_name): |
|---|
| | 57 | return False |
|---|
| | 58 | |
|---|
| | 59 | method = getattr(self, method_name) |
|---|
| | 60 | method(xmpp_action) |
|---|
| 30 | 61 | |
|---|
| 31 | 62 | |
|---|
| 32 | | def xmppCdsupdate(self): |
|---|
| | 63 | def xmpp_cdsupdate(self, xml=None): |
|---|
| 33 | 64 | m = mind.getMind() |
|---|
| 34 | 65 | for request in m.getDownloadRequests(): |
|---|
| … | … | |
| 43 | 74 | import urllib |
|---|
| 44 | 75 | |
|---|
| 45 | | sem.acquire() |
|---|
| | 76 | for share_name, settings in config.getShares(): |
|---|
| | 77 | if settings['type'] == 'webvideo': |
|---|
| | 78 | break |
|---|
| 46 | 79 | |
|---|
| 47 | | path = '/home/armooo/Videos/web' |
|---|
| | 80 | self.sem.acquire() |
|---|
| 48 | 81 | |
|---|
| | 82 | path = settings['path'] |
|---|
| 49 | 83 | file_name = os.path.join(path, '%s-%s' % (data['bodyOfferId'] ,data['url'].split('/')[-1])) |
|---|
| 50 | 84 | |
|---|
| … | … | |
| 62 | 96 | file_info.update(self.metadata_full(file_name, tsn)) |
|---|
| 63 | 97 | |
|---|
| 64 | | data['url'] = 'http://10.0.1.51:9032' + urllib.quote('/WebVideo/%s' % os.path.split(file_name)[-1]) |
|---|
| | 98 | import socket |
|---|
| | 99 | s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|---|
| | 100 | s.connect(('tivo.com',123)) |
|---|
| | 101 | ip = s.getsockname()[0] |
|---|
| | 102 | port = config.getPort() |
|---|
| | 103 | |
|---|
| | 104 | data['url'] = 'http://%s:%s' % (ip, port) + urllib.quote('/%s/%s' % (share_name, os.path.split(file_name)[-1])) |
|---|
| 65 | 105 | data['duration'] = file_info['duration'] / 1000 |
|---|
| 66 | 106 | data['size'] = file_info['size'] |
|---|
| … | … | |
| 71 | 111 | m.completeDownloadRequest(data) |
|---|
| 72 | 112 | |
|---|
| 73 | | sem.release() |
|---|
| | 113 | self.sem.release() |
|---|
| 74 | 114 | |
|---|
| 75 | | |
|---|
| 76 | | class XmppListener(Client): |
|---|
| 77 | | def __init__(self, web_video): |
|---|
| 78 | | m = mind.getMind() |
|---|
| 79 | | xmpp_info = m.getXMPPLoginInfo() |
|---|
| 80 | | |
|---|
| 81 | | Client.__init__(self, |
|---|
| 82 | | jid=JID(xmpp_info['username'] + '/pyTivo'), |
|---|
| 83 | | password=config.getTivoPassword(), |
|---|
| 84 | | server=xmpp_info['server'], |
|---|
| 85 | | port=xmpp_info['port'], |
|---|
| 86 | | tls_settings=TLSSettings(verify_peer=False), |
|---|
| 87 | | auth_methods = ('sasl:plain',), |
|---|
| 88 | | ) |
|---|
| 89 | | |
|---|
| 90 | | self.web_video = web_video |
|---|
| 91 | | self.presence_list = xmpp_info['presence_list'] |
|---|
| 92 | | |
|---|
| 93 | | def session_started(self): |
|---|
| 94 | | self.stream.set_message_handler(None, self.message) |
|---|
| 95 | | |
|---|
| 96 | | p = Presence() |
|---|
| 97 | | self.stream.send(p) |
|---|
| 98 | | for p in self.presence_list: |
|---|
| 99 | | print p |
|---|
| 100 | | p = Presence(to_jid=JID(p)) |
|---|
| 101 | | self.stream.send(p) |
|---|
| 102 | | |
|---|
| 103 | | def message(self,stanza): |
|---|
| 104 | | xmpp_action = ElementTree.fromstring(stanza.get_body()) |
|---|
| 105 | | |
|---|
| 106 | | method_name = 'xmpp_' + xmpp_action.findtext('action').lower() |
|---|
| 107 | | if not hasattr(self, method_name): |
|---|
| 108 | | return False |
|---|
| 109 | | |
|---|
| 110 | | method = getattr(self, method_name) |
|---|
| 111 | | method(xmpp_action) |
|---|
| 112 | | return True |
|---|
| 113 | | |
|---|
| 114 | | def xmpp_cdsupdate(self, xml): |
|---|
| 115 | | self.web_video.xmppCdsupdate() |
|---|
| 116 | | |
|---|