1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/gmyth-stream/main.py Tue Mar 27 20:27:51 2007 +0100
1.3 @@ -0,0 +1,85 @@
1.4 + '''
1.5 + # GMyth-Stream
1.6 + #
1.7 + # @file main.py
1.8 + #
1.9 + # @brief <p> Plugin for GMyth-Stream
1.10 + #
1.11 + # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
1.12 + # @author Artur Duque de Souza <artur.souza@indt.org.br>
1.13 + #
1.14 + #
1.15 + # This program is free software; you can redistribute it and/or modify
1.16 + # it under the terms of the GNU Lesser General Public License as published by
1.17 + # the Free Software Foundation; either version 2 of the License, or
1.18 + # (at your option) any later version.
1.19 + #
1.20 + # This program is distributed in the hope that it will be useful,
1.21 + # but WITHOUT ANY WARRANTY; without even the implied warranty of
1.22 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.23 + # GNU General Public License for more details.
1.24 + #
1.25 + # You should have received a copy of the GNU Lesser General Public License
1.26 + # along with this program; if not, write to the Free Software
1.27 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.28 + #
1.29 + '''
1.30 +
1.31 +#!/usr/bin/python
1.32 +
1.33 +import sys
1.34 +import os
1.35 +import ConfigParser
1.36 +
1.37 +def now():
1.38 + return time.strftime("%Y-%m-%d %H:%M:%S");
1.39 +
1.40 +
1.41 +config = ConfigParser.ConfigParser()
1.42 +config.read("stream.conf")
1.43 +
1.44 +media_plugin = config.get("Media", "engine")
1.45 +exec("from plugins.media.%s import *" % media_plugin)
1.46 +
1.47 +media = Media(config)
1.48 +
1.49 +comm_plugin = config.get("Comm", "engine")
1.50 +exec("from plugins.comm.%s import *" % comm_plugin)
1.51 +
1.52 +# Start Our Server:
1.53 +server = Server(config)
1.54 +
1.55 +print "--> Starting the server..."
1.56 +
1.57 +while (server.finish == 0):
1.58 + con, client = server.getRequest()
1.59 +
1.60 + while True:
1.61 + msg = server.getMsg(1024).strip()
1.62 +
1.63 + if not msg: break
1.64 +
1.65 + elif (msg == "SETUP"):
1.66 + setup = server.getMsg(1024).strip().split(" ")
1.67 + media.setup(setup[0], setup[1], setup[2], \
1.68 + setup[3], setup[4], setup[5])
1.69 +
1.70 + elif (msg == "PLAY"):
1.71 + media.play()
1.72 +
1.73 + elif (msg == "STOP"):
1.74 + media.stop()
1.75 +
1.76 + elif (msg == "CLOSE"):
1.77 + server.finish = 1
1.78 + media.stop()
1.79 + break
1.80 +
1.81 + print "[%s] %s: %s" % (now(), client, msg)
1.82 +
1.83 + print "[%s] Closing connection with %s" % (now(), client)
1.84 + server.disconnect_client(con)
1.85 +
1.86 +server.stop()
1.87 +
1.88 +print "--> Server stopped..."