diff -r 2b4e9d183146 -r e51af4d0caf5 gmyth-stream/server/0.3/lib/request_handler.py --- a/gmyth-stream/server/0.3/lib/request_handler.py Fri Aug 03 21:43:42 2007 +0100 +++ b/gmyth-stream/server/0.3/lib/request_handler.py Mon Aug 13 22:54:55 2007 +0100 @@ -13,6 +13,7 @@ import threading import SocketServer import BaseHTTPServer +import mimetypes import lib.utils as utils import lib.file_handler as files @@ -64,6 +65,7 @@ "/get_log.do": self.serve_get_log, "/get_all_log.do": self.serve_get_all_log, "/stream.do": self.serve_stream, + "/transcode.do": self.serve_transcode, "/list.do": self.serve_list, "/get_file_info.do": self.serve_file_info, } @@ -353,6 +355,46 @@ # serve_file_info() def serve_stream(self, body): + filename = self.query.get("uri", None)[0] + + if not os.path.exists (filename): + self.send_error(404, "File not found") + return + + size = int(os.path.getsize(filename)) + self.send_response(200) + self.send_header("Content-Type", mimetypes.guess_type(filename)[0]) + self.send_header("Cache-Control","no-cache") + self.send_header("Content-Length", size) + #self.send_header("Connection", "close") + self.end_headers() + + media = open(filename) + data_in = " " + total_read = 0 + + test_tid = int(self.query.get("tid", "0")[0]) + if test_tid == 0 or test_tid not in self.tid_queue: + test_tid = self._get_new_id(self.server.last_tid) + + self.transcoders_log.insert(test_tid, "gms.Stream: %s" % filename) + + try: + while data_in != "": + data_in = media.read(4096) + total_read += 4096 + self.wfile.write(data_in) + status = utils.progress_bar(total_read, size, 50) + msg_status = "Status:%s:%s%%" % (test_tid, status) + self.transcoders_log._update_status(test_tid, msg_status) + self.transcoders_log._update_status(test_tid, "OK: Done") + + except Exception, e: + self.log.error("Stream error: %s" %e) + self.transcoders_log._update_status(test_tid, "Error: %s" % e) + # serve_stream() + + def serve_transcode(self, body): transcoder = self._get_transcoder() try: obj = transcoder(self.query) @@ -362,7 +404,7 @@ self.send_response(200) self.send_header("Content-Type", obj.get_mimetype()) - self.send_header("Cache-Control","no-cache") + self.send_header("Cache-Control","no-cache") if (obj.name == "gmencoder"): self.send_header("Transfer-Encoding", "chunked") @@ -371,12 +413,10 @@ self.end_headers() if body: - test_tid = int(self.query.get("tid", "0")[0]) if test_tid == 0 or test_tid not in self.tid_queue: test_tid = self._get_new_id(self.server.last_tid) - if self.query.get("transcoder", None): self.transcoders_log.insert(test_tid, "gms.%s" % obj.name) obj.tid = test_tid @@ -387,33 +427,6 @@ self.server.del_transcoders(self, obj) files.TranscodedFile("", self.query) - elif self.query.get("type", "")[0] == "file" and \ - self.query.get("uri", None): - - filename = self.query.get("uri", None)[0] - self.transcoders_log.insert(test_tid, "gms.%s" % filename) - - try: - media = open(filename) - data_in = " " - total_read = 0 - size = int(os.path.getsize(filename)) - - while data_in != "": - data_in = media.read(4096) - total_read += 4096 - self.wfile.write(data_in) - status = utils.progress_bar(total_read, size, 50) - msg_status = "Status:%s:%s%%" % (test_tid, status) - self.transcoders_log._update_status(test_tid, - msg_status) - - self.transcoders_log._update_status(test_tid, "OK: Done") - - except Exception, e: - self.log.error("Stream error: %s" %e) - self.transcoders_log._update_status(test_tid, - "Error: %s" % e) # serve_stream()