rustfmt things
This commit is contained in:
parent
f2faa0564a
commit
9d9ecb3cc0
6 changed files with 75 additions and 60 deletions
|
@ -16,4 +16,3 @@ pub mod utils;
|
|||
pub mod video_model;
|
||||
pub mod ytdl;
|
||||
// mod video_thumbnail;
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use core::fmt;
|
||||
use std::{error::Error, pin::Pin};
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
use cxx_qt::CxxQtType;
|
||||
use cxx_qt_lib::{QStringList, QString};
|
||||
use cxx_qt_lib::{QString, QStringList};
|
||||
use obws::responses::scenes::Scenes;
|
||||
use obws::Client;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
use std::{error::Error, pin::Pin};
|
||||
use tracing::{debug, error};
|
||||
|
||||
use crate::obs::obs_model::QList_QString;
|
||||
|
@ -13,7 +13,7 @@ use crate::obs::obs_model::QList_QString;
|
|||
pub struct Obs {
|
||||
scenes: Scenes,
|
||||
client: Option<Client>,
|
||||
current_program_scene: Option<String>
|
||||
current_program_scene: Option<String>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Obs {
|
||||
|
@ -30,7 +30,7 @@ impl Clone for Obs {
|
|||
Self {
|
||||
scenes: self.scenes.clone(),
|
||||
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 {
|
||||
scenes: Scenes::default(),
|
||||
client: None,
|
||||
current_program_scene: None
|
||||
current_program_scene: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,12 +51,13 @@ impl Obs {
|
|||
Client::connect("localhost", 4455, Some("")).await?;
|
||||
let scenes_object = client.scenes();
|
||||
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);
|
||||
Ok(Self {
|
||||
scenes: scene_list,
|
||||
client: Some(client),
|
||||
current_program_scene: Some(current_program_scene)
|
||||
current_program_scene: Some(current_program_scene),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -84,12 +85,17 @@ impl Obs {
|
|||
|
||||
let client = make_client();
|
||||
let runtime = tokio::runtime::Runtime::new()?;
|
||||
let handle = runtime.spawn(async move {
|
||||
let handle = runtime.spawn(async move {
|
||||
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 {
|
||||
Ok(o) => debug!("in spawn: after setting: success"),
|
||||
Err(e) => error!(?e, "in spawn: after setting")
|
||||
Ok(o) => {
|
||||
debug!("in spawn: after setting: success")
|
||||
}
|
||||
Err(e) => error!(?e, "in spawn: after setting"),
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -151,13 +157,11 @@ pub struct ObsModelRust {
|
|||
port: QString,
|
||||
connected: bool,
|
||||
obs: Option<Obs>,
|
||||
current_program_scene: QString
|
||||
current_program_scene: QString,
|
||||
}
|
||||
|
||||
impl obs_model::ObsModel {
|
||||
pub fn update_scenes(
|
||||
mut self: Pin<&mut Self>,
|
||||
) -> QStringList {
|
||||
pub fn update_scenes(mut self: Pin<&mut Self>) -> QStringList {
|
||||
debug!("updating scenes");
|
||||
let mut scenes_list = QList_QString::default();
|
||||
if let Some(obs) = &self.as_mut().rust_mut().obs {
|
||||
|
@ -184,7 +188,8 @@ impl obs_model::ObsModel {
|
|||
Ok(o) => {
|
||||
if let Some(scene) = &o.current_program_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().rust_mut().obs = Some(o);
|
||||
|
@ -226,7 +231,9 @@ mod test {
|
|||
let future = Client::connect("localhost", 4455, Some(""));
|
||||
let client = runtime.block_on(future).unwrap();
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -285,24 +285,22 @@ use cxx_qt_lib::{
|
|||
QByteArray, QModelIndex, QString, QStringList, QUrl, QVariant,
|
||||
};
|
||||
use dirs;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Deserializer, Map, Serializer, Value};
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::io::{self, Read, Write};
|
||||
use serde_json::{json, Value};
|
||||
use std::io::{Read, Write};
|
||||
use std::iter;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::pin::Pin;
|
||||
use std::str;
|
||||
use std::{fs, println};
|
||||
use tar::{Archive, Builder};
|
||||
use tracing::{debug, debug_span, error, info, instrument};
|
||||
use tracing::{debug, error};
|
||||
use zstd::{Decoder, Encoder};
|
||||
|
||||
use self::service_item_model::{
|
||||
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
|
||||
ServiceRoles,
|
||||
};
|
||||
|
||||
use super::service_item_model::service_item_model::ServiceItemModel;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ServiceItem {
|
||||
name: QString,
|
||||
|
|
|
@ -287,7 +287,6 @@ pub struct SlideModelRust {
|
|||
count: i32,
|
||||
}
|
||||
|
||||
|
||||
impl Default for SlideModelRust {
|
||||
fn default() -> Self {
|
||||
let obs =
|
||||
|
@ -319,7 +318,10 @@ impl slide_model::SlideModel {
|
|||
.append(self.get_role(SlideRoles::VideoThumbnail));
|
||||
|
||||
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) =
|
||||
self.as_mut().rust_mut().slides.get_mut(index as usize)
|
||||
{
|
||||
|
@ -327,26 +329,39 @@ impl slide_model::SlideModel {
|
|||
let path =
|
||||
PathBuf::from(slide.video_background.to_string());
|
||||
let screenshot = ffmpeg::bg_path_from_video(&path);
|
||||
let screenshot_string = QString::from(
|
||||
screenshot.to_str().unwrap()
|
||||
).insert(0, &QString::from("file://")).to_owned();
|
||||
let screenshot_string =
|
||||
QString::from(screenshot.to_str().unwrap())
|
||||
.insert(0, &QString::from("file://"))
|
||||
.to_owned();
|
||||
slide.video_thumbnail = screenshot_string;
|
||||
std::thread::spawn(move || {
|
||||
let result = ffmpeg::bg_from_video(&path, &screenshot);
|
||||
let result =
|
||||
ffmpeg::bg_from_video(&path, &screenshot);
|
||||
match result {
|
||||
Ok(_o) => debug!("Success making video background!"),
|
||||
Err(error) => error!(?error, "Error making video background")
|
||||
Ok(_o) => {
|
||||
debug!("Success making video background!")
|
||||
}
|
||||
Err(error) => error!(
|
||||
?error,
|
||||
"Error making video background"
|
||||
),
|
||||
};
|
||||
let result = thread.queue(move |mut slide_model|
|
||||
slide_model.as_mut().data_changed(
|
||||
&model_index,
|
||||
&model_index,
|
||||
&vector_roles,
|
||||
)
|
||||
);
|
||||
let result =
|
||||
thread.queue(move |mut slide_model| {
|
||||
slide_model.as_mut().data_changed(
|
||||
&model_index,
|
||||
&model_index,
|
||||
&vector_roles,
|
||||
)
|
||||
});
|
||||
match result {
|
||||
Ok(o) => debug!("Success in creating qt_thread"),
|
||||
Err(error) => error!(?error, "Error in creating qt_thread")
|
||||
Ok(o) => {
|
||||
debug!("Success in creating qt_thread")
|
||||
}
|
||||
Err(error) => error!(
|
||||
?error,
|
||||
"Error in creating qt_thread"
|
||||
),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -54,7 +54,6 @@ impl SongBuilder {
|
|||
artist_names: self.artist_names.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn search_song(s: &str) -> Result<Vec<Song>, Error> {
|
||||
|
@ -103,7 +102,8 @@ mod tests {
|
|||
.init();
|
||||
|
||||
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 {
|
||||
title: String::from("Perfect"),
|
||||
lyrics: String::from(""),
|
||||
|
|
|
@ -27,8 +27,8 @@ mod ytdl {
|
|||
use cxx_qt::{CxxQtType, Threading};
|
||||
use cxx_qt_lib::{QString, QUrl};
|
||||
use dirs;
|
||||
use tracing::debug;
|
||||
use std::{fs, pin::Pin};
|
||||
use tracing::debug;
|
||||
use youtube_dl::YoutubeDl;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
|
@ -41,10 +41,7 @@ pub struct YtdlRust {
|
|||
}
|
||||
|
||||
impl ytdl::Ytdl {
|
||||
pub fn get_video(
|
||||
mut self: Pin<&mut Self>,
|
||||
url: QUrl,
|
||||
) -> bool {
|
||||
pub fn get_video(mut self: Pin<&mut Self>, url: QUrl) -> bool {
|
||||
if !url.is_valid() {
|
||||
false
|
||||
} else {
|
||||
|
@ -58,8 +55,7 @@ impl ytdl::Ytdl {
|
|||
debug!(?data_dir);
|
||||
self.as_mut().set_loading(true);
|
||||
let thread = self.qt_thread();
|
||||
let runtime =
|
||||
tokio::runtime::Runtime::new().unwrap();
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
runtime.spawn(async move {
|
||||
let url = url.to_string();
|
||||
let output_dirs = data_dir.to_str().unwrap();
|
||||
|
@ -71,9 +67,11 @@ impl ytdl::Ytdl {
|
|||
.download(true)
|
||||
.run()
|
||||
.unwrap();
|
||||
let output =
|
||||
ytdl.into_single_video().unwrap();
|
||||
debug!(output.title, output.thumbnail, output.url);
|
||||
let output = ytdl.into_single_video().unwrap();
|
||||
debug!(
|
||||
output.title,
|
||||
output.thumbnail, output.url
|
||||
);
|
||||
let title = QString::from(&output.title);
|
||||
let thumbnail = QUrl::from(
|
||||
&output.thumbnail.unwrap_or_default(),
|
||||
|
@ -82,9 +80,7 @@ impl ytdl::Ytdl {
|
|||
file.push_str("/");
|
||||
file.push_str(&output.title);
|
||||
file.push_str(".");
|
||||
file.push_str(
|
||||
&output.ext.unwrap_or_default(),
|
||||
);
|
||||
file.push_str(&output.ext.unwrap_or_default());
|
||||
debug!(file);
|
||||
|
||||
thread.queue(move |mut qobject_ytdl| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue