Skip to content

Commit

Permalink
Added Scene Collection (#24)
Browse files Browse the repository at this point in the history
* Update command.rs

update for scene collection

* Update main.rs

update for scene collection

* Update for collection and item

* Added SceneItem

* Added SceneItem

* Update README.md
  • Loading branch information
mansman12 authored Dec 21, 2023
1 parent 3e62593 commit 4298f22
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
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

0 comments on commit 4298f22

Please sign in to comment.