23 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
3c837f337e upd workflow names 2025-06-25 18:01:52 +01:00
1f49dd961f add release workflow 2025-06-25 17:58:01 +01:00
59de0fdc4e add explicit perms 2025-06-25 17:44:49 +01:00
ac60cf0c06 upd artifact name 2025-06-25 17:40:20 +01:00
479a447e52 add .gitkeep 2025-06-25 17:37:32 +01:00
e8bacd70b6 add shiv to build dependencies 2025-06-25 17:27:11 +01:00
5cff6e268a add build workflow 2025-06-25 17:22:48 +01:00
430aaf5cc5 add a little colour to the output
patch bump
2025-06-25 17:22:32 +01:00
130bf74f27 add note about pyz included in Releases. 2025-06-25 16:56:38 +01:00
b8bcea59fc add link to OBS
add note about env vars
2025-06-25 15:17:45 +01:00
16 changed files with 482 additions and 168 deletions

62
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,62 @@
name: Build PYZ
on:
push:
tags:
- 'v*.*.*'
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
pdm sync -d -G build
- name: Build addon
run: pdm run compile
- name: Upload build artifacts
if: success()
uses: actions/upload-artifact@v4
with:
name: pyz_build
path: ./bin/simple-recorder.pyz
upload_release:
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') }}
needs: build
steps:
- name: Download releases files
uses: actions/download-artifact@v4.1.7
with:
name: pyz_build
- name: Display structure of downloaded files
run: tree
- name: Release
uses: softprops/action-gh-release@v1
with:
files: simple-recorder.pyz
fail_on_unmatched_files: true
prerelease: ${{ contains(github.ref, '-') }}

26
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
name: Release
on:
release:
types: [published]
push:
tags:
- 'v*.*.*'
jobs:
pypi-publish:
name: upload release to PyPI
runs-on: ubuntu-latest
environment: pypi
permissions:
# This permission is needed for private repositories.
contents: read
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/checkout@v4
- uses: pdm-project/setup-pdm@v4
- name: Publish package distributions to PyPI
run: pdm publish

4
.gitignore vendored
View File

@@ -162,4 +162,6 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
bin/
!bin/.gitkeep
bin/*

View File

@@ -12,6 +12,7 @@ Run it as a CLI or a GUI.
## Requirements
- Python 3.11 or greater
- [OBS Studio 28+][obs-studio]
## Installation
@@ -27,38 +28,78 @@ uv tool install simple-recorder
pipx install simple-recorder
```
*with pyz*
An executable pyz has been included in [Release](https://github.com/onyx-and-iris/simple-recorder/releases) which you can run in Windows. Follow the steps in this [Setting up Windows for Zipapps](https://jhermann.github.io/blog/python/deployment/2020/02/29/python_zippapps_on_windows.html#Setting-Up-Windows-10-for-Zipapps) guide.
## Configuration
Pass --host, --port and --password as flags on the root command:
```console
simple-recorder --host=localhost --port=4455 --password=<websocket password> --help
```
Or load them from your environment:
```env
OBS_HOST=localhost
OBS_PORT=4455
OBS_PASSWORD=<websocket password>
OBS_THEME=Reds
```
## Use
Without passing a subcommand (start/stop) a GUI will be launched, otherwise a CLI will be launched.
### GUI
To launch the GUI run the root command without any subcommands:
```console
simple-recorder
```
![simple-recorder](./img/simple-recorder.png)
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
```shell
Usage: simple-recorder [OPTIONS] COMMAND
┏━ Subcommands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┃ start Start recording
┃ stop Stop recording
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┏━ Subcommands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ start Start recording ┃
┃ stop Stop recording ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
┏━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┃ --host <HOST>
┃ --port <PORT>
┃ --password <PASSWORD>
┃ --theme <THEME>
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┏━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ --host <HOST> OBS WebSocket host
┃ --port <PORT> OBS WebSocket port
┃ --password <PASSWORD> OBS WebSocket password
┃ --theme <THEME> OBS WebSocket theme
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
```
For example:
```console
simple-recorder start "File Name"
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/

0
bin/.gitkeep Normal file
View File

69
pdm.lock generated
View File

@@ -2,14 +2,28 @@
# It is not intended for manual editing.
[metadata]
groups = ["default"]
groups = ["default", "build"]
strategy = ["inherit_metadata"]
lock_version = "4.5.0"
content_hash = "sha256:7d4367f16062b5a2d661a207b7b33518aaea59371e239b8cf90a5b5b583e1abc"
content_hash = "sha256:292c5ea319597e3539895c1ac50004c884c5d46edd5f7b195ede79156558feab"
[[metadata.targets]]
requires_python = ">=3.11"
[[package]]
name = "click"
version = "8.2.1"
requires_python = ">=3.10"
summary = "Composable command line interface toolkit"
groups = ["build"]
dependencies = [
"colorama; platform_system == \"Windows\"",
]
files = [
{file = "click-8.2.1-py3-none-any.whl", hash = "sha256:61a3265b914e850b85317d0b3109c7f8cd35a670f963866005d6ef1d5175a12b"},
{file = "click-8.2.1.tar.gz", hash = "sha256:27c491cc05d968d271d5a1db13e3b5a184636d9d930f148c50b038f0d0646202"},
]
[[package]]
name = "clypi"
version = "1.8.1"
@@ -25,6 +39,18 @@ files = [
{file = "clypi-1.8.1.tar.gz", hash = "sha256:9efa0a5a0e3668dd390e0d90321587dcb8eea12e28facd2ac437383f0de3dc76"},
]
[[package]]
name = "colorama"
version = "0.4.6"
requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
summary = "Cross-platform colored terminal text."
groups = ["build"]
marker = "platform_system == \"Windows\""
files = [
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
]
[[package]]
name = "freesimplegui"
version = "5.2.0.post1"
@@ -50,6 +76,17 @@ files = [
{file = "obsws_python-1.7.2.tar.gz", hash = "sha256:b5cdaad30fbe1f6d4787b6530048b9882f070c3ee7830abb6dad4a47f84d7fa0"},
]
[[package]]
name = "pip"
version = "25.1.1"
requires_python = ">=3.9"
summary = "The PyPA recommended tool for installing Python packages."
groups = ["build"]
files = [
{file = "pip-25.1.1-py3-none-any.whl", hash = "sha256:2913a38a2abf4ea6b64ab507bd9e967f3b53dc1ede74b01b0931e1ce548751af"},
{file = "pip-25.1.1.tar.gz", hash = "sha256:3de45d411d308d5054c2168185d8da7f9a2cd753dbac8acbfa88a8909ecd9077"},
]
[[package]]
name = "python-dateutil"
version = "2.9.0.post0"
@@ -64,6 +101,34 @@ files = [
{file = "python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"},
]
[[package]]
name = "setuptools"
version = "80.9.0"
requires_python = ">=3.9"
summary = "Easily download, build, install, upgrade, and uninstall Python packages"
groups = ["build"]
files = [
{file = "setuptools-80.9.0-py3-none-any.whl", hash = "sha256:062d34222ad13e0cc312a4c02d73f059e86a4acbfbdea8f8f76b28c99f306922"},
{file = "setuptools-80.9.0.tar.gz", hash = "sha256:f36b47402ecde768dbfafc46e8e4207b4360c654f1f3bb84475f0a28628fb19c"},
]
[[package]]
name = "shiv"
version = "1.0.8"
requires_python = ">=3.6"
summary = "A command line utility for building fully self contained Python zipapps."
groups = ["build"]
dependencies = [
"click!=7.0,>=6.7",
"importlib-resources; python_version < \"3.7\"",
"pip>=9.0.3",
"setuptools",
]
files = [
{file = "shiv-1.0.8-py2.py3-none-any.whl", hash = "sha256:a60e4b05a2d2f8b820d567b1d89ee59af731759771c32c282d03c4ceae6aba24"},
{file = "shiv-1.0.8.tar.gz", hash = "sha256:2a68d69e98ce81cb5b8fdafbfc1e27efa93e6d89ca14bfae33482e4176f561d6"},
]
[[package]]
name = "six"
version = "1.17.0"

View File

@@ -1,6 +1,6 @@
[project]
name = "simple-recorder"
version = "0.1.0"
version = "0.1.3"
description = "A simple OBS recorder"
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]
dependencies = [
@@ -24,4 +24,10 @@ build-backend = "pdm.backend"
distribution = true
[tool.pdm.scripts]
compile = "uvx shiv -c simple-recorder -o bin/simple-recorder.pyz ."
compile = "shiv -c simple-recorder -o bin/simple-recorder.pyz ."
[dependency-groups]
build = [
"shiv>=1.0.8",
]

View File

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

View File

@@ -1,149 +0,0 @@
import logging
from datetime import datetime
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)
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("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("Recording is already active.")
client.set_profile_parameter(
"Output",
"FilenameFormatting",
f"{self.filename} {self.get_timestamp()}",
)
client.start_record()
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("Recording is not active.")
client.stop_record()
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)