32 Commits

Author SHA1 Message Date
cb892d66d8 run ruff format as well 2025-06-27 12:38:35 +01:00
fccef1e2bf rename build workflow to release
add ruff workflow
2025-06-27 12:31:35 +01:00
3c77be2ff9 reword 2025-06-27 08:28:06 +01:00
e8d0fcf56d upd button name in README 2025-06-27 08:25:00 +01:00
69a0f607e4 upd screenshot 2025-06-27 08:23:27 +01:00
40429892e8 minor bump 2025-06-27 08:19:42 +01:00
1a5c0d4537 use help output in README 2025-06-27 08:19:18 +01:00
ebad2f51c9 upd screenshot 2025-06-27 08:19:08 +01:00
528573cd5a process pause + record mouse/keyboard events 2025-06-27 08:19:02 +01:00
3eb37295c2 register pause + resume as subcommands on the CLI 2025-06-27 08:17:16 +01:00
ef68915f6a implement pause + resume 2025-06-27 08:17:04 +01:00
b161c1ec3d upd description 2025-06-27 07:54:12 +01:00
e37ae8dddc upd screenshot 2025-06-27 07:50:46 +01:00
1d6fbd0bda add tabgroup to mainframe
add pause, split and add chapter buttons to Recorder tab
- they are not implemented yet

add timeouts on requests + handle them

add obs connected status message on GUI load
2025-06-27 07:47:56 +01:00
0814678278 debug should be a hidden option
patch bump
2025-06-26 14:38:53 +01:00
68041f1406 fix bug with parser (regression)
patch bump
2025-06-26 09:56:53 +01:00
bba2361964 add available themes to --theme help string
patch bump
2025-06-26 08:56:32 +01:00
d8cdae61a9 upd --help output in README 2025-06-26 06:54:47 +01:00
a43813fc00 fix help string for theme option 2025-06-26 06:53:36 +01:00
87dbd0b8e5 typo 2025-06-26 06:52:20 +01:00
00dbe43479 patch bump 2025-06-26 06:47:50 +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
17 changed files with 543 additions and 261 deletions

View File

@@ -1,62 +0,0 @@
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/publish.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
name: Publish to PyPI
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

View File

@@ -1,23 +1,62 @@
name: Release name: Release PYZ
on: on:
release: push:
types: [published] tags:
- 'v*.*.*'
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: write
jobs: jobs:
pypi-publish: build:
name: upload release to PyPI
runs-on: ubuntu-latest 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: steps:
- uses: actions/checkout@v4 - name: Checkout code
uses: actions/checkout@v4
- uses: pdm-project/setup-pdm@v4 - name: Set up PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: '3.11'
- name: Publish package distributions to PyPI - name: Install dependencies
run: pdm publish 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, '-') }}

19
.github/workflows/ruff.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
name: Ruff
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
with:
args: 'format --check --diff'

View File

@@ -3,9 +3,7 @@
[![pdm-managed](https://img.shields.io/endpoint?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fpdm-project%2F.github%2Fbadge.json)](https://pdm-project.org) [![pdm-managed](https://img.shields.io/endpoint?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fpdm-project%2F.github%2Fbadge.json)](https://pdm-project.org)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
A single purpose application for naming file recording in OBS. A simple OBS recorder app. Run it as a CLI or a GUI.
Run it as a CLI or a GUI.
--- ---
@@ -30,7 +28,7 @@ pipx install simple-recorder
*with pyz* *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. 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 ## Configuration
@@ -46,42 +44,61 @@ 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*.
#### Themes
You can change the colour theme with the --theme option:
```console
simple-recorder --theme="Light Purple"
```
### 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
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃ pause Pause recording ┃
┃ resume Resume 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> 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 ```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/

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 84 KiB

View File

@@ -1,6 +1,6 @@
[project] [project]
name = "simple-recorder" name = "simple-recorder"
version = "0.1.2" version = "0.2.0"
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,164 +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",
"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 | 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 application."""
SimpleRecorder.parse().start()
if __name__ == "__main__":
run()

View 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()

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

183
src/simple_recorder/gui.py Normal file
View 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()

View 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?")

View 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?")

View 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?")

View 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?")

View File

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