mirror of https://github.com/dnaka91/obws
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
873 B
Rust
35 lines
873 B
Rust
use std::env;
|
|
|
|
use anyhow::Result;
|
|
use base64::engine::{general_purpose, Engine};
|
|
use obws::{requests::sources::TakeScreenshot, Client};
|
|
use tokio::fs;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
dotenvy::dotenv().ok();
|
|
|
|
env::set_var("RUST_LOG", "obws=debug");
|
|
tracing_subscriber::fmt::init();
|
|
|
|
let client = Client::connect("localhost", 4455, env::var("OBS_PASSWORD").ok()).await?;
|
|
|
|
let screenshot = client
|
|
.sources()
|
|
.take_screenshot(TakeScreenshot {
|
|
source: "OBWS-TEST-Scene".into(),
|
|
width: None,
|
|
height: None,
|
|
compression_quality: None,
|
|
format: "png",
|
|
})
|
|
.await?;
|
|
|
|
let pos = screenshot.find("base64,").unwrap();
|
|
let image = general_purpose::STANDARD.decode(&screenshot[pos + 7..])?;
|
|
|
|
fs::write("screenshot.png", &image).await?;
|
|
|
|
Ok(())
|
|
}
|