gmyth-stream/main.py
author rosfran
Fri Mar 30 23:09:39 2007 +0100 (2007-03-30)
branchtrunk
changeset 472 e5618b012121
parent 470 57833200a415
child 474 07c12d2ceddf
permissions -rwxr-xr-x
[svn r477] Added functions to get the channel's list from the MythTV, using the normal backend server messages.
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@470
    37
                media.setup(setup[0], setup[1], setup[2], \
morphbr@470
    38
                            setup[3], setup[4], setup[5],
morphbr@470
    39
                            setup[6], setup[7], setup[8],
morphbr@470
    40
                            setup[9])
morphbr@470
    41
morphbr@470
    42
                server.Ack("SETUP")
morphbr@470
    43
morphbr@470
    44
            else:
morphbr@471
    45
                lib.log("Wrong SETUP command from: %s" % client[0])
morphbr@453
    46
morphbr@453
    47
        elif (msg == "PLAY"):
morphbr@453
    48
            media.play()
morphbr@470
    49
            server.Ack("PLAY")
morphbr@453
    50
morphbr@453
    51
        elif (msg == "STOP"):
morphbr@453
    52
            media.stop()
morphbr@470
    53
            server.Ack("STOP")
morphbr@453
    54
morphbr@453
    55
        elif (msg == "CLOSE"):
morphbr@453
    56
            server.finish = 1
morphbr@453
    57
            media.stop()
morphbr@470
    58
            server.Ack("CLOSE")
morphbr@453
    59
            break
morphbr@453
    60
morphbr@470
    61
    lib.log("Closing connection with %s" % client[0])
morphbr@453
    62
    server.disconnect_client(con)
morphbr@453
    63
morphbr@453
    64
server.stop()
morphbr@466
    65
del(server)
morphbr@470
    66
lib.log("Server stopped. Closing...")
morphbr@470
    67