13 Commits

Author SHA1 Message Date
9152c83063 This should work but it hasn't been tested. Waiting on https://github.com/aatikturk/obsws-python/pull/58 2025-06-26 06:46:32 +01:00
6bdbb470c9 fix docstring 2025-06-26 06:20:21 +01:00
b6c0e9dece update README 2025-06-26 06:16:40 +01:00
d28d5a578a add styler module
upd entry point import
2025-06-26 06:16:12 +01:00
ae86785ba6 separate the cli commands into different modules
this makes it easier to use them as components of both the cli and the gui.
2025-06-26 06:15:48 +01:00
76815926e9 add custom error class. this allows us to fetch the raw message before it's been coloured. 2025-06-26 06:13:32 +01:00
04b4e5521a decouple the gui from the cli 2025-06-26 06:12:57 +01:00
eecd51e0ca add Themes to README 2025-06-25 19:02:31 +01:00
57f2e9deff remove created 2025-06-25 18:50:42 +01:00
ca7c60f0e4 add tag trigger to Release 2025-06-25 18:40:30 +01:00
c1055408fb fixes double colouring bug
patch bump
2025-06-25 18:29:24 +01:00
b22f6f6f95 add created trigger to Release action 2025-06-25 18:18:57 +01:00
d2486be29a add more theme options
patch bump
2025-06-25 18:06:59 +01:00
12 changed files with 297 additions and 171 deletions

View File

@@ -3,6 +3,9 @@ name: Release
on: on:
release: release:
types: [published] types: [published]
push:
tags:
- 'v*.*.*'
jobs: jobs:
pypi-publish: pypi-publish:

View File

@@ -46,42 +46,60 @@ Or load them from your environment:
OBS_HOST=localhost OBS_HOST=localhost
OBS_PORT=4455 OBS_PORT=4455
OBS_PASSWORD=<websocket password> OBS_PASSWORD=<websocket password>
OBS_THEME=Reds
``` ```
## Use ## Use
Without passing a subcommand (start/stop) a GUI will be launched, otherwise a CLI will be launched.
### GUI ### GUI
To launch the GUI run the root command without any subcommands:
```console
simple-recorder
```
![simple-recorder](./img/simple-recorder.png) ![simple-recorder](./img/simple-recorder.png)
Just enter the filename and click *Start Recording*. Just enter the filename and click *Start Recording*.
#### Themes
Passing flags is fine, however, for example to set the theme:
```console
simple-recorder --theme="Light Purple"
```
Available themes: Light Purple, Neutral Blue, Reds, Sandy Beach, Kayak, Light Blue 2, Dark Teal1
### CLI ### CLI
```shell ```shell
Usage: simple-recorder [OPTIONS] COMMAND Usage: simple-recorder [OPTIONS] COMMAND
┏━ Subcommands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ┏━ Subcommands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ start Start recording ┃ ┃ start Start recording ┃
┃ stop Stop recording ┃ ┃ stop Stop recording ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
┏━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ┏━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ --host <HOST> ┃ --host <HOST> OBS WebSocket host
┃ --port <PORT> ┃ --port <PORT> OBS WebSocket port
┃ --password <PASSWORD> ┃ --password <PASSWORD> OBS WebSocket password
┃ --theme <THEME> ┃ --theme <THEME> OBS WebSocket theme
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
``` ```
For example:
```console ```console
simple-recorder start "File Name" simple-recorder start "File Name"
simple-recorder stop simple-recorder stop
``` ```
If no filename is passed to start then you will be prompted for one. A default_name will be used if none is supplied to the prompt. - If no filename is passed to start then you will be prompted for one.
- A default_name will be used if none is supplied to the prompt.
[obs-studio]: https://obsproject.com/ [obs-studio]: https://obsproject.com/

View File

@@ -1,6 +1,6 @@
[project] [project]
name = "simple-recorder" name = "simple-recorder"
version = "0.1.1" version = "0.1.3"
description = "A simple OBS recorder" description = "A simple OBS recorder"
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }] authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]
dependencies = [ dependencies = [

View File

@@ -1,3 +1,3 @@
from .app import run from .cli import run
__all__ = ["run"] __all__ = ["run"]

View File

@@ -1,156 +0,0 @@
import logging
from datetime import datetime
import clypi
import FreeSimpleGUI as fsg
import obsws_python as obsws
from clypi import ClypiConfig, ClypiException, Command, Positional, arg, configure
from typing_extensions import override
logger = logging.getLogger(__name__)
config = ClypiConfig(
nice_errors=(ClypiException,),
)
configure(config)
highlight = clypi.Styler(fg="green")
error = clypi.Styler(fg="red", bold=True)
class Start(Command):
"""Start recording."""
filename: Positional[str] = arg(
default="default_name",
help="Name of the recording",
prompt="Enter the name for the recording",
)
host: str = arg(inherited=True)
port: int = arg(inherited=True)
password: str = arg(inherited=True)
@staticmethod
def get_timestamp():
return datetime.now().strftime("%Y-%m-%d %H-%M-%S")
@override
async def run(self):
if not self.filename:
raise ClypiException(error("Recording name cannot be empty."))
with obsws.ReqClient(
host=self.host, port=self.port, password=self.password
) as client:
resp = client.get_record_status()
if resp.output_active:
raise ClypiException(error("Recording is already active."))
filename = f"{self.filename} {self.get_timestamp()}"
client.set_profile_parameter(
"Output",
"FilenameFormatting",
filename,
)
client.start_record()
print(f"Recording started with filename: {highlight(filename)}")
class Stop(Command):
"""Stop recording."""
host: str = arg(inherited=True)
port: int = arg(inherited=True)
password: str = arg(inherited=True)
@override
async def run(self):
with obsws.ReqClient(
host=self.host, port=self.port, password=self.password
) as client:
resp = client.get_record_status()
if not resp.output_active:
raise ClypiException(error("Recording is not active."))
client.stop_record()
print("Recording stopped successfully.")
def theme_parser(value: str) -> str:
"""Parse the theme argument."""
themes = ["Light Purple", "Neutral Blue", "Reds", "Sandy Beach"]
if value not in themes:
raise ClypiException(
f"Invalid theme: {value}. Available themes: {', '.join(themes)}"
)
return value
class SimpleRecorder(Command):
subcommand: Start | Stop | None = None
host: str = arg(default="localhost", env="OBS_HOST")
port: int = arg(default=4455, env="OBS_PORT")
password: str | None = arg(default=None, env="OBS_PASSWORD")
theme: str = arg(default="Reds", parser=theme_parser, env="OBS_THEME")
@override
async def run(self):
fsg.theme(self.theme)
input_text = fsg.InputText("", key="-FILENAME-")
start_record_button = fsg.Button("Start Recording", key="Start Recording")
stop_record_button = fsg.Button("Stop Recording", key="Stop Recording")
layout = [
[fsg.Text("Enter recording filename:")],
[input_text],
[start_record_button, stop_record_button],
[fsg.Text("Status: Not started", key="-OUTPUT-")],
]
window = fsg.Window("Simple Recorder", layout, finalize=True)
status_text = window["-OUTPUT-"]
input_text.bind("<Return>", "-ENTER-")
start_record_button.bind("<Return>", "-ENTER-")
stop_record_button.bind("<Return>", "-ENTER-")
while True:
event, values = window.read()
logger.debug(f"Event: {event}, Values: {values}")
if event == fsg.WIN_CLOSED:
break
elif event in (
"Start Recording",
"Start Recording-ENTER-",
"-FILENAME--ENTER-",
):
try:
await Start(
filename=input_text.get(),
host=self.host,
port=self.port,
password=self.password,
).run()
status_text.update("Status: Recording started", text_color="green")
except ClypiException as e:
status_text.update(str(e), text_color="red")
logger.error(f"Error starting recording: {e}")
elif event in ("Stop Recording", "Stop Recording-ENTER-"):
try:
await Stop(
host=self.host,
port=self.port,
password=self.password,
).run()
status_text.update("Status: Recording stopped", text_color="green")
except ClypiException as e:
status_text.update(str(e), text_color="red")
logger.error(f"Error stopping recording: {e}")
def run():
"""Run the CLI application."""
SimpleRecorder.parse().start()
if __name__ == "__main__":
run()

View File

@@ -0,0 +1,58 @@
import logging
from clypi import ClypiConfig, ClypiException, Command, arg, configure
from typing_extensions import override
from .errors import SimpleRecorderError
from .gui import SimpleRecorderWindow
from .split import Split
from .start import Start
from .stop import Stop
logger = logging.getLogger(__name__)
config = ClypiConfig(
nice_errors=(SimpleRecorderError,),
)
configure(config)
def theme_parser(value: str) -> str:
"""Parse the theme argument."""
themes = [
"Light Purple",
"Neutral Blue",
"Reds",
"Sandy Beach",
"Kayak",
"Light Blue 2",
"Dark Teal1",
]
if value not in themes:
raise ClypiException(
f"Invalid theme: {value}. Available themes: {', '.join(themes)}"
)
return value
class SimpleRecorder(Command):
subcommand: Start | Stop | Split | None = None
host: str = arg(default="localhost", env="OBS_HOST", help="OBS WebSocket host")
port: int = arg(default=4455, env="OBS_PORT", help="OBS WebSocket port")
password: str | None = arg(
default=None, env="OBS_PASSWORD", help="OBS WebSocket password"
)
theme: str = arg(
default="Reds", parser=theme_parser, env="OBS_THEME", help="OBS WebSocket theme"
)
@override
async def run(self):
"""Run the Simple Recorder GUI."""
window = SimpleRecorderWindow(self.host, self.port, self.password, self.theme)
await window.run()
def run():
"""Run the application."""
SimpleRecorder.parse().start()

View File

@@ -0,0 +1,11 @@
from clypi import ClypiException
from .styler import error
class SimpleRecorderError(ClypiException):
"""Base class for all SimpleRecorder exceptions."""
def __init__(self, message: str):
super().__init__(error(message))
self.raw_message = message

View File

@@ -0,0 +1,89 @@
import logging
import FreeSimpleGUI as fsg
from clypi import ClypiException
from .split import Split
from .start import Start
from .stop import Stop
logger = logging.getLogger(__name__)
class SimpleRecorderWindow(fsg.Window):
def __init__(self, host, port, password, theme):
self.logger = logger.getChild(self.__class__.__name__)
self.host = host
self.port = port
self.password = password
fsg.theme(theme)
layout = [
[fsg.Text("Enter recording filename:")],
[fsg.InputText("", key="-FILENAME-")],
[
fsg.Button("Start Recording"),
fsg.Button("Stop Recording"),
fsg.Button("Split Recording"),
],
[fsg.Text("Status: Not started", key="-OUTPUT-")],
]
super().__init__("Simple Recorder", layout, finalize=True)
self["-FILENAME-"].bind("<Return>", " || RETURN")
self["Start Recording"].bind("<Return>", " || RETURN")
self["Stop Recording"].bind("<Return>", " || RETURN")
self["Split Recording"].bind("<Return>", " || RETURN")
async def run(self):
while True:
event, values = self.read()
if event == fsg.WIN_CLOSED:
break
match event.split(" || "):
case ["Start Recording", "RETURN" | None] | ["-FILENAME-", "RETURN"]:
try:
await Start(
filename=values["-FILENAME-"],
host=self.host,
port=self.port,
password=self.password,
).run()
self["-OUTPUT-"].update(
"Recording started successfully", text_color="green"
)
except ClypiException as e:
self["-OUTPUT-"].update(
f"Error: {e.raw_message}", text_color="red"
)
case ["Stop Recording", "RETURN" | None]:
try:
await Stop(
host=self.host, port=self.port, password=self.password
).run()
self["-OUTPUT-"].update(
"Recording stopped successfully", text_color="green"
)
except ClypiException as e:
self["-OUTPUT-"].update(
f"Error: {e.raw_message}", text_color="red"
)
case ["Split Recording", "RETURN" | None]:
try:
await Split(
host=self.host, port=self.port, password=self.password
).run()
self["-OUTPUT-"].update(
"Recording split successfully", text_color="green"
)
except ClypiException as e:
self["-OUTPUT-"].update(
f"Error: {e.raw_message}", text_color="red"
)
case _:
self.logger.warning(f"Unhandled event: {event}")
self.close()

View File

@@ -0,0 +1,27 @@
import obsws_python as obsws
from clypi import Command, arg
from .errors import SimpleRecorderError
class Split(Command):
"""Split recording."""
host: str = arg(inherited=True)
port: int = arg(inherited=True)
password: str = arg(inherited=True)
async def run(self):
with obsws.ReqClient(
host=self.host, port=self.port, password=self.password
) as client:
resp = client.get_record_status()
if not resp.output_active:
raise SimpleRecorderError("Recording is not active.")
if resp.output_paused:
raise SimpleRecorderError(
"Recording is paused. Please resume before splitting."
)
client.split_record_file()
print("Recording split successfully.")

View File

@@ -0,0 +1,46 @@
from datetime import datetime
import obsws_python as obsws
from clypi import Command, Positional, arg
from typing_extensions import override
from .errors import SimpleRecorderError
from .styler import highlight
class Start(Command):
"""Start recording."""
filename: Positional[str] = arg(
default="default_name",
help="Name of the recording",
prompt="Enter the name for the recording",
)
host: str = arg(inherited=True)
port: int = arg(inherited=True)
password: str = arg(inherited=True)
@staticmethod
def get_timestamp():
return datetime.now().strftime("%Y-%m-%d %H-%M-%S")
@override
async def run(self):
if not self.filename:
raise SimpleRecorderError("Recording name cannot be empty.")
with obsws.ReqClient(
host=self.host, port=self.port, password=self.password
) as client:
resp = client.get_record_status()
if resp.output_active:
raise SimpleRecorderError("Recording is already active.")
filename = f"{self.filename} {self.get_timestamp()}"
client.set_profile_parameter(
"Output",
"FilenameFormatting",
filename,
)
client.start_record()
print(f"Recording started with filename: {highlight(filename)}")

View File

@@ -0,0 +1,26 @@
import obsws_python as obsws
from clypi import Command, arg
from typing_extensions import override
from .errors import SimpleRecorderError
from .styler import highlight
class Stop(Command):
"""Stop recording."""
host: str = arg(inherited=True)
port: int = arg(inherited=True)
password: str = arg(inherited=True)
@override
async def run(self):
with obsws.ReqClient(
host=self.host, port=self.port, password=self.password
) as client:
resp = client.get_record_status()
if not resp.output_active:
raise SimpleRecorderError("Recording is not active.")
client.stop_record()
print(highlight("Recording stopped successfully."))

View File

@@ -0,0 +1,4 @@
import clypi
highlight = clypi.Styler(fg="green")
error = clypi.Styler(fg="red", bold=True)