def _bucketize(self, index, queries, field, size, office): db = DBQuery(index=index, office=office, host=dbhost) try: buckets = db.bucketize(queries, [field], size) except Exception as e: return str(e) # reformat buckets to have str keys buckets1 = {} if field in buckets: for k in buckets[field]: buckets1[str(k)] = buckets[field][k] return buckets1
("networks.HwAddress", network1['HwAddress'])) return (rtspuri, camids) return (None, []) for simh in sim_hosts: if simh[1] == "0": continue port_scan.append("-p " + simh[1] + " " + simh[0]) scanner = Scanner() while True: options = port_scan if dbp and not sim_hosts: r = dbp.bucketize("ip_text:* or port:*", ["ip_text", "port"], size=1000) if r: options.extend([k for k in r["ip_text"] if r["ip_text"][k]]) options.extend(["-p " + str(k) for k in r["port"] if r["port"][k]]) for ip, port in scanner.scan(" ".join(options)): # new or disconnected camera print("Probing " + ip + ":" + str(port), flush=True) try: rtspuri, camids = probe_camera_info(ip, port) if rtspuri is None: continue except: print(traceback.format_exc(), flush=True) continue # check database to see if this camera is already registered
except Exception as e: return None while True: streams = {} options = [] try: streams = {item["name"]: item for item in srsapi.list_stream()} except: print(traceback.format_exc(), flush=True) continue if dbp: try: r = dbp.bucketize("rtmpuri:* or rtmpid:*", ["rtmpuri", "rtmpid"], size=1000) if r: options = [{ "rtmpid": item.split("/")[-1], "rtmpuri": item } for item in list(r["rtmpuri"].keys())] except: print(traceback.format_exc(), flush=True) continue for item in options: rtmpid = item["rtmpid"] rtmpuri = item["rtmpuri"] sinfo = streams[rtmpid] if rtmpid in streams else None register(rtmpid, rtmpuri, sinfo) if sinfo: del streams[rtmpid]