gmyth-stream/main.py
author morphbr
Tue Mar 27 00:13:27 2007 +0100 (2007-03-27)
branchtrunk
changeset 453 a806d8ad0ff0
child 466 a7aba7d166fb
permissions -rwxr-xr-x
[svn r458]
     1  '''
     2  # GMyth-Stream
     3  #
     4  # @file main.py
     5  #
     6  # @brief <p> Plugin for GMyth-Stream
     7  #
     8  # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
     9  # @author Artur Duque de Souza <artur.souza@indt.org.br>
    10  #
    11  #
    12  # This program is free software; you can redistribute it and/or modify
    13  # it under the terms of the GNU Lesser General Public License as published by
    14  # the Free Software Foundation; either version 2 of the License, or
    15  # (at your option) any later version.
    16  #
    17  # This program is distributed in the hope that it will be useful,
    18  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    19  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20  # GNU General Public License for more details.
    21  #
    22  # You should have received a copy of the GNU Lesser General Public License
    23  # along with this program; if not, write to the Free Software
    24  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    25  #
    26  '''
    27 
    28 #!/usr/bin/python
    29 
    30 import sys
    31 import os
    32 import ConfigParser
    33 
    34 def now():
    35     return time.strftime("%Y-%m-%d %H:%M:%S");
    36 
    37 
    38 config = ConfigParser.ConfigParser()
    39 config.read("stream.conf")
    40 
    41 media_plugin = config.get("Media", "engine")
    42 exec("from plugins.media.%s import *" % media_plugin)
    43 
    44 media = Media(config)
    45 
    46 comm_plugin = config.get("Comm", "engine")
    47 exec("from plugins.comm.%s import *" % comm_plugin)
    48 
    49 # Start Our Server:
    50 server = Server(config)
    51 
    52 print "--> Starting the server..."
    53 
    54 while (server.finish == 0):
    55     con, client = server.getRequest()
    56 
    57     while True:
    58         msg = server.getMsg(1024).strip()
    59 
    60         if not msg: break
    61 
    62         elif (msg == "SETUP"):
    63             setup = server.getMsg(1024).strip().split(" ")
    64             media.setup(setup[0], setup[1], setup[2], \
    65                         setup[3], setup[4], setup[5])
    66 
    67         elif (msg == "PLAY"):
    68             media.play()
    69 
    70         elif (msg == "STOP"):
    71             media.stop()
    72 
    73         elif (msg == "CLOSE"):
    74             server.finish = 1
    75             media.stop()
    76             break
    77 
    78         print "[%s] %s: %s" % (now(), client, msg)
    79 
    80     print "[%s] Closing connection with %s" % (now(), client)
    81     server.disconnect_client(con)
    82 
    83 server.stop()
    84 
    85 print "--> Server stopped..."