mirror of
https://github.com/onyx-and-iris/simple-recorder.git
synced 2025-08-05 10:41:45 +00:00
Compare commits
11 Commits
eecd51e0ca
...
bba2361964
Author | SHA1 | Date | |
---|---|---|---|
bba2361964 | |||
d8cdae61a9 | |||
a43813fc00 | |||
87dbd0b8e5 | |||
00dbe43479 | |||
6bdbb470c9 | |||
b6c0e9dece | |||
d28d5a578a | |||
ae86785ba6 | |||
76815926e9 | |||
04b4e5521a |
41
README.md
41
README.md
@ -30,7 +30,7 @@ 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.
|
||||
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
|
||||
|
||||
@ -46,52 +46,59 @@ Or load them from your environment:
|
||||
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
|
||||
```
|
||||
|
||||

|
||||
|
||||
Just enter the filename and click *Start Recording*.
|
||||
|
||||
#### Themes
|
||||
|
||||
Load the GUI with different themes:
|
||||
However, passing flags is fine, 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> 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/
|
@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "simple-recorder"
|
||||
version = "0.1.3"
|
||||
version = "0.1.5"
|
||||
description = "A simple OBS recorder"
|
||||
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]
|
||||
dependencies = [
|
||||
|
@ -1,3 +1,3 @@
|
||||
from .app import run
|
||||
from .cli import run
|
||||
|
||||
__all__ = ["run"]
|
||||
|
@ -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("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.")
|
||||
|
||||
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("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()
|
60
src/simple_recorder/cli.py
Normal file
60
src/simple_recorder/cli.py
Normal file
@ -0,0 +1,60 @@
|
||||
import logging
|
||||
|
||||
from clypi import ClypiConfig, ClypiException, Command, arg, configure
|
||||
from typing_extensions import override
|
||||
|
||||
from .errors import SimpleRecorderError
|
||||
from .gui import SimpleRecorderWindow
|
||||
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 | 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)})",
|
||||
)
|
||||
|
||||
@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()
|
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
|
70
src/simple_recorder/gui.py
Normal file
70
src/simple_recorder/gui.py
Normal file
@ -0,0 +1,70 @@
|
||||
import logging
|
||||
|
||||
import FreeSimpleGUI as fsg
|
||||
from clypi import ClypiException
|
||||
|
||||
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.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")
|
||||
|
||||
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 _:
|
||||
self.logger.warning(f"Unhandled event: {event}")
|
||||
|
||||
self.close()
|
46
src/simple_recorder/start.py
Normal file
46
src/simple_recorder/start.py
Normal 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)}")
|
26
src/simple_recorder/stop.py
Normal file
26
src/simple_recorder/stop.py
Normal 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."))
|
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)
|
Loading…
x
Reference in New Issue
Block a user