gmyth-stream/main.py
author morphbr
Sat Mar 31 00:55:28 2007 +0100 (2007-03-31)
branchtrunk
changeset 474 07c12d2ceddf
parent 471 2eef40885322
child 475 2521ec986005
permissions -rwxr-xr-x
[svn r479] * GMyth-Stream:
- Error handling: file does not exist on setup (mencoder)
morphbr@453
     1
#!/usr/bin/python
morphbr@453
     2
morphbr@470
     3
import os
morphbr@470
     4
import lib
morphbr@453
     5
import sys
morphbr@453
     6
import ConfigParser
morphbr@453
     7
morphbr@453
     8
config = ConfigParser.ConfigParser()
morphbr@453
     9
config.read("stream.conf")
morphbr@453
    10
morphbr@453
    11
media_plugin = config.get("Media", "engine")
morphbr@453
    12
exec("from plugins.media.%s import *" % media_plugin)
morphbr@453
    13
morphbr@453
    14
media = Media(config)
morphbr@453
    15
morphbr@453
    16
comm_plugin = config.get("Comm", "engine")
morphbr@453
    17
exec("from plugins.comm.%s import *" % comm_plugin)
morphbr@453
    18
morphbr@453
    19
# Start Our Server:
morphbr@453
    20
server = Server(config)
morphbr@453
    21
morphbr@470
    22
lib.log("Starting GMyth-Stream server")
morphbr@453
    23
morphbr@453
    24
while (server.finish == 0):
morphbr@453
    25
    con, client = server.getRequest()
morphbr@453
    26
morphbr@453
    27
    while True:
morphbr@453
    28
        msg = server.getMsg(1024).strip()
morphbr@453
    29
morphbr@453
    30
        if not msg: break
morphbr@453
    31
morphbr@470
    32
        lib.log("Received %s from: %s" % (msg, client) )
morphbr@470
    33
morphbr@470
    34
        if (msg == "SETUP"):
morphbr@453
    35
            setup = server.getMsg(1024).strip().split(" ")
morphbr@470
    36
            if ( len(setup) == 10 ):
morphbr@474
    37
                ret = media.setup(setup[0], setup[1], setup[2], \
morphbr@474
    38
                                  setup[3], setup[4], setup[5],
morphbr@474
    39
                                  setup[6], setup[7], setup[8],
morphbr@474
    40
                                  setup[9])
morphbr@470
    41
morphbr@474
    42
                if (ret == 0):
morphbr@474
    43
                    server.Ack("SETUP")
morphbr@474
    44
                else:
morphbr@474
    45
                    server.sendMsg(lib.log("File does not exist: %s" % setup[0]))
morphbr@470
    46
morphbr@470
    47
            else:
morphbr@474
    48
                server.sendMsg(lib.log("Wrong SETUP command from: %s" % client[0]))
morphbr@453
    49
morphbr@453
    50
        elif (msg == "PLAY"):
morphbr@453
    51
            media.play()
morphbr@470
    52
            server.Ack("PLAY")
morphbr@453
    53
morphbr@453
    54
        elif (msg == "STOP"):
morphbr@453
    55
            media.stop()
morphbr@470
    56
            server.Ack("STOP")
morphbr@453
    57
morphbr@453
    58
        elif (msg == "CLOSE"):
morphbr@453
    59
            server.finish = 1
morphbr@453
    60
            media.stop()
morphbr@470
    61
            server.Ack("CLOSE")
morphbr@453
    62
            break
morphbr@453
    63
morphbr@470
    64
    lib.log("Closing connection with %s" % client[0])
morphbr@453
    65
    server.disconnect_client(con)
morphbr@453
    66
morphbr@453
    67
server.stop()
morphbr@466
    68
del(server)
morphbr@470
    69
lib.log("Server stopped. Closing...")
morphbr@470
    70