def script_tick(seconds): #print(time.time()) global currentSecond global oldSecond global currentMinute global oldMinute global currentHour global oldHour global stopSecondToCheck global startSecondToCheck global minuteToCheck global hourToCheckAm global hourToCheckPm currentSecond = datetime.datetime.utcnow().second currentMinute = datetime.datetime.utcnow().minute currentHour = datetime.datetime.utcnow().hour if oldSecond != currentSecond: #print(currentSecond) # The block below ends the stream at 11:59:30 or 23:59:30 if currentSecond == stopSecondToCheck: #print(datetime.datetime.utcnow().isoformat() + " Second is now " + str(stopSecondToCheck) + ", this is where we should stop the stream (" + str(currentSecond) + ")") if currentMinute == minuteToCheck: #print(datetime.datetime.utcnow().isoformat() + " Minute is now " + str(minuteToCheck) + " (" + str(currentMinute) + ")") if currentHour == hourToCheckAm or currentHour == hourToCheckPm: #print(datetime.datetime.utcnow().isoformat() + " Hour is now " + str(hourToCheckAm) + " or " + str(hourToCheckPm) + " (" + str(currentHour) + ")") if obs.obs_frontend_streaming_active() == True: print(datetime.datetime.utcnow().isoformat() + " OBS is streaming") obs.obs_frontend_streaming_stop() print(datetime.datetime.utcnow().isoformat() + " Stream should have ended now") if obs.obs_frontend_streaming_active() == False: print(datetime.datetime.utcnow().isoformat() + " OBS is NOT streaming, don't do anything") # The block below starts the stream at 11:59:40 or 23:59:40 if currentSecond == startSecondToCheck: #print(datetime.datetime.utcnow().isoformat() + " Second is now " + str(startSecondToCheck) + ", this is where we should start the stream (" + str(currentSecond) + ")") if currentMinute == minuteToCheck: #print(datetime.datetime.utcnow().isoformat() + " Minute is now " + str(minuteToCheck) + " (" + str(currentMinute) + ")") if currentHour == hourToCheckAm or currentHour == hourToCheckPm: #print(datetime.datetime.utcnow().isoformat() + " Hour is now " + str(hourToCheckAm) + " or " + str(hourToCheckPm) + " (" + str(currentHour) + ")") if obs.obs_frontend_streaming_active() == False: print(datetime.datetime.utcnow().isoformat() + " OBS is NOT streaming") obs.obs_frontend_streaming_start() print(datetime.datetime.utcnow().isoformat() + " Stream should have started now") if obs.obs_frontend_streaming_active() == True: print(datetime.datetime.utcnow().isoformat() + " OBS is streaming, don't do anything") oldSecond = currentSecond oldMinute = currentMinute oldHour = currentHour
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 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 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 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 decrease_interval(): global interval global interval_bak if interval > 0: print("current timer: " + str(interval) + " minutes left") interval = interval - 1 else: if obs.obs_frontend_streaming_active(): stopStream() else: startStream() interval = interval_bak
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 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 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 stop_streaming(): if manage_streaming and obs.obs_frontend_streaming_active( ) and get_current_scene_name() == closing_scene: obs.obs_frontend_streaming_stop() obs.timer_remove(stop_streaming)
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)