mirror of
https://github.com/onyx-and-iris/simple-recorder.git
synced 2026-04-21 00:33:36 +00:00
Compare commits
41 Commits
v0.1.0
...
3c77be2ff9
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c77be2ff9 | |||
| e8d0fcf56d | |||
| 69a0f607e4 | |||
| 40429892e8 | |||
| 1a5c0d4537 | |||
| ebad2f51c9 | |||
| 528573cd5a | |||
| 3eb37295c2 | |||
| ef68915f6a | |||
| b161c1ec3d | |||
| e37ae8dddc | |||
| 1d6fbd0bda | |||
| 0814678278 | |||
| 68041f1406 | |||
| bba2361964 | |||
| d8cdae61a9 | |||
| a43813fc00 | |||
| 87dbd0b8e5 | |||
| 00dbe43479 | |||
| 6bdbb470c9 | |||
| b6c0e9dece | |||
| d28d5a578a | |||
| ae86785ba6 | |||
| 76815926e9 | |||
| 04b4e5521a | |||
| eecd51e0ca | |||
| 57f2e9deff | |||
| ca7c60f0e4 | |||
| c1055408fb | |||
| b22f6f6f95 | |||
| d2486be29a | |||
| 3c837f337e | |||
| 1f49dd961f | |||
| 59de0fdc4e | |||
| ac60cf0c06 | |||
| 479a447e52 | |||
| e8bacd70b6 | |||
| 5cff6e268a | |||
| 430aaf5cc5 | |||
| 130bf74f27 | |||
| b8bcea59fc |
62
.github/workflows/build.yml
vendored
Normal file
62
.github/workflows/build.yml
vendored
Normal 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
26
.github/workflows/release.yml
vendored
Normal 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
4
.gitignore
vendored
@@ -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/*
|
||||
70
README.md
70
README.md
@@ -3,15 +3,14 @@
|
||||
[](https://pdm-project.org)
|
||||
[](https://github.com/astral-sh/ruff)
|
||||
|
||||
A single purpose application for naming file recording in OBS.
|
||||
|
||||
Run it as a CLI or a GUI.
|
||||
A simple OBS recorder app. Run it as a CLI or a GUI.
|
||||
|
||||
---
|
||||
|
||||
## Requirements
|
||||
|
||||
- Python 3.11 or greater
|
||||
- [OBS Studio 28+][obs-studio]
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -27,38 +26,79 @@ uv tool install simple-recorder
|
||||
pipx install simple-recorder
|
||||
```
|
||||
|
||||
## Use
|
||||
*with pyz*
|
||||
|
||||
Without passing a subcommand (start/stop) a GUI will be launched, otherwise a CLI will be launched.
|
||||
An executable pyz has been included in [Releases](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
|
||||
|
||||
### GUI
|
||||
|
||||
To launch the GUI run the root command without any subcommands:
|
||||
|
||||
```console
|
||||
simple-recorder
|
||||
```
|
||||
|
||||

|
||||
|
||||
Just enter the filename and click *Start Recording*.
|
||||
Just enter the filename and click *Start*.
|
||||
|
||||
#### Themes
|
||||
|
||||
You can change the colour theme with the --theme option:
|
||||
|
||||
```console
|
||||
simple-recorder --theme="Light Purple"
|
||||
```
|
||||
|
||||
### CLI
|
||||
|
||||
```shell
|
||||
Usage: simple-recorder [OPTIONS] COMMAND
|
||||
|
||||
┏━ Subcommands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||
┏━ Subcommands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||
┃ start Start recording ┃
|
||||
┃ stop Stop recording ┃
|
||||
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
||||
┃ pause Pause recording ┃
|
||||
┃ resume Resume 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> GUI theme (Light Purple, Neutral Blue, Reds, Sandy Beach, ┃
|
||||
┃ Kayak, Light Blue 2) ┃
|
||||
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
||||
```
|
||||
|
||||
To launch the CLI pass any subcommand (start/stop etc...), 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
0
bin/.gitkeep
Normal file
Binary file not shown.
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 84 KiB |
69
pdm.lock
generated
69
pdm.lock
generated
@@ -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"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "simple-recorder"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
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",
|
||||
]
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
from .app import run
|
||||
from .cli import run
|
||||
|
||||
__all__ = ["run"]
|
||||
|
||||
@@ -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()
|
||||
71
src/simple_recorder/cli.py
Normal file
71
src/simple_recorder/cli.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import logging
|
||||
|
||||
from clypi import ClypiConfig, ClypiException, Command, arg, configure
|
||||
from typing_extensions import override
|
||||
|
||||
from .errors import SimpleRecorderError
|
||||
from .gui import SimpleRecorderWindow
|
||||
from .pause import Pause
|
||||
from .resume import Resume
|
||||
from .start import Start
|
||||
from .stop import Stop
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
config = ClypiConfig(
|
||||
nice_errors=(SimpleRecorderError,),
|
||||
)
|
||||
configure(config)
|
||||
|
||||
themes = [
|
||||
"Light Purple",
|
||||
"Neutral Blue",
|
||||
"Reds",
|
||||
"Sandy Beach",
|
||||
"Kayak",
|
||||
"Light Blue 2",
|
||||
]
|
||||
|
||||
|
||||
def theme_parser(value: str) -> str:
|
||||
"""Parse the theme argument."""
|
||||
if value not in themes:
|
||||
raise ClypiException(
|
||||
f"Invalid theme: {value}. Available themes: {', '.join(themes)}"
|
||||
)
|
||||
return value
|
||||
|
||||
|
||||
class SimpleRecorder(Command):
|
||||
subcommand: Start | Stop | Pause | Resume | 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=f"GUI theme ({', '.join(themes)})",
|
||||
)
|
||||
debug: bool = arg(
|
||||
default=False,
|
||||
env="DEBUG",
|
||||
help="Enable debug logging",
|
||||
hidden=True,
|
||||
)
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
"""Run the Simple Recorder GUI."""
|
||||
if self.debug:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
window = SimpleRecorderWindow(self.host, self.port, self.password, self.theme)
|
||||
await window.run()
|
||||
|
||||
|
||||
def run():
|
||||
"""Run the application."""
|
||||
SimpleRecorder.parse().start()
|
||||
11
src/simple_recorder/errors.py
Normal file
11
src/simple_recorder/errors.py
Normal 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
|
||||
183
src/simple_recorder/gui.py
Normal file
183
src/simple_recorder/gui.py
Normal file
@@ -0,0 +1,183 @@
|
||||
import logging
|
||||
|
||||
import FreeSimpleGUI as fsg
|
||||
import obsws_python as obsws
|
||||
|
||||
from .errors import SimpleRecorderError
|
||||
from .pause import Pause
|
||||
from .resume import Resume
|
||||
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)
|
||||
|
||||
try:
|
||||
with obsws.ReqClient(
|
||||
host=self.host, port=self.port, password=self.password, timeout=3
|
||||
) as client:
|
||||
resp = client.get_version()
|
||||
status_message = f"Connected to OBS {resp.obs_version} ✓"
|
||||
except (ConnectionRefusedError, TimeoutError):
|
||||
status_message = "Failed to connect to OBS. Is it running?"
|
||||
|
||||
recorder_layout = [
|
||||
[fsg.Text("Enter recording filename:", key="-PROMPT-")],
|
||||
[fsg.InputText("default_name", key="-FILENAME-", focus=True)],
|
||||
[
|
||||
fsg.Button("Start", key="Start Recording", size=(20, 1)),
|
||||
fsg.Button("Stop", key="Stop Recording", size=(20, 1)),
|
||||
],
|
||||
[
|
||||
fsg.Button("Pause", key="Pause Recording", size=(20, 1)),
|
||||
fsg.Button("Resume", key="Resume Recording", size=(20, 1)),
|
||||
],
|
||||
[
|
||||
fsg.Button("Split", key="Split Recording", size=(20, 1)),
|
||||
fsg.Button("Add Chapter", key="Add Chapter", size=(20, 1)),
|
||||
],
|
||||
]
|
||||
|
||||
frame = fsg.Frame(
|
||||
"",
|
||||
recorder_layout,
|
||||
relief=fsg.RELIEF_SUNKEN,
|
||||
)
|
||||
|
||||
recorder_tab = fsg.Tab(
|
||||
"Recorder",
|
||||
[
|
||||
[frame],
|
||||
[
|
||||
fsg.Text(
|
||||
f"Status: {status_message}",
|
||||
key="-OUTPUT-",
|
||||
text_color="white"
|
||||
if status_message.startswith("Connected")
|
||||
else "red",
|
||||
)
|
||||
],
|
||||
],
|
||||
)
|
||||
|
||||
settings_layout = [
|
||||
[fsg.Text("Enter the filepath for the recording:")],
|
||||
[fsg.InputText("", key="-FILEPATH-", size=(45, 1))],
|
||||
]
|
||||
|
||||
settings_tab = fsg.Tab("Settings", settings_layout)
|
||||
|
||||
mainframe = [
|
||||
[fsg.TabGroup([[recorder_tab, settings_tab]])],
|
||||
]
|
||||
|
||||
super().__init__("Simple Recorder", mainframe, finalize=True)
|
||||
self["-FILENAME-"].bind("<Return>", " || RETURN")
|
||||
self["Start Recording"].bind("<Return>", " || RETURN")
|
||||
self["Stop Recording"].bind("<Return>", " || RETURN")
|
||||
self["Pause Recording"].bind("<Return>", " || RETURN")
|
||||
self["Resume Recording"].bind("<Return>", " || RETURN")
|
||||
|
||||
self["-FILENAME-"].bind("<KeyPress>", " || KEYPRESS")
|
||||
self["-FILENAME-"].update(select=True)
|
||||
self["Add Chapter"].bind("<FocusIn>", " || FOCUS")
|
||||
self["Add Chapter"].bind("<Enter>", " || FOCUS")
|
||||
self["Add Chapter"].bind("<FocusOut>", " || LEAVE")
|
||||
self["Add Chapter"].bind("<Leave>", " || LEAVE")
|
||||
self["Add Chapter"].bind("<Button-3>", " || RIGHT_CLICK")
|
||||
|
||||
async def run(self):
|
||||
while True:
|
||||
event, values = self.read()
|
||||
self.logger.debug(f"Event: {event}, Values: {values}")
|
||||
if event == fsg.WIN_CLOSED:
|
||||
break
|
||||
|
||||
match e := event.split(" || "):
|
||||
case ["Start Recording"] | ["Start Recording" | "-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 SimpleRecorderError as e:
|
||||
self["-OUTPUT-"].update(
|
||||
f"Error: {e.raw_message}", text_color="red"
|
||||
)
|
||||
|
||||
case ["Stop Recording"] | ["Stop Recording", "RETURN"]:
|
||||
try:
|
||||
await Stop(
|
||||
host=self.host, port=self.port, password=self.password
|
||||
).run()
|
||||
self["-OUTPUT-"].update(
|
||||
"Recording stopped successfully", text_color="green"
|
||||
)
|
||||
except SimpleRecorderError as e:
|
||||
self["-OUTPUT-"].update(
|
||||
f"Error: {e.raw_message}", text_color="red"
|
||||
)
|
||||
|
||||
case ["Pause Recording"] | ["Pause Recording", "RETURN"]:
|
||||
try:
|
||||
await Pause(
|
||||
host=self.host, port=self.port, password=self.password
|
||||
).run()
|
||||
self["-OUTPUT-"].update(
|
||||
"Recording paused successfully", text_color="green"
|
||||
)
|
||||
except SimpleRecorderError as e:
|
||||
self["-OUTPUT-"].update(
|
||||
f"Error: {e.raw_message}", text_color="red"
|
||||
)
|
||||
|
||||
case ["Resume Recording"] | ["Resume Recording", "RETURN"]:
|
||||
try:
|
||||
await Resume(
|
||||
host=self.host, port=self.port, password=self.password
|
||||
).run()
|
||||
self["-OUTPUT-"].update(
|
||||
"Recording resumed successfully", text_color="green"
|
||||
)
|
||||
except SimpleRecorderError as e:
|
||||
self["-OUTPUT-"].update(
|
||||
f"Error: {e.raw_message}", text_color="red"
|
||||
)
|
||||
|
||||
case ["Add Chapter", "FOCUS" | "LEAVE" as focus_event]:
|
||||
if focus_event == "FOCUS":
|
||||
self["-OUTPUT-"].update(
|
||||
"Right-click to set a chapter name", text_color="white"
|
||||
)
|
||||
else:
|
||||
self["-OUTPUT-"].update("", text_color="white")
|
||||
|
||||
case ["Add Chapter", "RIGHT_CLICK"]:
|
||||
_ = fsg.popup_get_text(
|
||||
"Enter chapter name:",
|
||||
"Add Chapter",
|
||||
default_text="unnamed",
|
||||
)
|
||||
|
||||
case ["Split Recording" | "Add Chapter"]:
|
||||
self["-OUTPUT-"].update(
|
||||
"This feature is not implemented yet", text_color="orange"
|
||||
)
|
||||
|
||||
case _:
|
||||
self.logger.debug(f"Unhandled event: {e}")
|
||||
|
||||
self.close()
|
||||
30
src/simple_recorder/pause.py
Normal file
30
src/simple_recorder/pause.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import obsws_python as obsws
|
||||
from clypi import Command, arg
|
||||
from typing_extensions import override
|
||||
|
||||
from .errors import SimpleRecorderError
|
||||
|
||||
|
||||
class Pause(Command):
|
||||
"""Pause recording."""
|
||||
|
||||
host: str = arg(inherited=True)
|
||||
port: int = arg(inherited=True)
|
||||
password: str = arg(inherited=True)
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
try:
|
||||
with obsws.ReqClient(
|
||||
host=self.host, port=self.port, password=self.password, timeout=3
|
||||
) as client:
|
||||
resp = client.get_record_status()
|
||||
if not resp.output_active:
|
||||
raise SimpleRecorderError("No active recording to pause.")
|
||||
if resp.output_paused:
|
||||
raise SimpleRecorderError("Recording is already paused.")
|
||||
|
||||
client.pause_record()
|
||||
print("Recording paused successfully.")
|
||||
except TimeoutError:
|
||||
raise SimpleRecorderError("Failed to connect to OBS. Is it running?")
|
||||
30
src/simple_recorder/resume.py
Normal file
30
src/simple_recorder/resume.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import obsws_python as obsws
|
||||
from clypi import Command, arg
|
||||
from typing_extensions import override
|
||||
|
||||
from .errors import SimpleRecorderError
|
||||
|
||||
|
||||
class Resume(Command):
|
||||
"""Resume recording."""
|
||||
|
||||
host: str = arg(inherited=True)
|
||||
port: int = arg(inherited=True)
|
||||
password: str = arg(inherited=True)
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
try:
|
||||
with obsws.ReqClient(
|
||||
host=self.host, port=self.port, password=self.password, timeout=3
|
||||
) as client:
|
||||
resp = client.get_record_status()
|
||||
if not resp.output_active:
|
||||
raise SimpleRecorderError("No active recording to resume.")
|
||||
if not resp.output_paused:
|
||||
raise SimpleRecorderError("Recording is not paused.")
|
||||
|
||||
client.resume_record()
|
||||
print("Recording resumed successfully.")
|
||||
except TimeoutError:
|
||||
raise SimpleRecorderError("Failed to connect to OBS. Is it running?")
|
||||
49
src/simple_recorder/start.py
Normal file
49
src/simple_recorder/start.py
Normal file
@@ -0,0 +1,49 @@
|
||||
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.")
|
||||
|
||||
try:
|
||||
with obsws.ReqClient(
|
||||
host=self.host, port=self.port, password=self.password, timeout=3
|
||||
) 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)}")
|
||||
except TimeoutError:
|
||||
raise SimpleRecorderError("Failed to connect to OBS. Is it running?")
|
||||
29
src/simple_recorder/stop.py
Normal file
29
src/simple_recorder/stop.py
Normal file
@@ -0,0 +1,29 @@
|
||||
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):
|
||||
try:
|
||||
with obsws.ReqClient(
|
||||
host=self.host, port=self.port, password=self.password, timeout=3
|
||||
) 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."))
|
||||
except TimeoutError:
|
||||
raise SimpleRecorderError("Failed to connect to OBS. Is it running?")
|
||||
4
src/simple_recorder/styler.py
Normal file
4
src/simple_recorder/styler.py
Normal file
@@ -0,0 +1,4 @@
|
||||
import clypi
|
||||
|
||||
highlight = clypi.Styler(fg="green")
|
||||
error = clypi.Styler(fg="red", bold=True)
|
||||
Reference in New Issue
Block a user