rustfmt things

This commit is contained in:
Chris Cochrun 2024-04-14 10:50:30 -05:00
parent f2faa0564a
commit 9d9ecb3cc0
6 changed files with 75 additions and 60 deletions

View file

@ -16,4 +16,3 @@ pub mod utils;
pub mod video_model; pub mod video_model;
pub mod ytdl; pub mod ytdl;
// mod video_thumbnail; // mod video_thumbnail;

View file

@ -1,11 +1,11 @@
use core::fmt; use core::fmt;
use std::{error::Error, pin::Pin};
use std::thread::sleep;
use std::time::Duration;
use cxx_qt::CxxQtType; use cxx_qt::CxxQtType;
use cxx_qt_lib::{QStringList, QString}; use cxx_qt_lib::{QString, QStringList};
use obws::responses::scenes::Scenes; use obws::responses::scenes::Scenes;
use obws::Client; use obws::Client;
use std::thread::sleep;
use std::time::Duration;
use std::{error::Error, pin::Pin};
use tracing::{debug, error}; use tracing::{debug, error};
use crate::obs::obs_model::QList_QString; use crate::obs::obs_model::QList_QString;
@ -13,7 +13,7 @@ use crate::obs::obs_model::QList_QString;
pub struct Obs { pub struct Obs {
scenes: Scenes, scenes: Scenes,
client: Option<Client>, client: Option<Client>,
current_program_scene: Option<String> current_program_scene: Option<String>,
} }
impl fmt::Debug for Obs { impl fmt::Debug for Obs {
@ -30,7 +30,7 @@ impl Clone for Obs {
Self { Self {
scenes: self.scenes.clone(), scenes: self.scenes.clone(),
client: Some(make_client()), client: Some(make_client()),
current_program_scene: self.current_program_scene.clone() current_program_scene: self.current_program_scene.clone(),
} }
} }
} }
@ -40,7 +40,7 @@ impl Default for Obs {
Self { Self {
scenes: Scenes::default(), scenes: Scenes::default(),
client: None, client: None,
current_program_scene: None current_program_scene: None,
} }
} }
} }
@ -51,12 +51,13 @@ impl Obs {
Client::connect("localhost", 4455, Some("")).await?; Client::connect("localhost", 4455, Some("")).await?;
let scenes_object = client.scenes(); let scenes_object = client.scenes();
let scene_list = scenes_object.list().await?; let scene_list = scenes_object.list().await?;
let current_program_scene = scenes_object.current_program_scene().await?; let current_program_scene =
scenes_object.current_program_scene().await?;
debug!(?scene_list); debug!(?scene_list);
Ok(Self { Ok(Self {
scenes: scene_list, scenes: scene_list,
client: Some(client), client: Some(client),
current_program_scene: Some(current_program_scene) current_program_scene: Some(current_program_scene),
}) })
} }
@ -86,10 +87,15 @@ impl Obs {
let runtime = tokio::runtime::Runtime::new()?; let runtime = tokio::runtime::Runtime::new()?;
let handle = runtime.spawn(async move { let handle = runtime.spawn(async move {
debug!("in spawn: before setting"); debug!("in spawn: before setting");
let res = client.scenes().set_current_program_scene(&scene).await; let res = client
.scenes()
.set_current_program_scene(&scene)
.await;
match res { match res {
Ok(o) => debug!("in spawn: after setting: success"), Ok(o) => {
Err(e) => error!(?e, "in spawn: after setting") debug!("in spawn: after setting: success")
}
Err(e) => error!(?e, "in spawn: after setting"),
} }
}); });
@ -151,13 +157,11 @@ pub struct ObsModelRust {
port: QString, port: QString,
connected: bool, connected: bool,
obs: Option<Obs>, obs: Option<Obs>,
current_program_scene: QString current_program_scene: QString,
} }
impl obs_model::ObsModel { impl obs_model::ObsModel {
pub fn update_scenes( pub fn update_scenes(mut self: Pin<&mut Self>) -> QStringList {
mut self: Pin<&mut Self>,
) -> QStringList {
debug!("updating scenes"); debug!("updating scenes");
let mut scenes_list = QList_QString::default(); let mut scenes_list = QList_QString::default();
if let Some(obs) = &self.as_mut().rust_mut().obs { if let Some(obs) = &self.as_mut().rust_mut().obs {
@ -184,7 +188,8 @@ impl obs_model::ObsModel {
Ok(o) => { Ok(o) => {
if let Some(scene) = &o.current_program_scene { if let Some(scene) = &o.current_program_scene {
let scene = QString::from(scene); let scene = QString::from(scene);
self.as_mut().set_current_program_scene(scene); self.as_mut()
.set_current_program_scene(scene);
} }
self.as_mut().set_connected(true); self.as_mut().set_connected(true);
self.as_mut().rust_mut().obs = Some(o); self.as_mut().rust_mut().obs = Some(o);
@ -226,7 +231,9 @@ mod test {
let future = Client::connect("localhost", 4455, Some("")); let future = Client::connect("localhost", 4455, Some(""));
let client = runtime.block_on(future).unwrap(); let client = runtime.block_on(future).unwrap();
let scene = String::from("me"); let scene = String::from("me");
let res = runtime.block_on(client.scenes().set_current_program_scene(&scene)); let res = runtime.block_on(
client.scenes().set_current_program_scene(&scene),
);
debug_assert!(res.is_ok()); debug_assert!(res.is_ok());
} }
} }

View file

@ -285,24 +285,22 @@ use cxx_qt_lib::{
QByteArray, QModelIndex, QString, QStringList, QUrl, QVariant, QByteArray, QModelIndex, QString, QStringList, QUrl, QVariant,
}; };
use dirs; use dirs;
use serde::{Deserialize, Serialize}; use serde_json::{json, Value};
use serde_json::{json, Deserializer, Map, Serializer, Value}; use std::io::{Read, Write};
use std::ffi::{OsStr, OsString};
use std::io::{self, Read, Write};
use std::iter; use std::iter;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::pin::Pin; use std::pin::Pin;
use std::str;
use std::{fs, println}; use std::{fs, println};
use tar::{Archive, Builder}; use tar::{Archive, Builder};
use tracing::{debug, debug_span, error, info, instrument}; use tracing::{debug, error};
use zstd::{Decoder, Encoder}; use zstd::{Decoder, Encoder};
use self::service_item_model::{ use self::service_item_model::{
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32, QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
ServiceRoles, ServiceRoles,
}; };
use super::service_item_model::service_item_model::ServiceItemModel;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct ServiceItem { pub struct ServiceItem {
name: QString, name: QString,

View file

@ -287,7 +287,6 @@ pub struct SlideModelRust {
count: i32, count: i32,
} }
impl Default for SlideModelRust { impl Default for SlideModelRust {
fn default() -> Self { fn default() -> Self {
let obs = let obs =
@ -319,7 +318,10 @@ impl slide_model::SlideModel {
.append(self.get_role(SlideRoles::VideoThumbnail)); .append(self.get_role(SlideRoles::VideoThumbnail));
let thread = self.qt_thread(); let thread = self.qt_thread();
let model_index = self.as_ref().index(index, 0, &QModelIndex::default()).clone(); let model_index = self
.as_ref()
.index(index, 0, &QModelIndex::default())
.clone();
if let Some(slide) = if let Some(slide) =
self.as_mut().rust_mut().slides.get_mut(index as usize) self.as_mut().rust_mut().slides.get_mut(index as usize)
{ {
@ -327,26 +329,39 @@ impl slide_model::SlideModel {
let path = let path =
PathBuf::from(slide.video_background.to_string()); PathBuf::from(slide.video_background.to_string());
let screenshot = ffmpeg::bg_path_from_video(&path); let screenshot = ffmpeg::bg_path_from_video(&path);
let screenshot_string = QString::from( let screenshot_string =
screenshot.to_str().unwrap() QString::from(screenshot.to_str().unwrap())
).insert(0, &QString::from("file://")).to_owned(); .insert(0, &QString::from("file://"))
.to_owned();
slide.video_thumbnail = screenshot_string; slide.video_thumbnail = screenshot_string;
std::thread::spawn(move || { std::thread::spawn(move || {
let result = ffmpeg::bg_from_video(&path, &screenshot); let result =
ffmpeg::bg_from_video(&path, &screenshot);
match result { match result {
Ok(_o) => debug!("Success making video background!"), Ok(_o) => {
Err(error) => error!(?error, "Error making video background") debug!("Success making video background!")
}
Err(error) => error!(
?error,
"Error making video background"
),
}; };
let result = thread.queue(move |mut slide_model| let result =
thread.queue(move |mut slide_model| {
slide_model.as_mut().data_changed( slide_model.as_mut().data_changed(
&model_index, &model_index,
&model_index, &model_index,
&vector_roles, &vector_roles,
) )
); });
match result { match result {
Ok(o) => debug!("Success in creating qt_thread"), Ok(o) => {
Err(error) => error!(?error, "Error in creating qt_thread") debug!("Success in creating qt_thread")
}
Err(error) => error!(
?error,
"Error in creating qt_thread"
),
} }
}); });
} }

View file

@ -54,7 +54,6 @@ impl SongBuilder {
artist_names: self.artist_names.unwrap_or_default(), artist_names: self.artist_names.unwrap_or_default(),
} }
} }
} }
pub fn search_song(s: &str) -> Result<Vec<Song>, Error> { pub fn search_song(s: &str) -> Result<Vec<Song>, Error> {
@ -103,7 +102,8 @@ mod tests {
.init(); .init();
let song = "Perfect"; let song = "Perfect";
let res = search_song(song).unwrap().into_iter().next().unwrap(); let res =
search_song(song).unwrap().into_iter().next().unwrap();
let song = Song { let song = Song {
title: String::from("Perfect"), title: String::from("Perfect"),
lyrics: String::from(""), lyrics: String::from(""),

View file

@ -27,8 +27,8 @@ mod ytdl {
use cxx_qt::{CxxQtType, Threading}; use cxx_qt::{CxxQtType, Threading};
use cxx_qt_lib::{QString, QUrl}; use cxx_qt_lib::{QString, QUrl};
use dirs; use dirs;
use tracing::debug;
use std::{fs, pin::Pin}; use std::{fs, pin::Pin};
use tracing::debug;
use youtube_dl::YoutubeDl; use youtube_dl::YoutubeDl;
#[derive(Clone, Default)] #[derive(Clone, Default)]
@ -41,10 +41,7 @@ pub struct YtdlRust {
} }
impl ytdl::Ytdl { impl ytdl::Ytdl {
pub fn get_video( pub fn get_video(mut self: Pin<&mut Self>, url: QUrl) -> bool {
mut self: Pin<&mut Self>,
url: QUrl,
) -> bool {
if !url.is_valid() { if !url.is_valid() {
false false
} else { } else {
@ -58,8 +55,7 @@ impl ytdl::Ytdl {
debug!(?data_dir); debug!(?data_dir);
self.as_mut().set_loading(true); self.as_mut().set_loading(true);
let thread = self.qt_thread(); let thread = self.qt_thread();
let runtime = let runtime = tokio::runtime::Runtime::new().unwrap();
tokio::runtime::Runtime::new().unwrap();
runtime.spawn(async move { runtime.spawn(async move {
let url = url.to_string(); let url = url.to_string();
let output_dirs = data_dir.to_str().unwrap(); let output_dirs = data_dir.to_str().unwrap();
@ -71,9 +67,11 @@ impl ytdl::Ytdl {
.download(true) .download(true)
.run() .run()
.unwrap(); .unwrap();
let output = let output = ytdl.into_single_video().unwrap();
ytdl.into_single_video().unwrap(); debug!(
debug!(output.title, output.thumbnail, output.url); output.title,
output.thumbnail, output.url
);
let title = QString::from(&output.title); let title = QString::from(&output.title);
let thumbnail = QUrl::from( let thumbnail = QUrl::from(
&output.thumbnail.unwrap_or_default(), &output.thumbnail.unwrap_or_default(),
@ -82,9 +80,7 @@ impl ytdl::Ytdl {
file.push_str("/"); file.push_str("/");
file.push_str(&output.title); file.push_str(&output.title);
file.push_str("."); file.push_str(".");
file.push_str( file.push_str(&output.ext.unwrap_or_default());
&output.ext.unwrap_or_default(),
);
debug!(file); debug!(file);
thread.queue(move |mut qobject_ytdl| { thread.queue(move |mut qobject_ytdl| {