Enable SSDP responses over UDP. Initial MediaServer implementation. Camera discovers the server and starts the backup.
1 parent 8b33ec3 commit 7a65af0cef0bb45e441aec17e3c49bfad36bccc7
@Jeff Rebeiro Jeff Rebeiro authored on 3 Feb 2013
Showing 3 changed files
View
3
■■
common.py
import os
import socket
import uuid
 
# TODO(jrebeiro): Move the CONFIG_FILE variable to the main runnable module
CONFIG_FILE = os.path.expanduser("~/pc-autobackup.cfg")
 
 
def LoadOrCreateConfig():
"""Load an existing configuration or create one."""
config = ConfigParser.RawConfigParser()
# TODO(jrebeiro): Move the CONFIG_FILE variable to the main runnable module
config.read(CONFIG_FILE)
 
if not config.has_section('AUTOBACKUP'):
config.add_section('AUTOBACKUP')
with open(CONFIG_FILE, 'wb') as config_file:
config.write(config_file)
 
return config
View
37
mediaserver.py
#!/usr/bin/python
#
# Copyright 2013 Jeff Rebeiro (jeff@rebeiro.net) All rights reserved
# Simple UPNP implementation for PC Autobackup
# Simple UPNP MediaServer implementation for PC Autobackup
 
__author__ = 'jeff@rebeiro.net (Jeff Rebeiro)'
 
import HTMLParser
 
from twisted.internet import reactor
from twisted.web.resource import Resource
from twisted.web.server import Site
 
import common
 
X_BACKUP_RESPONSE = '''<?xml version="1.0"?>
</device>
</root>'''
 
 
class MediaServer(Resource):
 
isLeaf = True
 
def __init__(self):
self.config = common.LoadOrCreateConfig()
 
def render_GET(self, request):
if request.path == '/DMS/SamsungDmsDesc.xml':
return self.GetDMSDescription()
 
def GetDMSDescription(self):
response = DMS_DESC % {'friendly_name': self.config.get('AUTOBACKUP',
'server_name'),
'uuid': self.config.get('AUTOBACKUP', 'uuid')}
if __name__ == '__main__':
print "Response:"
print response
 
return response
 
def StartMediaServer():
resource = MediaServer()
factory = Site(resource)
reactor.listenTCP(52235, factory)
reactor.run()
 
 
def main():
config = common.LoadOrCreateConfig()
StartMediaServer()
 
 
if __name__ == "__main__":
main()
View
ssdp.py