def set_recording_dir(self,ip='127.0.0.1',hosttype='x86'): set_thread = threading.Timer(600, self.set_recording_dir) set_thread.start() try: _rcmd = RecordingCommand() _rcmd.send_command('RecordCmd=SetFileProperty&FileFormat=mp4&TotalFilePath=D:/RecordFile', ip) except Exception as error: print str(error)
def set_recording_dir(self,ip='127.0.0.1',hosttype='x86'): set_thread = threading.Timer(600, self.set_recording_dir) set_thread.start() try: _rcmd = RecordingCommand() _rcmd.send_command('RecordCmd=SetFileProperty&FileFormat=mp4&TotalFilePath=D:/RecordFile') except Exception as error: print str(error)
def restart_rtmp_living(self,ip='127.0.0.1',hosttype = 'x86'): reload_thread = threading.Timer(3*3600, self.restart_rtmp_living)#3小时重新发起直播 reload_thread.start() try: _rcmd = RecordingCommand() #info = _rcmd.send_command('RecordCmd=QueryRAllInfo') #if 'LivingStart' in info['info']: _rcmd.send_command('BroadCastCmd=StopBroadCast', ip) time.sleep(3) _rcmd.send_command('BroadCastCmd=StartBroadCast', ip) except Exception as error: print str(error)
def start(): app = make_app() app.listen(10006) log('recording srv starting, using port 10006', project='recording', level=3) global _rcmd _rcmd = RecordingCommand() global _utils _utils = zkutils() start_card_server() stype = 'recording' reglist = gather_sds('recording', '../common/tokens.json') #处理本机 service_url = r'http://<ip>:10006/recording/0/recording' local_service_desc = {} local_service_desc['type'] = stype local_service_desc['id'] = 'recording' local_service_desc['url'] = service_url _utils = zkutils() mac = _utils.mymac() local_service_desc['mac'] = mac local_service_desc['ip'] = '127.0.0.1' reglist.append(local_service_desc) log('mac:%s, ip:%s' % (mac, _utils.myip()), project='recording', level=3) global _class_schedule _class_schedule = Schedule(None) for reg in reglist: _class_schedule.analyse_json(reg['ip'], reg['mac']) _class_schedule.restart_rtmp_living() _class_schedule.set_recording_dir() del_dir_schedule() global rh rh = RegHt(reglist) global _ioloop _ioloop = IOLoop.instance() log('running ...', project='recording', level=3) _ioloop.start() log('terminated!!!!!', project='recording', level=3)
def restart_rtmp_living(self,ip='127.0.0.1',hosttype = 'x86'): reload_thread = threading.Timer(3*3600, self.restart_rtmp_living)#3小时重新发起直播 reload_thread.start() try: _rcmd = RecordingCommand() #info = _rcmd.send_command('RecordCmd=QueryRAllInfo') #if 'LivingStart' in info['info']: _rcmd.send_command('BroadCastCmd=StopBroadCast') time.sleep(3) _rcmd.send_command('BroadCastCmd=StartBroadCast') except Exception as error: print str(error)
def StopLiving(): log("StopLiving called", project="recording", level=3) _rcmd = RecordingCommand() rc = _rcmd.send_command("BroadCastCmd=StopBroadCast", ip) return rc
def _rtmp_living(ip, mac, hosttype): rc = {} rc["result"] = "ok" rc["info"] = "" log("_rtmp_living: starting ...., ip=%s, mac=%s, hosttype=%s" % (ip, mac, hosttype), project="recording") if hosttype == "x86": if not CardLive_Runing(): log("_rtmp_living: cardlive.exe NOT prepared?", project="recording", level=2) rc["result"] = "error" rc["info"] = "cardlive.exe is not exit!" return rc try: log("_rtmp_living: try to get relay url", project="recording") middle_req = urllib2.urlopen(_load_base_url() + "getServerUrl?type=middle", timeout=2) middle_url = middle_req.read() except Exception as e: log("_rtmp_living: to get relay url fault! reason=%s" % e, project="recording", level=1) rc["result"] = "error" rc["info"] = str(e) return rc log("_rtmp_living: en, got relay url: %s" % middle_url, project="recording") try: log("_rtmp_living: to call relay of prepublishbatch", project="recording") req = urllib2.Request(middle_url + "/repeater/prepublishbatch") if hosttype == "x86": data = _x86_rtmp_living_data(mac) else: data = _arm_rtmp_living_data(ip, mac, hosttype) data = json.dumps(data) response = urllib2.urlopen(req, data) content = json.load(response) log("_rtmp_living: response_code=%s" % str(content["response_code"]), project="recording") if content["response_code"] != 0: rc = _error_code(content["response_code"], content) log("_rtmp_living: err: info=%s" % rc["info"], project="recording", level=1) return rc urls = [] urls = content["content"] movie_url = rtmp_ip = port = app = "" infos = [] for url in urls: info = {} info["uid"] = str(url["uid"]) info["rtmp_repeater"] = str(url["rtmp_repeater"]) if "teacher" in url["uid"]: info["card_info"] = "card0" if "teacher_full" in url["uid"]: info["card_info"] = "card1" if "student" in url["uid"]: info["card_info"] = "card2" if "student_full" in url["uid"]: info["card_info"] = "card3" if "vga" in url["uid"]: info["card_info"] = "card4" if "blackboard_writing" in url["uid"]: info["card_info"] = "card5" if "movie" in url["uid"]: info["card_info"] = "card6" str(info) infos.append(info) if "teacher" in url["rtmp_repeater"]: # movie_url = url['rtmp_repeater'] # livingS(movie_url) url = url["rtmp_repeater"] url = url[7:] rtmp_ip = url.split(":")[0] url = url[len(rtmp_ip) + 1 :] port = url.split("/")[0] url = url[len(port) + 1 :] app = url.split("/")[0] _rcmd = RecordingCommand() if hosttype == "x86": ReslivingS(rtmp_ip, port, app) else: arm_arg = "BroadCastCmd=RtmpUrlS&" for info in infos: arm_arg = arm_arg + info["rtmp_repeater"] + "^" arm_arg = arm_arg[:-1] log_info(arm_arg) rc = _rcmd.send_command(arm_arg, ip) print rc time.sleep(1) rc = _rcmd.send_command("BroadCastCmd=StartBroadCast", ip) if rc["result"] == "ok": rc["info"] = infos except Exception as err: rc["result"] = "error" rc["info"] = str(err) log("_rtmp_living: exception info=%s" % rc["info"], project="recording", level=1) return rc
def _stop_record(self, info): ''' 停止录像任务 ''' _rcmd = RecordingCommand() _rcmd.send_command('RecordCmd=StopRecord', info['_ip'])
def _record_task(self,info): ''' 开始录像任务 ''' print 'start record_task' _rcmd = RecordingCommand() _rcmd.send_command('RecordCmd=StopRecord', info['_ip']) time.sleep(0.2) if info['_record_mode'].lower() == 'all': _rcmd.send_command('RecordCmd=SetRecordMode&RecordMode=All', info['_ip']) elif info['_record_mode'].lower() == 'resource': _rcmd.send_command('RecordCmd=SetRecordMode&RecordMode=Resource', info['_ip']) elif info['_record_mode'].lower() == 'movie': _rcmd.send_command('RecordCmd=SetRecordMode&RecordMode=Movie', info['_ip']) time.sleep(0.2) _directory_name = 'RecordCmd=SetFileFolder&SubFileFolder=' + info['_directory_name'] _rcmd.send_command(_directory_name, info['_ip']) time.sleep(0.2) _course_info = 'RecordCmd=SetCourseInfo&Department=%s&Subject=%s&CourseName=%s&\ Teacher=%s&Address=%s&DateTime=%s&Description=%s&Grade=%s'\ %(info['_department'], info['_subject'],info['_course_name'], info['_teacher'],info['_address'],info['_datetime'],info['_description'],info['_grade']) _rcmd.send_command(_course_info, info['_ip']) time.sleep(0.2) _rcmd.send_command('RecordCmd=StartRecord', info['_ip'])
def _record_task(self, info): ''' 开始录像任务 ''' print 'start record_task' _rcmd = RecordingCommand() _rcmd.send_command('RecordCmd=StopRecord', info['_ip']) time.sleep(0.2) if info['_record_mode'].lower() == 'all': _rcmd.send_command('RecordCmd=SetRecordMode&RecordMode=All', info['_ip']) elif info['_record_mode'].lower() == 'resource': _rcmd.send_command('RecordCmd=SetRecordMode&RecordMode=Resource', info['_ip']) elif info['_record_mode'].lower() == 'movie': _rcmd.send_command('RecordCmd=SetRecordMode&RecordMode=Movie', info['_ip']) time.sleep(0.2) _directory_name = 'RecordCmd=SetFileFolder&SubFileFolder=' + info[ '_directory_name'] _rcmd.send_command(_directory_name, info['_ip']) time.sleep(0.2) _course_info = 'RecordCmd=SetCourseInfo&Department=%s&Subject=%s&CourseName=%s&\ Teacher=%s&Address=%s&DateTime=%s&Description=%s&Grade=%s'\ %(info['_department'], info['_subject'],info['_course_name'], info['_teacher'],info['_address'],info['_datetime'],info['_description'],info['_grade']) _rcmd.send_command(_course_info, info['_ip']) time.sleep(0.2) _rcmd.send_command('RecordCmd=StartRecord', info['_ip'])
def StopLiving(): log('StopLiving called', project = 'recording', level = 3) _rcmd = RecordingCommand() rc=_rcmd.send_command('BroadCastCmd=StopBroadCast',ip) return rc
def _rtmp_living(ip, mac, hosttype): rc = {} rc['result'] = 'ok' rc['info'] = '' log('_rtmp_living: starting ...., ip=%s, mac=%s, hosttype=%s' % (ip, mac, hosttype), \ project = 'recording') if hosttype == 'x86': if not CardLive_Runing(): log('_rtmp_living: cardlive.exe NOT prepared?', project='recording', level = 2) rc['result'] = 'error' rc['info'] = 'cardlive.exe is not exit!' return rc try: log('_rtmp_living: try to get relay url', project = 'recording') middle_req = urllib2.urlopen(_load_base_url() + 'getServerUrl?type=middle', timeout = 2) middle_url = middle_req.read() except Exception as e: log('_rtmp_living: to get relay url fault! reason=%s' % e, project = 'recording', level = 1) rc['result'] = 'error' rc['info'] = str(e) return rc log('_rtmp_living: en, got relay url: %s' % middle_url, project = 'recording') try: log('_rtmp_living: to call relay of prepublishbatch', project = 'recording') req = urllib2.Request(middle_url+'/repeater/prepublishbatch') if hosttype == 'x86': data = _x86_rtmp_living_data(mac) else: data = _arm_rtmp_living_data(ip, mac, hosttype) data = json.dumps(data) response = urllib2.urlopen(req, data) content = json.load(response) log('_rtmp_living: response_code=%s' % str(content['response_code']), project = 'recording') if content['response_code'] != 0: rc = _error_code(content['response_code'],content) log('_rtmp_living: err: info=%s' % rc['info'], project = 'recording', level = 1) return rc urls = [] urls = content['content'] movie_url = rtmp_ip = port = app = '' infos = [] for url in urls: info = {} info['uid'] = str(url['uid']) info['rtmp_repeater'] = str(url['rtmp_repeater']) if 'teacher' in url['uid']: info['card_info'] = 'card0' if 'teacher_full' in url['uid']: info['card_info'] = 'card1' if 'student' in url['uid']: info['card_info'] = 'card2' if 'student_full' in url['uid']: info['card_info'] = 'card3' if 'vga' in url['uid']: info['card_info'] = 'card4' if 'blackboard_writing' in url['uid']: info['card_info'] = 'card5' if 'movie' in url['uid']: info['card_info'] = 'card6' str(info) infos.append(info) if 'teacher' in url['rtmp_repeater']: #movie_url = url['rtmp_repeater'] #livingS(movie_url) url = url['rtmp_repeater'] url = url[7:] rtmp_ip = url.split(':')[0] url = url[len(rtmp_ip)+1:] port = url.split('/')[0] url =url[len(port)+1:] app = url.split('/')[0] _rcmd = RecordingCommand() if hosttype == 'x86': ReslivingS(rtmp_ip,port,app) else: arm_arg = 'BroadCastCmd=RtmpUrlS&' for info in infos: arm_arg = arm_arg + info['rtmp_repeater'] +'^' arm_arg = arm_arg[:-1] log_info(arm_arg) rc = _rcmd.send_command(arm_arg,ip) print rc time.sleep(1) rc=_rcmd.send_command('BroadCastCmd=StartBroadCast',ip) if rc['result'] == 'ok': rc['info'] = infos except Exception as err: rc['result'] = 'error' rc['info'] = str(err) log('_rtmp_living: exception info=%s' % rc['info'], \ project = 'recording', level = 1) return rc