def timer_check_recording(): global Debug_Mode if Debug_Mode: print("Timer Event: timer_check_recording") global Enabled_Recording global Enabled_Streaming global Pause_Time global Recording_Start global Recording_Timer global Recording_End global Time_To_Record Recording_Active = False if Enabled_Recording and Recording_Start is not "None": if int(Recording_Start[:2]) <= int(Recording_End[:2]): if Debug_Mode: print("Normal Time") print("timer_check_recording(): [{}] vs [{}]".format( str(datetime.today().strftime("%a")), Avoid_These_Days)) Recording_Active = time.strftime( "%H:%M") >= Recording_Start and time.strftime( "%H:%M") <= Recording_End and str(datetime.today( ).strftime("%a")) not in Avoid_These_Days else: if Debug_Mode: print("Backwards Time") Recording_Active = not (time.strftime("%H:%M") <= Recording_Start and time.strftime("%H:%M") >= Recording_End) if Recording_Active: if obs.obs_frontend_recording_active(): if time.time() >= Time_To_Record and str( datetime.today().strftime("%a")) in Avoid_These_Days: if Debug_Mode: print("I'm going to stop recording now") obs.obs_frontend_recording_stop() obs.timer_add(timer_start_recording, Pause_Time) Time_To_Record = time.time() + Recording_Timer else: obs.obs_frontend_recording_start() if obs.obs_frontend_streaming_active( ) is False and Enabled_Streaming is True: obs.obs_frontend_streaming_start() else: if obs.obs_frontend_recording_active(): obs.obs_frontend_recording_stop() else: if Debug_Mode: print("Sleeping Waiting for timer ", Recording_Start) if obs.obs_frontend_streaming_active( ) and Enabled_Streaming is True: obs.obs_frontend_streaming_stop()
def timer_check_recording(): # print("Timer Event: timer_check_recording") global enabled_flag if get_pid("gzclient"): # print("Find gzclient") if not obs.obs_frontend_recording_active(): obs.obs_frontend_recording_start() # print("Recording is started.") elif obs.obs_frontend_recording_active(): obs.obs_frontend_recording_stop()
def timer_start_recording(): global Debug_Mode if Debug_Mode: print("Timer Event: timer_start_recording") if obs.obs_frontend_recording_active() is False: obs.obs_frontend_recording_start() obs.timer_remove(timer_start_recording)
def update_status(): """ Updates the STATUS global with the current status (recording/streaming) and publishes it (JSON-encoded) to the configured MQTT_HOST/MQTT_PORT/MQTT_CHANNEL. Meant to be called at the configured INTERVAL. """ global PREV_STATUS global STATUS STATUS["recording"] = obs.obs_frontend_recording_active() STATUS["streaming"] = obs.obs_frontend_streaming_active() STATUS["paused"] = obs.obs_frontend_recording_paused() STATUS["replay_buffer"] = obs.obs_frontend_replay_buffer_active() STATUS["fps"] = obs.obs_get_active_fps() STATUS["frame_time_ns"] = obs.obs_get_average_frame_time_ns() # Commented this out because it doesn't seem useful (real-time): #STATUS["frame_interval_ns"] = obs.obs_get_frame_interval_ns() STATUS["frames"] = obs.obs_get_total_frames() STATUS["lagged_frames"] = obs.obs_get_lagged_frames() #print("update_status() STATUS: %s" % STATUS) # Uncomment for debug if PREV_STATUS["streaming"] and not STATUS["streaming"]: # Publish a one-time final message indicating streaming is stopped CLIENT.publish(MQTT_CHANNEL, json.dumps(STATUS)) elif PREV_STATUS["recording"] and not STATUS["recording"]: # Publish a one-time final message indicating recording is stopped CLIENT.publish(MQTT_CHANNEL, json.dumps(STATUS)) # Only start publishing regular messages if we're streaming or recording if STATUS["recording"] or STATUS["streaming"]: CLIENT.publish(MQTT_CHANNEL, json.dumps(STATUS)) PREV_STATUS = STATUS.copy()
def check_stream_state(): global curRec global curStream global enable_rec global enable_stream changed = False stream_active = obs.obs_frontend_streaming_active() rec_active = obs.obs_frontend_recording_active() if enable_rec and (rec_active != curRec): changed = True if enable_stream and (stream_active != curStream): changed = True if changed: light_on = False if enable_rec and rec_active: light_on = True if enable_stream and stream_active: light_on = True if light_on: load_start_url() else: load_stop_url() curStream = stream_active curRec = rec_active
def script_load(settings): global curRec global curStream obs.script_log(obs.LOG_DEBUG, "Loading script") curStream = obs.obs_frontend_streaming_active() curRec = obs.obs_frontend_recording_active() obs.timer_add(check_stream_state, 1000)
def timer_start_recording(): global Debug_Mode if Debug_Mode: print("Entrando en timer_start_recording") # obs_frontend_recording_active: TRUE si la grabación está activa, False en caso contrario. if obs.obs_frontend_recording_active() is False: obs.obs_frontend_recording_start() # Inicia la grabación. obs.timer_remove(timer_start_recording)
def start_recording(): global is_stopped if is_stopped: if not obs.obs_frontend_recording_active(): obs.obs_frontend_recording_start() print("Start recording...") else: obs.timer_remove(start_recording)
def stop_recording(): global is_stopped if obs.obs_frontend_recording_active(): obs.obs_frontend_recording_stop() print("Stop recording...") is_stopped = False else: obs.timer_remove(stop_recording) is_stopped = True
def timer_check_recording(): # print("Timer Event: timer_check_recording") global cmd try: if not obs.obs_frontend_recording_active( ) and cmd.state == "start recording": # print("Find gzclient") obs.obs_frontend_recording_start() # print("Recording is started.") elif obs.obs_frontend_recording_active( ) and cmd.state == "stop recording": obs.obs_frontend_recording_stop() cmd.state = "idle..." elif cmd.state == "disable": # obs.obs_frontend_recording_stop() obs.timer_remove(timer_check_recording) # print("Not find gzclient") # print("Recording is stopped.") except: pass
def obs_event(event): if event == obs.OBS_FRONTEND_EVENT_EXIT: rpc.clear() rpc.close() return key = None message = "Idling" scene = obs.obs_frontend_get_current_scene() if obs.obs_frontend_streaming_active(): key = 'play_button' message = "Streaming" if obs.obs_frontend_recording_active(): key = 'record' message = "Recording" if obs.obs_frontend_recording_active( ) and obs.obs_frontend_streaming_active(): message = "Streaming and Recording" rpc.update(state=message, start=None if message == "Idling" else datetime.datetime.now().timestamp(), small_image=key, large_image='obs_studio')
def on_event(event): if event == obs.OBS_FRONTEND_EVENT_SCENE_CHANGED: if get_current_scene_name() == closing_scene: if manage_recording and obs.obs_frontend_recording_active(): if stop_recording_delay == 0: stop_recording() else: obs.timer_add(stop_recording, stop_recording_delay * 1000) if manage_streaming and obs.obs_frontend_streaming_active(): if stop_streaming_delay == 0: stop_streaming() else: obs.timer_add(stop_streaming, stop_streaming_delay * 1000) else: if manage_recording and obs.obs_frontend_recording_active(): obs.timer_remove(stop_recording) if manage_streaming and obs.obs_frontend_streaming_active(): obs.timer_remove(stop_streaming) elif not (obs.obs_frontend_streaming_active() or obs.obs_frontend_recording_active()) and ( event == obs.OBS_FRONTEND_EVENT_STREAMING_STARTING or event == obs.OBS_FRONTEND_EVENT_RECORDING_STARTING ) and get_current_scene_name() != start_scene: scenes = obs.obs_frontend_get_scenes() if scenes != None: for scene_source in scenes: print(str(obs.obs_source_get_type(scene_source))) scene_name = obs.obs_source_get_name(scene_source) if scene_name == start_scene: print(scene_name) obs.obs_frontend_set_current_scene(scene_source) break obs.source_list_release(scenes) elif (event == obs.OBS_FRONTEND_EVENT_STREAMING_STOPPING and not obs.obs_frontend_recording_active()) or ( event == obs.OBS_FRONTEND_EVENT_RECORDING_STOPPING and not obs.obs_frontend_streaming_active()): obs.obs_frontend_remove_event_callback(on_event)
def update_countdown(): text = "" t = diff_time().total_seconds() if t < 0: text = countdown_final_text obs.timer_remove(update_countdown) elif not (obs.obs_frontend_streaming_active() or obs.obs_frontend_recording_active()): text = "" obs.timer_remove(update_countdown) else: text = time(minute=math.floor(t / 60), second=int(t % 60)).strftime("%M:%S") set_text_source(text)
def on_event(event): if (event == obs.OBS_FRONTEND_EVENT_STREAMING_STARTED or event == obs.OBS_FRONTEND_EVENT_RECORDING_STARTED) and get_current_scene_name() == slide_scene and not active: activate_timer() elif event == obs.OBS_FRONTEND_EVENT_SCENE_CHANGED: if get_current_scene_name() == slide_scene: if obs.obs_frontend_streaming_active() or obs.obs_frontend_recording_active(): if not active: activate_timer() else: set_filter_value(screen_sourcename, "Color Correction", "opacity", 100) set_filter_value(camera_sourcename, "Blur", "Filter.Blur.Size", 0) elif active: deactivate_timer() elif (event == obs.OBS_FRONTEND_EVENT_STREAMING_STOPPED or event == obs.OBS_FRONTEND_EVENT_RECORDING_STOPPED) and not (obs.obs_frontend_streaming_active() or obs.obs_frontend_recording_active()) and active: deactivate_timer()
def check_start(): t = diff_time().total_seconds() if t > preshow_duration and not (obs.obs_frontend_streaming_active() or obs.obs_frontend_recording_active()): set_text_source("Waiting" + ("".join(["." for i in range(((int(t) % 4) - 3) * -1)]))) elif t <= preshow_duration: obs.obs_frontend_add_event_callback(on_event) if manage_streaming: obs.obs_frontend_streaming_start() if manage_recording: obs.obs_frontend_recording_start() obs.timer_add(update_countdown, 1000) obs.timer_remove(check_start)
def busy_thread(): obs.obs_frontend_recording_stop() last_demo_processed = "" while run: if al and last_demo_processed != "": try: subprocess.check_output("pidof hl2_linux", shell=True) except subprocess.CalledProcessError: print("Attempting to auto restart TF2") obs.obs_frontend_recording_stop() subprocess.call("steam -applaunch 440 +playdemo "+df+"/"+last_demo_processed, shell=True) time.sleep(6) if not os.path.exists(wf): print("--ERROR: Watch folder doesn't exist!") elif not os.path.exists(rf): print("--ERROR: Record folder doesn't exist!") else: res = [fn for fn in os.listdir(wf) if fn.startswith("recstart.")] if(len(res) > 0): print("RECSTART Detected") os.remove(wf+"/"+res[0]) last_demo_processed = "_".join(res[0].split(".")[1].split("_")[:2]) obs.obs_frontend_recording_start() res = [fn for fn in os.listdir(wf) if fn.startswith("recstop.")] if len(res) > 0: print("RECSTOP DETECTED") os.remove(wf+"/"+res[0]) if obs.obs_frontend_recording_active(): obs.obs_frontend_recording_stop() newest = max(glob.glob(rf+"/*"), key=os.path.getctime) newsplit = newest.split("/") n = res[0].split(".")[1] filename = "/".join(newsplit[:-1]) + "/" + n + "." + newsplit[-1].split(".")[1] last_demo_processed = "_".join(n.split("_")[:2]) os.rename(newest, filename) print("Recorded "+filename) if(cb): if not os.path.exists(df): print("--ERROR: Demo folder doesn't exist!") elif not os.path.exists(af): print("--ERROR: Archive folder doesn't exist!") else: move_file("_".join(res[0].split(".")[1].split("_")[:2])) time.sleep(.1)
def script_update(settings): global weekday weekday = obs.obs_data_get_int(settings, "weekday") global event_start event_start = obs.obs_data_get_int(settings, "event_start") global start_scene start_scene = obs.obs_data_get_string(settings, "start_scene") global manage_streaming manage_streaming = obs.obs_data_get_bool(settings, "manage_streaming") global manage_recording manage_recording = obs.obs_data_get_bool(settings, "manage_recording") global preshow_triggered preshow_triggered = False global preshow_duration preshow_duration = obs.obs_data_get_int(settings, "preshow_duration") global text_source text_source = obs.obs_data_get_string(settings, "text_source") global countdown_final_text countdown_final_text = obs.obs_data_get_string(settings, "countdown_final_text") global stop_streaming_delay stop_streaming_delay = obs.obs_data_get_int(settings, "stop_streaming_delay") global stop_recording_delay stop_recording_delay = obs.obs_data_get_int(settings, "stop_recording_delay") global closing_scene closing_scene = obs.obs_data_get_string(settings, "closing_scene") obs.timer_remove(check_start) obs.timer_remove(update_countdown) set_text_source("") if (manage_streaming or manage_recording ) and start_scene != "" and weekday == datetime.now().weekday( ) and diff_time().total_seconds() > 0 and not ( obs.obs_frontend_streaming_active() or obs.obs_frontend_recording_active()): obs.timer_add(check_start, 1000)
def start(properties, button): # TODO: Add option to enable recursive search, directoryception. replays = glob(replays_dir + '/*.slp') found = len(replays) print('Replays found:', found) if (found): dolphin_process = launch_dolphin() time.sleep(3) # for each replay, load slippi and record video for replay in replays: watch_replay(replay) # Time it takes for a replay to load time.sleep(.8) if (obs.obs_frontend_recording_active()): obs.obs_frontend_recording_stop() obs.obs_frontend_recording_start() time.sleep(math.ceil(get_frames(replay) / 60) + 1) obs.obs_frontend_recording_stop() dolphin_process.terminate()
def stopwatch(): global source_name global timer source = obs.obs_get_source_by_name(source_name) diff = time.time() - start if stop_stream and diff >= stop_stream_time: timer = False if obs.obs_frontend_streaming_active(): obs.obs_frontend_streaming_stop() print('Stopwatch - Stream stopped!') if obs.obs_frontend_recording_active(): obs.obs_frontend_recording_stop() print('Stopwatch - Recording stopped!') obs.timer_remove(stopwatch) obs.remove_current_callback() text = str(timed(int(diff))) try: settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", text) obs.obs_source_update(source, settings) obs.obs_data_release(settings) except UnboundLocalError: pass
def update_text(): global cal_url global interval global source_names global CLIENT_SECRET_FILE global max_events global images_path global image_sources # Gets stored credentials (taken from Calendar API quickstart) credentials = get_credentials() http = credentials.authorize(httplib2.Http()) service = discovery.build('calendar', 'v3', http=http) # Time objects using datetime dt_now = datetime.datetime.utcnow() now = datetime.datetime.utcnow().isoformat( ) + 'Z' # 'Z' indicates UTC time # Gets events currently happending by setting bounds to events happening within a second of current datetime events = service.events().list( calendarId=cal_url, timeMin=now, timeMax=(dt_now + datetime.timedelta(0, 1)).isoformat() + 'Z', maxResults=max_events, singleEvents=True, orderBy='startTime').execute() # Logs the events to console for event in events['items']: print(event['summary']) # Updates the text for each event count = 0 stream_event_happening = False record_event_happening = False for event in events['items']: if (count >= max_events): break text = event['summary'] settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", text) source = obs.obs_get_source_by_name(source_names[count]) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source) settings2 = obs.obs_data_create() obs.obs_data_set_string(settings2, "file", "{}/{}.jpg".format(images_path, text)) source2 = obs.obs_get_source_by_name(image_sources[count]) obs.obs_source_update(source2, settings2) obs.obs_data_release(settings2) obs.obs_source_release(source2) count += 1 # Checks for the "Stream" event and starts streaming if not doing so already if text == "Stream": stream_event_happening = True if ~obs.obs_frontend_streaming_active(): obs.obs_frontend_streaming_start() # Likewise, checks for "Record" event elif text == "Record": record_event_happening = True if ~obs.obs_frontend_recording_active(): obs.obs_frontend_recording_start() # Stops the stream/recording if the Google Calendar event is no longer occuring if obs.obs_frontend_streaming_active() and not (stream_event_happening): obs.obs_frontend_streaming_stop() if obs.obs_frontend_recording_active() and not (record_event_happening): obs.obs_frontend_recording_stop() # Sets any specified sources to blank if here is no event for x in range(count, max_events): text = "" settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", text) source = obs.obs_get_source_by_name(source_names[x]) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source) settings2 = obs.obs_data_create() obs.obs_data_set_string(settings2, "file", text) source2 = obs.obs_get_source_by_name(image_sources[x]) obs.obs_source_update(source2, settings2) obs.obs_data_release(settings2) obs.obs_source_release(source2)
def stop_recording(): if manage_recording and obs.obs_frontend_recording_active( ) and get_current_scene_name() == closing_scene: obs.obs_frontend_recording_stop() obs.timer_remove(stop_recording)
def frame_tick(): global packet_reader global bot_num global elapsed global overtime global ended global kickoff global team global name global total_goals global own_goals global bot_list global goal_time global end_time global start_time global names global cheer global total_blue global total_orange global boost global boost_bar_pos global orange_name_item global blue_boost_item global ended boost_bar_pos = [10, 100] try: packet = packet_reader.get_packet() except: print("Can't read packet") return teams = [0, 1] # Todo: reset score after game if not league_on: league_info = league_status() if league_info is None: print('League has not started yet') return if time.time() >= end_time and auto_record: obs.obs_frontend_recording_stop() end_time = 999999999999999 buffer_delay = time.time() + 20 return if packet.game_info.is_match_ended: boost = [[0, 0], [0, 0]] total_blue = 0 total_orange = 0 do_reset_bar() boost_bar(boost) set_names('Blue-Name', '') set_names('Orange-Name', '') prev_total_goals = 0 if obs.obs_frontend_recording_active() and end_time == 999999999999999 and not ended and auto_record: end_time = time.time() + end_delay ended = True return else: if not obs.obs_frontend_recording_active() and start_time == 999999999999999 and auto_record: #Todo: add start match delay around 3 seconds start_time = time.time() + 3 ended = False if time.time() >= start_time and auto_record: obs.obs_frontend_recording_start() start_time = 999999999999999 ended = False return ended = False for n in range(bot_num): team = packet.game_cars[n].team name = packet.game_cars[n].name.lower() if team == 0: boost[0][0] = packet.game_cars[n].boost / 100 else: boost[0][1] = packet.game_cars[n].boost/100 prev_overtime = overtime prev_ended = ended prev_total_goals = total_goals bot_num = packet.num_cars elapsed = packet.game_info.seconds_elapsed overtime = packet.game_info.is_overtime ended = packet.game_info.is_match_ended kickoff = packet.game_info.is_kickoff_pause for n in range(bot_num): team = packet.game_cars[n].team name = packet.game_cars[n].name goals = packet.teams[team].score own_goals = packet.game_cars[n].score_info.own_goals bot_list[n][0] = team bot_list[n][1] = name bot_list[n][2] = goals bot_list[n][3] = own_goals b_goal = 0 r_goal = 0 for n in range(bot_num): # Todo: streamline goal detection if bot_list[n][0] == 0: b_goal = b_goal + bot_list[n][2] r_goal = r_goal + bot_list[n][3] else: r_goal = r_goal + bot_list[n][2] b_goal = b_goal + bot_list[n][3] total_goals = r_goal + b_goal b_team_str = '' r_team_str = '' for n in range(bot_num): # Todo: streamline name if bot_list[n][0] == 0: if b_team_str != '': b_team_str = b_team_str + ' and ' + bot_list[n][1] else: b_team_str = bot_list[n][1] else: if r_team_str != '': r_team_str = r_team_str + ' and ' + bot_list[n][1] else: r_team_str = bot_list[n][1] if prev_total_goals != total_goals: # Working current_event = 'goal' else: current_event = 'normal' if overtime and not prev_overtime: current_state = 'overtime' else: current_state = 'normal' if ended and not prev_ended: current_state = 'ended' else: current_state = 'normal' boost_bar(boost) set_names('Blue-Name', b_team_str) set_names('Orange-Name', r_team_str) if current_event == "goal": goal_time = time.time() + delay if time.time() >= goal_time: goal_time = 999999999999999 toggle(True) if kickoff: toggle(False) return
def stop(properties, button): if (obs.obs_frontend_recording_active()): obs.obs_frontend_recording_stop() if (dolphin_process != None): dolphin_process.terminate()
def timer_check(): global Debug_Mode if Debug_Mode: print("Entrando en timer_check") global start_time_record global end_time_record # in_process_record = False updated_json = False # leer archivo con configuraciones print("Leyendo JSON") # json_path = "/peztech/static/obs.json" json_path = "D:/Documentos/PythonProjects/pezTech/static/obs.json" with open(json_path, 'r') as file: data = json.load(file) enabled_record = bool(data['enabled_record']) start_time_record = data['start_time'] end_time_record = data['end_time'] if start_time_record: start_time_record = datetime.strptime(start_time_record, "%Y-%m-%d %H:%M:%S") else: enabled_record = False """if start_time_record == "" or start_time_record == end_time_record: enabled_record = False""" if end_time_record: end_time_record = datetime.strptime(end_time_record, "%Y-%m-%d %H:%M:%S") if enabled_record is True: print("Grabacion habilitada, procesando...") print("Hora de comienzo grabacion: " + str(start_time_record)) print("Hora de fin grabacion: " + str(end_time_record)) actual_time = datetime.now(pytz.timezone('America/Santiago')) actual_time = actual_time.strftime("%H:%M:%S") print("actualTime: " + str(actual_time)) start_time_record_format = start_time_record.strftime("%H:%M:%S") actual_time_format = time.strftime(actual_time) # if int(start_time_record[:2]) <= int(end_time_record[:2]): if start_time_record and str(end_time_record) == "": in_process_record = actual_time_format >= start_time_record_format elif start_time_record and end_time_record: end_time_record_format = end_time_record.strftime("%H:%M:%S") # in_process_record = actual_time_format >= start_time_record_format and # actual_time_format <= end_time_record_format in_process_record = start_time_record_format <= actual_time_format <= end_time_record_format else: end_time_record_format = end_time_record.strftime("%H:%M:%S") in_process_record = not (actual_time_format > end_time_record_format) if in_process_record: print("La grabacion esta en proceso") # obs_frontend_recording_active: TRUE si la grabación está activa, False en caso contrario. if obs.obs_frontend_recording_active(): print("En proceso de grabado...") # si la hora actual es mayor a la hora de fin de la grabacion, se finaliza if end_time_record: if Debug_Mode: print("Dejando de grabar ahora") # obs.obs_frontend_recording_stop( ) # detiene la grabacion data['enabled_record'] = "False" data['start_time'] = "" data['end_time'] = "" data['description_record'] = "" updated_json = True else: print("Iniciando la grabacion...") # si la grabacion no esta activa, se inicia obs.obs_frontend_recording_start() # Inicia la grabación. else: print( "La grabacion aun no esta en el tiempo de comienzo o no esta activa" ) # obs_frontend_recording_active: TRUE si la grabación está activa, False en caso contrario. if obs.obs_frontend_recording_active(): print("in_process_record FALSE, FINALIZANDO LA GRABACION") obs.obs_frontend_recording_stop() # Detiene la grabación. data['enabled_record'] = "False" data['start_time'] = "" data['end_time'] = "" data['description_record'] = "" updated_json = True else: print("No existe grabacion habilitada") if updated_json is True: print("Actualizando JSON") with open(json_path, 'w') as file: file.write(json.dumps(data)) obs.timer_remove(timer_check)
def stop_recording(): if obs.obs_frontend_recording_active(): obs.obs_frontend_recording_stop() obs.timer_remove(stop_recording) start_recording()