gmyth-stream/main.py
author morphbr
Fri Mar 30 23:12:52 2007 +0100 (2007-03-30)
branchtrunk
changeset 473 b94790c04fd5
parent 470 57833200a415
child 474 07c12d2ceddf
permissions -rwxr-xr-x
[svn r478] * GMyth-Stream:
- Fixed bug regarding buffer length
     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             if ( len(setup) == 10 ):
    37                 media.setup(setup[0], setup[1], setup[2], \
    38                             setup[3], setup[4], setup[5],
    39                             setup[6], setup[7], setup[8],
    40                             setup[9])
    41 
    42                 server.Ack("SETUP")
    43 
    44             else:
    45                 lib.log("Wrong SETUP command from: %s" % client[0])
    46 
    47         elif (msg == "PLAY"):
    48             media.play()
    49             server.Ack("PLAY")
    50 
    51         elif (msg == "STOP"):
    52             media.stop()
    53             server.Ack("STOP")
    54 
    55         elif (msg == "CLOSE"):
    56             server.finish = 1
    57             media.stop()
    58             server.Ack("CLOSE")
    59             break
    60 
    61     lib.log("Closing connection with %s" % client[0])
    62     server.disconnect_client(con)
    63 
    64 server.stop()
    65 del(server)
    66 lib.log("Server stopped. Closing...")
    67