-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize and make things more typed, as well as improve the CLI (#14)
* Reorganize and make things more typed, as well as improve the CLI Signed-off-by: Dallas Strouse <[email protected]> * Slightly update the README to add websocket details Signed-off-by: Dallas Strouse <[email protected]> * Format and clippy fixes Signed-off-by: Dallas Strouse <[email protected]> * Bring back a default websocket argument Signed-off-by: Dallas Strouse <[email protected]> --------- Signed-off-by: Dallas Strouse <[email protected]>
- Loading branch information
1 parent
af35b01
commit 62998f5
Showing
5 changed files
with
183 additions
and
104 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,11 @@ obs-cmd virtualcam start | |
obs-cmd replay toggle | ||
obs-cmd replay save | ||
obs-cmd info | ||
obs-cmd --obsws obsws://localhost:4455/secret info # You can override the default `obsws` url | ||
obs-cmd --websocket obsws://localhost:4455/secret info # You can override the default `obsws` url | ||
``` | ||
|
||
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. | ||
|
||
### Installation | ||
|
||
|
||
|
@@ -105,4 +107,4 @@ Donations are welcome and will go towards further development of this project | |
monero:88LyqYXn4LdCVDtPWKuton9hJwbo8ZduNEGuARHGdeSJ79BBYWGpMQR8VGWxGDKtTLLM6E9MJm8RvW9VMUgCcSXu19L9FSv | ||
bitcoin:bc1q6mh77hfv8x8pa0clzskw6ndysujmr78j6se025 | ||
lightning:[email protected] | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
use clap::{Parser, Subcommand}; | ||
use std::str::FromStr; | ||
use url::Url; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct ObsWebsocket { | ||
pub hostname: String, | ||
pub port: u16, | ||
pub password: Option<String>, | ||
} | ||
|
||
impl FromStr for ObsWebsocket { | ||
type Err = &'static str; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match Url::parse(s) { | ||
Ok(unvalidated_websocket) => { | ||
if unvalidated_websocket.scheme() != "obsws" { | ||
return Err( | ||
"Invalid URL format, use the format obsws://hostname:port/password", | ||
); | ||
} | ||
|
||
let hostname = unvalidated_websocket.host().unwrap().to_string(); | ||
|
||
let port = | ||
match unvalidated_websocket.port() { | ||
Some(port) => port, | ||
None => return Err( | ||
"Please specify a port in the format obsws://hostname:port/password", | ||
), | ||
}; | ||
|
||
let password = match unvalidated_websocket.path() { | ||
"" => None, | ||
_ => { | ||
let mut pass = unvalidated_websocket.path().to_string(); | ||
// Otherwise the `/` part of the password in the URL is included. | ||
let _ = pass.remove(0); | ||
Some(pass) | ||
} | ||
}; | ||
|
||
Ok(ObsWebsocket { | ||
hostname, | ||
port, | ||
password, | ||
}) | ||
} | ||
Err(_) => Err("Invalid URL format, use the format obsws://hostname:port/password"), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Subcommand, Clone, Debug)] | ||
pub enum Replay { | ||
Start, | ||
Stop, | ||
Toggle, | ||
Save, | ||
} | ||
|
||
#[derive(Subcommand, Clone, Debug)] | ||
pub enum VirtualCamera { | ||
Start, | ||
Stop, | ||
Toggle, | ||
} | ||
|
||
#[derive(Subcommand, Clone, Debug)] | ||
pub enum Streaming { | ||
Start, | ||
Stop, | ||
Toggle, | ||
} | ||
|
||
#[derive(Subcommand, Clone, Debug)] | ||
pub enum Recording { | ||
Start, | ||
Stop, | ||
Toggle, | ||
} | ||
|
||
#[derive(Parser)] | ||
#[clap(author, version, about, long_about = None)] | ||
pub struct Cli { | ||
#[clap(short, long)] | ||
/// The default websocket URL is `obsws://localhost:4455/secret` | ||
/// if this argument is not provided | ||
pub websocket: Option<ObsWebsocket>, | ||
#[clap(subcommand)] | ||
pub command: Commands, | ||
} | ||
|
||
#[derive(Subcommand)] | ||
pub enum Commands { | ||
Info, | ||
Scene { | ||
switch_placeholder: String, // NOTE: just for args positioning | ||
scene_name: String, | ||
}, | ||
|
||
#[clap(subcommand)] | ||
Replay(Replay), | ||
|
||
#[clap(subcommand)] | ||
VirtualCamera(VirtualCamera), | ||
|
||
#[clap(subcommand)] | ||
Streaming(Streaming), | ||
|
||
#[clap(subcommand)] | ||
Recording(Recording), | ||
|
||
ToggleMute { | ||
device: String, | ||
}, | ||
|
||
Filter { | ||
command: String, | ||
source: String, | ||
filter: String, | ||
}, | ||
} |
Oops, something went wrong.