Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Scene Collection #24

Merged
merged 6 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Just a minimal API is supported
obs-cmd --help
obs-cmd scene switch <scene>
obs-cmd scene switch @cam-front
obs-cmd scene-collection switch <collection>
obs-cmd scene-item toggle <scene> <item>
obs-cmd toggle-mute Mic/Aux
obs-cmd recording toggle
obs-cmd streaming start
Expand Down
11 changes: 11 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ pub enum Commands {
switch_placeholder: String, // NOTE: just for args positioning
scene_name: String,
},
SceneCollection {
switch_placeholder: String, // NOTE: just for args positioning
scene_collection_name: String,
},

#[clap(subcommand)]
Replay(Replay),
Expand All @@ -121,4 +125,11 @@ pub enum Commands {
source: String,
filter: String,
},

SceneItem {
command: String,
scene: String,
source: String,
}

}
55 changes: 53 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ mod command;
use command::*;

use clap::Parser;
use obws::{requests::filters::SetEnabled, Client};
use obws::{requests::filters::SetEnabled as SetEnabledFilter, Client};
use obws::{requests::scene_items::SetEnabled as SetEnabledItem};
use obws::{requests::scene_items::Id as IdItem};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -28,6 +30,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Result: {:?}", res);
}

Commands::SceneCollection {
switch_placeholder,
scene_collection_name,
} => {
// let scene_name = &args[3];
let res = client.scene_collections().set_current(scene_collection_name).await;
println!("Set current scene collection: {} {}", switch_placeholder, scene_collection_name);
println!("Result: {:?}", res);
}

Commands::Info => {
let version = client.general().version().await?;
println!("Version: {:?}", version);
Expand Down Expand Up @@ -152,14 +164,53 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
};
let res = client
.filters()
.set_enabled(SetEnabled {
.set_enabled(SetEnabledFilter {
source,
filter,
enabled,
})
.await;
println!("Result: {:?}", res);
}

Commands::SceneItem {
command,
scene,
source,
} => {
println!("Scene Item: {:?} {:?} {:?}", command, scene, source);

// get item_id
let item_id = client
.scene_items()
.id(IdItem {
scene,
source,
search_offset: Some(0)
})
.await?;

// use item_id in toggle
let enabled: bool = match command.as_str() {
"enable" => true,
"disable" => false,
"toggle" => !client.scene_items().enabled(scene, item_id).await?,
_ => {
println!("Invalid scene item command: {}", command);
return Ok(());
}
}; // use item_id in setenabled
let res = client
.scene_items()
.set_enabled(SetEnabledItem {
scene,
item_id,
enabled,
})
.await;
println!("Result: {:?}", res);
}

}

Ok(())
Expand Down
Loading