gmyth-stream/main.py
author rosfran
Wed Mar 28 15:53:29 2007 +0100 (2007-03-28)
branchtrunk
changeset 467 bc13aaf7561d
parent 453 a806d8ad0ff0
child 470 57833200a415
permissions -rwxr-xr-x
[svn r472] Changed all the g_debug, g_warning and g_debug calls, to the gmyth_debug status/error printing function.
morphbr@453
     1
#!/usr/bin/python
morphbr@453
     2
morphbr@453
     3
import sys
morphbr@453
     4
import os
morphbr@453
     5
import ConfigParser
morphbr@453
     6
morphbr@453
     7
def now():
morphbr@453
     8
    return time.strftime("%Y-%m-%d %H:%M:%S");
morphbr@453
     9
morphbr@453
    10
morphbr@453
    11
config = ConfigParser.ConfigParser()
morphbr@453
    12
config.read("stream.conf")
morphbr@453
    13
morphbr@453
    14
media_plugin = config.get("Media", "engine")
morphbr@453
    15
exec("from plugins.media.%s import *" % media_plugin)
morphbr@453
    16
morphbr@453
    17
media = Media(config)
morphbr@453
    18
morphbr@453
    19
comm_plugin = config.get("Comm", "engine")
morphbr@453
    20
exec("from plugins.comm.%s import *" % comm_plugin)
morphbr@453
    21
morphbr@453
    22
# Start Our Server:
morphbr@453
    23
server = Server(config)
morphbr@453
    24
morphbr@453
    25
print "--> Starting the server..."
morphbr@453
    26
morphbr@453
    27
while (server.finish == 0):
morphbr@453
    28
    con, client = server.getRequest()
morphbr@453
    29
morphbr@453
    30
    while True:
morphbr@453
    31
        msg = server.getMsg(1024).strip()
morphbr@453
    32
morphbr@453
    33
        if not msg: break
morphbr@453
    34
morphbr@453
    35
        elif (msg == "SETUP"):
morphbr@453
    36
            setup = server.getMsg(1024).strip().split(" ")
morphbr@453
    37
            media.setup(setup[0], setup[1], setup[2], \
morphbr@466
    38
                        setup[3], setup[4], setup[5],
morphbr@466
    39
                        setup[6], setup[7], setup[8],
morphbr@466
    40
                        setup[9])
morphbr@453
    41
morphbr@453
    42
        elif (msg == "PLAY"):
morphbr@453
    43
            media.play()
morphbr@453
    44
morphbr@453
    45
        elif (msg == "STOP"):
morphbr@453
    46
            media.stop()
morphbr@453
    47
morphbr@453
    48
        elif (msg == "CLOSE"):
morphbr@453
    49
            server.finish = 1
morphbr@453
    50
            media.stop()
morphbr@453
    51
            break
morphbr@453
    52
morphbr@453
    53
        print "[%s] %s: %s" % (now(), client, msg)
morphbr@453
    54
morphbr@453
    55
    print "[%s] Closing connection with %s" % (now(), client)
morphbr@453
    56
    server.disconnect_client(con)
morphbr@453
    57
morphbr@453
    58
server.stop()
morphbr@466
    59
del(server)
morphbr@453
    60
print "--> Server stopped..."