|
#!/usr/bin/python3 |
|
|
|
import asyncio |
|
import obsws_python as obs |
|
from desktop_notifier import DesktopNotifier, Urgency |
|
|
|
class OBSReplay: |
|
client: obs.ReqClient |
|
notifier: DesktopNotifier |
|
|
|
def __init__(self): |
|
self.client = obs.ReqClient() |
|
self.notifier = DesktopNotifier( |
|
app_name = "obs-replay" |
|
) |
|
|
|
async def notify(self, title: str, content: str, urgency: Urgency = Urgency.Normal): |
|
await self.notifier.send( |
|
title = title, |
|
message = content, |
|
urgency = urgency |
|
) |
|
|
|
async def save_replay(self) -> bool: |
|
if not self.client.get_replay_buffer_status().output_active: |
|
await self.notify("Save Replay Failed", "Replay buffer output is not active.") |
|
return False |
|
|
|
self.client.save_replay_buffer() |
|
return True |
|
|
|
def is_recording(self): |
|
return self.client.get_record_status().output_active |
|
|
|
async def start_record(self) -> bool: |
|
if self.is_recording(): |
|
await self.notify("Start Record Failed", "Record output is already active.") |
|
return False |
|
|
|
self.client.start_record() |
|
return True |
|
|
|
async def stop_record(self) -> bool: |
|
if not self.is_recording(): |
|
await self.notify("Stop Record Failed", "Record output is not active.") |
|
return False |
|
|
|
self.client.stop_record() |
|
return True |
|
|
|
async def main(app: OBSReplay): |
|
if app.is_recording(): # Stop recording |
|
if not await app.stop_record(): |
|
return |
|
|
|
await app.notify("Recording Stopped", "Reinvoke to save replay and start recording.") |
|
else: # Save replay and start recording |
|
if not await app.save_replay(): |
|
return |
|
|
|
if not await app.start_record(): |
|
return |
|
|
|
await app.notify("Replay Saved; Recording", "Replay saved and recording stated. Reinvoke to stop recording.") |
|
|
|
async def main_wrapper(): |
|
app = OBSReplay() |
|
|
|
try: |
|
await main(app) |
|
except Exception as exception: |
|
await app.notify("Failed", exception) |
|
|
|
if __name__ == "__main__": |
|
asyncio.run(main_wrapper()) |
RUFF
RUFF
RUFF
RUFF
RUFF
RUFF
RUFF
RUFF
RUFF