""" Created by Koen van de Sande for the VideOlympics showcase http://www.videolympics.org Version: April 2009 """ import BaseHTTPServer # # change this number if you want to use an other port than 8001 # PORT = 8001 ## shot maxima for the TRECVID2007 test set (video 111 through 219, including 200) #validShotMaxima = {111: 131, 112: 193, 113: 59, 114: 248, 115: 267, 116: 15, 117: 20, 118: 61, 119: 26, 120: 186, 121: 236, 122: 581, 123: 253, 124: 396, 125: 186, 126: 47, 127: 141, 128: 132, 129: 89, 130: 48, 131: 334, 132: 141, 133: 155, 134: 121, 135: 107, 136: 217, 137: 56, 138: 105, 139: 105, 140: 59, 141: 128, 142: 122, 143: 125, 144: 87, 145: 111, 146: 113, 147: 89, 148: 54, 149: 116, 150: 144, 151: 131, 152: 130, 153: 94, 154: 108, 155: 94, 156: 125, 157: 406, 158: 108, 159: 103, 160: 158, 161: 71, 162: 112, 163: 102, 164: 104, 165: 133, 166: 136, 167: 154, 168: 166, 169: 119, 170: 105, 171: 187, 172: 82, 173: 64, 174: 153, 175: 81, 176: 61, 177: 98, 178: 206, 179: 180, 180: 265, 181: 307, 182: 92, 183: 386, 184: 233, 185: 186, 186: 74, 187: 149, 188: 224, 189: 178, 190: 107, 191: 125, 192: 18, 193: 103, 194: 139, 195: 87, 196: 190, 197: 34, 198: 105, 199: 86, 200: 554, 201: 202, 202: 462, 203: 329, 204: 700, 205: 313, 206: 326, 207: 168, 208: 227, 209: 402, 210: 135, 211: 167, 212: 153, 213: 181, 214: 121, 215: 311, 216: 202, 217: 188, 218: 142, 219: 196} # shot maxima for the TRECVID2008 test set (video 1 through 219 from tv8.sv.test) validShotMaxima = {1: 85, 2: 142, 3: 192, 4: 88, 5: 93, 6: 426, 7: 81, 8: 118, 9: 127, 10: 48, 11: 196, 12: 209, 13: 246, 14: 117, 15: 86, 16: 226, 17: 167, 18: 247, 19: 123, 20: 13, 21: 188, 22: 206, 23: 397, 24: 199, 25: 65, 26: 151, 27: 77, 28: 73, 29: 220, 30: 98, 31: 49, 32: 88, 33: 88, 34: 120, 35: 194, 36: 192, 37: 98, 38: 21, 39: 171, 40: 102, 41: 25, 42: 84, 43: 168, 44: 159, 45: 75, 46: 155, 47: 400, 48: 278, 49: 232, 50: 187, 51: 164, 52: 143, 53: 131, 54: 60, 55: 117, 56: 75, 57: 141, 58: 108, 59: 178, 60: 99, 61: 69, 62: 166, 63: 96, 64: 80, 65: 86, 66: 90, 67: 91, 68: 155, 69: 79, 70: 214, 71: 50, 72: 115, 73: 80, 74: 90, 75: 71, 76: 97, 77: 115, 78: 63, 79: 61, 80: 155, 81: 131, 82: 245, 83: 128, 84: 143, 85: 140, 86: 94, 87: 90, 88: 129, 89: 121, 90: 129, 91: 133, 92: 144, 93: 99, 94: 82, 95: 109, 96: 96, 97: 127, 98: 106, 99: 94, 100: 71, 101: 136, 102: 89, 103: 96, 104: 184, 105: 116, 106: 95, 107: 247, 108: 93, 109: 99, 110: 65, 111: 302, 112: 99, 113: 147, 114: 118, 115: 149, 116: 126, 117: 779, 118: 224, 119: 186, 120: 174, 121: 142, 122: 147, 123: 191, 124: 131, 125: 158, 126: 173, 127: 159, 128: 158, 129: 202, 130: 158, 131: 112, 132: 209, 133: 103, 134: 196, 135: 179, 136: 86, 137: 68, 138: 67, 139: 74, 140: 61, 141: 45, 142: 68, 143: 72, 144: 38, 145: 52, 146: 81, 147: 48, 148: 98, 149: 76, 150: 326, 151: 182, 152: 230, 153: 284, 154: 306, 155: 225, 156: 219, 157: 86, 158: 82, 159: 307, 160: 192, 161: 359, 162: 227, 163: 102, 164: 302, 165: 171, 166: 180, 167: 396, 168: 288, 169: 144, 170: 78, 171: 77, 172: 129, 173: 74, 174: 137, 175: 89, 176: 97, 177: 116, 178: 175, 179: 175, 180: 129, 181: 106, 182: 89, 183: 57, 184: 264, 185: 625, 186: 152, 187: 400, 188: 640, 189: 328, 190: 386, 191: 294, 192: 202, 193: 182, 194: 164, 195: 183, 196: 156, 197: 234, 198: 183, 199: 696, 200: 218, 201: 188, 202: 143, 203: 182, 204: 198, 205: 149, 206: 140, 207: 254, 208: 175, 209: 377, 210: 182, 211: 287, 212: 185, 213: 315, 214: 138, 215: 287, 216: 155, 217: 202, 218: 371, 219: 279,} class Handler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): # get input request = self.path if request.startswith("/"): request = request[1:] # convert to 'clean' shotname temp = request.strip() parts = temp.split("/") team = None shotname = None output = None # parse input for part in parts: if part.startswith("team="): try: team = int(part[5:]) except: output = "ERROR INVALID\n" if part.startswith("shot"): try: # note: this test server does not verify shot names. # the real contest server (of course) will do this temp = part.replace("shot","") shotparts = temp.split("_") vid = int(shotparts[0]) shot = int(shotparts[1]) if vid in validShotMaxima: if shot >= 1 and shot <= validShotMaxima[vid]: shotname = part else: raise Exception("Shot number not in range") else: raise Exception("Unknown video") except: output = "ERROR INVALID\n" shotname = None if team is None or shotname is None: output = "ERROR INVALID\n" # always send a valid HTTP response (200) self.send_response(200) self.send_header("Content-type", "text/plain") self.end_headers() if output is None: # still valid, no error condition self.wfile.write("OK\n") else: # code above has specified an output already self.wfile.write(output) httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler) print "VideOlympics Test Server serving at port", PORT httpd.serve_forever()