OSDN Git Service

fix mp4 vfr.
[rec10/rec10-git.git] / rec10 / trunk / src / gridserver.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
5 from SocketServer import *
6
7 import configreader
8 import recdb
9 import recdblist
10 RECV_BUF = 8192
11
12 class Handler(BaseRequestHandler):
13     """
14     This is a server to encode ts files in another pc.
15
16     """
17     def handle(self):
18         print("connect from:", self.client_address)
19         cons = getTask()
20         recdblist.printutf8(cons + " is sent")
21         self.request.send(cons.encode('UTF-8'))
22         """while True:
23             #ret = self.request.recv(RECV_BUF)
24             #if len(ret) == 0:
25             #    break
26             self.request.send()
27
28             """
29         self.request.close()
30
31 def getTask():
32     tasks = recdb.getnow("1")
33     rett = ""
34     for task in tasks:
35         if task["type"] == recdblist.REC_ENCODE_QUE:
36             title = task['title']
37             opt = task['opt']
38             btime = task['btime']
39             etime = task['etime']
40             chtxt = task['chtxt']
41             recdb.del_reckey(recdblist.REC_ENCODE_QUE, title, chtxt, btime)
42             recdb.rec_reckey(recdblist.REC_ENCODE_GRID, title, chtxt, btime, etime, opt)
43             rett = "title=" + title + "," + "opt=" + opt + ";"
44             break
45     return rett
46 def main():
47     port = int(configreader.getpath("gridserver_port"))
48     sv = ThreadingTCPServer(('', port), Handler)
49     recdblist.printutf8("This is a Rec10 GridServer.")
50     recdblist.printutf8("Waiting for connections at port" + str(port))
51     recdblist.printutf8('listen to:')
52     print (sv.socket.getsockname())
53     sv.serve_forever()
54
55 if __name__ == '__main__': main()