adding a basic setup for connecting OBS
This commit is contained in:
parent
511c34ee41
commit
c6c3ed5d42
5 changed files with 324 additions and 10 deletions
|
@ -14,4 +14,5 @@ pub mod songs;
|
|||
pub mod video_model;
|
||||
pub mod ytdl;
|
||||
pub mod utils;
|
||||
pub mod obs;
|
||||
// mod video_thumbnail;
|
||||
|
|
38
src/rust/obs.rs
Normal file
38
src/rust/obs.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use std::error::Error;
|
||||
|
||||
use obws::Client;
|
||||
use obws::responses::scenes::Scenes;
|
||||
use tracing::debug;
|
||||
pub struct Obs {
|
||||
scenes: Scenes,
|
||||
client: Client,
|
||||
}
|
||||
|
||||
impl Obs {
|
||||
pub async fn setup(mut self) -> Result<(), Box<dyn Error>> {
|
||||
let client = Client::connect("localhost", 4455, Some("")).await?;
|
||||
let scene_list = client.scenes().list().await?;
|
||||
debug!(?scene_list);
|
||||
self.scenes = scene_list;
|
||||
self.client = client;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_list(self) -> Result<Vec<String>, String> {
|
||||
let scenes = self.scenes.scenes.iter().map(|x| x.name).collect::<Vec<String>>();
|
||||
if scenes.len() > 0 {
|
||||
Ok(scenes)
|
||||
} else {
|
||||
Err(format!("Scenes found: {}", scenes.len()))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_scene(self, scene: String) -> Result<(), String> {
|
||||
if let Some(scene) = self.scenes.scenes.iter().filter(|x| x.name == scene).next() {
|
||||
self.client.scenes().set_current_program_scene(scene.name.as_str());
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Couldn't set the scene".to_string())
|
||||
}
|
||||
}
|
||||
}
|
|
@ -56,6 +56,8 @@ mod service_item_model {
|
|||
video_start_time: f32,
|
||||
#[qproperty]
|
||||
video_end_time: f32,
|
||||
#[qproperty]
|
||||
obs_scene: QString,
|
||||
}
|
||||
|
||||
impl Default for ServiceItm {
|
||||
|
@ -75,6 +77,7 @@ mod service_item_model {
|
|||
looping: false,
|
||||
video_start_time: 0.0,
|
||||
video_end_time: 0.0,
|
||||
obs_scene: QString::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -147,6 +150,8 @@ mod service_item_model {
|
|||
use tar::{Archive, Builder};
|
||||
use tracing::{debug, debug_span, error, info, instrument};
|
||||
use zstd::{Decoder, Encoder};
|
||||
|
||||
use crate::obs::Obs;
|
||||
impl qobject::ServiceItemMod {
|
||||
#[qinvokable]
|
||||
pub fn clear(mut self: Pin<&mut Self>) {
|
||||
|
@ -602,6 +607,7 @@ mod service_item_model {
|
|||
// We use this signal generated by our signals enum to tell QML that
|
||||
// the active service_item has changed which is used to reposition views.
|
||||
self.as_mut().emit_active_changed();
|
||||
Obs::set_scene(service_item.obs_scene.to_string());
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue