Skip to content

Commit

Permalink
Now is possible to pass ws url as env variable
Browse files Browse the repository at this point in the history
OBS_WEBSOCKET_URL=obsws://localhost:4455/secret obs-cmd info

fix: #52
  • Loading branch information
g committed Dec 21, 2024
1 parent f978024 commit a5218f9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "obs-cmd"
version = "0.17.8"
version = "0.18.1"
edition = "2021"
description = "A minimal command to control obs via obs-websocket"
authors = ["Luigi Maselli <luigi@grigio.org>"]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ obs-cmd replay status
obs-cmd replay last-replay
obs-cmd info
obs-cmd --websocket obsws://localhost:4455/secret info # You can override the default `obsws` url
OBS_WEBSOCKET_URL=obsws://localhost:4455/secret obs-cmd info
```

You can override the websocket URL, which can be found in OBS -> Tools -> WebSocket Server Settings. `localhost` for the hostname will work for most, instead of the full IP address. If you set the password as `secret` you can avoid to specify the `--websocket` argument.
Expand Down
15 changes: 13 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,25 @@ use obws::requests::sources::SaveScreenshot;
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = Cli::parse();

let client = match cli.websocket {
let client = match std::env::var("OBS_WEBSOCKET_URL") {
Ok(url) => {
let parsed_url = url::Url::parse(&url).expect("Invalid OBS_WEBSOCKET_URL format");
let hostname = parsed_url.host_str().expect("Hostname not found in OBS_WEBSOCKET_URL").to_string();
let port = parsed_url.port().expect("Port not found in OBS_WEBSOCKET_URL");
let password = parsed_url.path_segments().and_then(|mut segments| segments.next()).ok_or(url::ParseError::RelativeUrlWithoutBase)?;

// let password = parsed_url.password().map(|p| p.to_string());
Client::connect(hostname, port, Some(password)).await?
},
Err(_) => match cli.websocket {
Some(ObsWebsocket {
hostname,
port,
password,
}) => Client::connect(hostname, port, password).await?,
None => Client::connect("localhost", 4455, Some("secret")).await?,
};
},
};

match &cli.command {
Commands::Scene(action) => {
Expand Down

0 comments on commit a5218f9

Please sign in to comment.