gmyth-stream/main.py
author melunko
Tue Apr 03 14:58:30 2007 +0100 (2007-04-03)
branchtrunk
changeset 482 bf3ac902013e
parent 474 07c12d2ceddf
permissions -rwxr-xr-x
[svn r487] Removed unitialized warning on gmyth_jobqueue.c
     1 #!/usr/bin/python
     2 
     3 import os
     4 import lib
     5 import sys
     6 import ConfigParser
     7 
     8 config = ConfigParser.ConfigParser()
     9 config.read("stream.conf")
    10 
    11 media_plugin = config.get("Media", "engine")
    12 exec("from plugins.media.%s import *" % media_plugin)
    13 
    14 media = Media(config)
    15 
    16 comm_plugin = config.get("Comm", "engine")
    17 exec("from plugins.comm.%s import *" % comm_plugin)
    18 
    19 # Start Our Server:
    20 server = Server(config)
    21 
    22 lib.log("Starting GMyth-Stream server")
    23 
    24 while (server.finish == 0):
    25     con, client = server.getRequest()
    26 
    27     while True:
    28         msg = server.getMsg(1024).strip()
    29 
    30         if not msg: break
    31 
    32         lib.log("Received %s from: %s" % (msg, client) )
    33 
    34         if (msg == "SETUP"):
    35             setup = server.getMsg(1024).strip().split(" ")
    36             size = len(setup)
    37             options = []
    38 
    39             if ( size < 10 ):
    40                 server.sendMsg(lib.log("Wrong SETUP command from: %s" % client[0]))
    41 
    42             else:
    43 
    44                 if ( size > 10 ):
    45                     i = 10
    46                     while (i < size):
    47                         options.append(setup[i])
    48                         i += 1
    49 
    50                 ret = media.setup(setup[0], setup[1], setup[2], \
    51                                   setup[3], setup[4], setup[5],
    52                                   setup[6], setup[7], setup[8],
    53                                   setup[9], options)
    54 
    55                 if (ret == 0):
    56                     server.Ack("SETUP")
    57                 else:
    58                     server.sendMsg(lib.log(ret))
    59 
    60 
    61         elif (msg == "PLAY"):
    62             media.play()
    63             server.Ack("PLAY")
    64 
    65         elif (msg == "STOP"):
    66             media.stop()
    67             server.Ack("STOP")
    68 
    69         elif (msg == "CLOSE"):
    70             server.finish = 1
    71             media.stop()
    72             server.Ack("CLOSE")
    73             break
    74 
    75     lib.log("Closing connection with %s" % client[0])
    76     server.disconnect_client(con)
    77 
    78 server.stop()
    79 del(server)
    80 lib.log("Server stopped. Closing...")
    81