clippy-fix

This commit is contained in:
Chris Cochrun 2024-06-25 23:04:30 -05:00
parent 3f2f57f8e7
commit cbf5fe3d9d
14 changed files with 166 additions and 184 deletions

View file

@ -13,7 +13,7 @@ pub fn bg_from_video(
) -> Result<(), Box<dyn Error>> {
if !screenshot.exists() {
let output_duration = Command::new("ffprobe")
.args(&["-i", &video.to_string_lossy()])
.args(["-i", &video.to_string_lossy()])
.output()
.expect("failed to execute ffprobe");
io::stderr().write_all(&output_duration.stderr).unwrap();
@ -49,7 +49,7 @@ pub fn bg_from_video(
debug!(hours, minutes, seconds, at_second);
}
let _output = Command::new("ffmpeg")
.args(&[
.args([
"-i",
&video.to_string_lossy(),
"-ss",
@ -103,7 +103,7 @@ mod test {
let result = bg_from_video(video, &screenshot);
// let result = runtime.block_on(future);
match result {
Ok(o) => assert_eq!(screenshot.exists(), true),
Ok(_o) => assert!(screenshot.exists()),
Err(e) => debug_assert!(
false,
"There was an error in the runtime future. {:?}",

View file

@ -39,7 +39,7 @@ mod qobject {
use cxx_qt_lib::{QString, QUrl};
use rfd::FileDialog;
use std::{path::Path, pin::Pin};
use tracing::{debug, debug_span, error, info, instrument};
use tracing::{debug, error};
#[derive(Clone)]
pub struct FileHelperRust {

View file

@ -155,7 +155,7 @@ mod qobject {
}
use crate::schema::images::dsl::*;
use cxx_qt::{CxxQtType, Threading};
use cxx_qt::{CxxQtType};
use cxx_qt_lib::{QModelIndex, QString, QUrl, QVariant};
use diesel::sqlite::SqliteConnection;
use diesel::{delete, insert_into, prelude::*, update};
@ -428,7 +428,7 @@ impl qobject::ImageModel {
}
let role_names = self.as_ref().role_names();
let role_names_iter = role_names.iter();
if let Some(image) = self.rust().images.get(index as usize) {
if let Some(_image) = self.rust().images.get(index as usize) {
for i in role_names_iter {
qvariantmap.insert(
QString::from(&i.1.to_string()),

View file

@ -3,13 +3,14 @@ use cxx_qt::CxxQtType;
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::qobject::QList_QString;
#[derive(Default)]
pub struct Obs {
scenes: Scenes,
client: Option<Client>,
@ -35,15 +36,7 @@ impl Clone for Obs {
}
}
impl Default for Obs {
fn default() -> Self {
Self {
scenes: Scenes::default(),
client: None,
current_program_scene: None,
}
}
}
impl Obs {
pub async fn new() -> Result<Self, Box<dyn Error>> {
@ -68,7 +61,7 @@ impl Obs {
.iter()
.map(|x| x.name.clone())
.collect::<Vec<String>>();
if scenes.len() > 0 {
if !scenes.is_empty() {
Ok(scenes)
} else {
Err(format!("Scenes found: {}", scenes.len()))?
@ -80,19 +73,19 @@ impl Obs {
scene: String,
) -> Result<(), Box<dyn Error>> {
// debug!("Starting function");
if let Some(client) = &self.client {
if let Some(_client) = &self.client {
debug!(scene, "setting scene in 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;
match res {
Ok(o) => {
Ok(_o) => {
debug!("in spawn: after setting: success")
}
Err(e) => error!(?e, "in spawn: after setting"),
@ -118,8 +111,8 @@ impl Obs {
fn make_client() -> Client {
let runtime = tokio::runtime::Runtime::new().unwrap();
let future = Client::connect("localhost", 4455, Some(""));
let client = runtime.block_on(future).unwrap();
client
runtime.block_on(future).unwrap()
}
#[cxx_qt::bridge]

View file

@ -472,7 +472,7 @@ impl qobject::PresentationModel {
index: i32,
) -> bool {
let binding = self.as_mut();
let pres = binding.presentations.get(index as usize).clone();
let pres = binding.presentations.get(index as usize);
if let Some(item) = pres {
let item = item.clone();
binding.add_presentation(item);
@ -636,8 +636,8 @@ impl qobject::PresentationModel {
}
pub fn row_count(&self, _parent: &QModelIndex) -> i32 {
let cnt = self.presentations.len() as i32;
// println!("row count is {cnt}");
cnt
self.presentations.len() as i32
}
}

View file

@ -298,7 +298,6 @@ use cxx_qt_lib::{
};
use dirs;
use serde_json::{json, Value};
use std::io::{Read, Write};
use std::iter;
use std::path::{Path, PathBuf};
use std::pin::Pin;
@ -397,7 +396,7 @@ impl Default for ServiceItemModelRust {
}
impl qobject::ServiceItemModel {
pub fn setup(mut self: Pin<&mut Self>) {
pub fn setup(self: Pin<&mut Self>) {
todo!()
}
@ -414,7 +413,7 @@ impl qobject::ServiceItemModel {
pub fn remove_items(mut self: Pin<&mut Self>) {
let mut indices = vec![];
let mut items = self.service_items.clone();
for (index, item) in items.iter_mut().enumerate().filter(|(y, x)| x.selected) {
for (index, _item) in items.iter_mut().enumerate().filter(|(_y, x)| x.selected) {
let index = index as i32;
indices.push(index);
}
@ -434,7 +433,7 @@ impl qobject::ServiceItemModel {
self.as_mut().end_remove_rows();
}
let item = self.as_mut().get_item(*index);
self.as_mut().item_removed(&index, &item);
self.as_mut().item_removed(index, &item);
}
}
@ -567,7 +566,7 @@ impl qobject::ServiceItemModel {
}
let rn = self.as_ref().role_names();
let rn_iter = rn.iter();
if let Some(service_item) =
if let Some(_service_item) =
self.service_items.get(index as usize)
{
for i in rn_iter {
@ -705,7 +704,7 @@ impl qobject::ServiceItemModel {
.as_ref()
.service_items
.iter()
.position(|i| i.selected == true)
.position(|i| i.selected)
{
// Here we will need to branch to get the selected items
debug!(first_item = ?current_index);
@ -829,7 +828,7 @@ impl qobject::ServiceItemModel {
// println!("service_item is deactivating {:?}", i);
service_item.active = false;
}
let obs = self.as_mut().obs.clone();
let _obs = self.as_mut().obs.clone();
if let Some(service_item) = self
.as_mut()
@ -919,7 +918,7 @@ impl qobject::ServiceItemModel {
s.insert_str(0, "temp_");
temp_dir.push(s);
match fs::create_dir_all(&temp_dir) {
Ok(f) => {
Ok(_f) => {
println!("created_temp_dir: {:?}", &temp_dir)
}
Err(e) => println!("temp-dir-error: {e}"),
@ -928,8 +927,8 @@ impl qobject::ServiceItemModel {
temp_service_file.push("serviceitems.json");
self.as_mut().save_progress_updated(10);
let mut service_json: Vec<Value> = vec![];
let progress_fraction = items.len() as f32 / 100 as f32;
for (id, item) in items.iter().enumerate() {
let progress_fraction = items.len() as f32 / 100_f32;
for (_id, item) in items.iter().enumerate() {
let text_list = QList_QString::from(&item.text);
let mut text_vec = Vec::<String>::default();
@ -942,7 +941,7 @@ impl qobject::ServiceItemModel {
);
println!("bg_path: {:?}", background_path);
let flat_background_name =
background_path.file_name().clone();
background_path.file_name();
let flat_background;
match flat_background_name {
Some(name) => {
@ -975,7 +974,7 @@ impl qobject::ServiceItemModel {
println!("audio: {:?}", &name);
if name.to_str().unwrap() != "temp" {
flat_audio =
name.to_str().unwrap().clone()
name.to_str().unwrap()
} else {
flat_audio = "";
}
@ -1055,7 +1054,7 @@ impl qobject::ServiceItemModel {
service_file,
&service_json,
) {
Ok(e) => {
Ok(_e) => {
debug!(time = ?now.elapsed(), "file written");
std::thread::spawn(move || {
debug!(time = ?now.elapsed(), "idk");
@ -1138,8 +1137,8 @@ impl qobject::ServiceItemModel {
datadir.push("lumina");
datadir.push("temp");
println!("datadir: {:?}", datadir);
fs::remove_dir_all(&datadir);
fs::create_dir_all(&datadir);
let _ = fs::remove_dir_all(&datadir);
let _ = fs::create_dir_all(&datadir);
if let Ok(lf) = &lfr {
println!("archive: {:?}", lf);
@ -1154,14 +1153,17 @@ impl qobject::ServiceItemModel {
println!("filename: {:?}", file.path().unwrap());
println!("size: {:?}", file.size());
if !file_path.exists() {
file.unpack_in(&datadir);
match file.unpack_in(&datadir) {
Ok(t) => (),
Err(e) => error!("Error unpacking archive: {}", e),
}
}
}
// older save files use servicelist.json instead of serviceitems.json
// Let's check to see if that's the case and change it's name in the
// temp dir.
for mut file in
for file in
fs::read_dir(datadir.clone()).unwrap().filter(|f| {
f.as_ref()
.map(|e| {
@ -1176,7 +1178,7 @@ impl qobject::ServiceItemModel {
let mut service_path = datadir.clone();
service_path.push("serviceitems.json");
match fs::rename(file.unwrap().path(), service_path) {
Ok(i) => println!("We did it captain"),
Ok(_i) => println!("We did it captain"),
Err(e) => println!("error: {:?}", e),
}
}
@ -1186,7 +1188,7 @@ impl qobject::ServiceItemModel {
// let mut service_list =
// fs::File::open(service_path).unwrap();
let mut s = fs::read_to_string(service_path).unwrap();
let s = fs::read_to_string(service_path).unwrap();
// service_list.read_to_string(&mut s);
let ds: Value = serde_json::from_str(&s).unwrap();
for obj in ds.as_array().unwrap() {
@ -1208,7 +1210,7 @@ impl qobject::ServiceItemModel {
// it exists on disk, if not use the flat version
let audio_string =
obj.get("audio").unwrap().as_str().unwrap();
let mut audio;
let audio;
println!("audio_on_disk: {audio_string}");
if !Path::new(&audio_string).exists() {
@ -1242,7 +1244,7 @@ impl qobject::ServiceItemModel {
let bgstr =
obj.get("background").unwrap().as_str().unwrap();
let mut background;
let background;
println!("background_on_disk: {bgstr}");
let bgpath =
bgstr.strip_prefix("file://").unwrap_or("");
@ -1350,7 +1352,7 @@ impl qobject::ServiceItemModel {
}
}
pub fn load_last_saved(mut self: Pin<&mut Self>) -> bool {
pub fn load_last_saved(self: Pin<&mut Self>) -> bool {
todo!();
// Don't actually need
}
@ -1505,14 +1507,14 @@ impl qobject::ServiceItemModel {
}
pub fn row_count(&self, _parent: &QModelIndex) -> i32 {
let cnt = self.service_items.len() as i32;
// println!("row count is {cnt}");
cnt
self.service_items.len() as i32
}
}
impl ServiceItemModelRust {
pub fn save(mut model: Pin<&mut ServiceItemModel>, file: QUrl) -> bool {
pub fn save(_model: Pin<&mut ServiceItemModel>, _file: QUrl) -> bool {
todo!()
}
}

View file

@ -30,7 +30,7 @@ use configparser::ini::Ini;
use cxx_qt::CxxQtType;
use cxx_qt_lib::{QString, QUrl};
use dirs;
use std::{path::PathBuf, pin::Pin};
use std::{pin::Pin};
// In order for settings to save to the ini file,
// I'll need to create my own setting functions I think.
@ -68,7 +68,7 @@ impl qobject::Settings {
conf.push("lumina");
conf.push("lumina.conf");
match self.as_mut().rust_mut().config.load(conf) {
Ok(map) => {
Ok(_map) => {
// println!("{:?}", self.rust().config);
let sf = self
.as_ref()
@ -100,7 +100,7 @@ impl qobject::Settings {
"lastSaveFile",
Some(file.to_string()),
) {
Some(s) => {
Some(_s) => {
println!(
"set-save-file: {:?}",
self.as_mut()

View file

@ -221,7 +221,7 @@ use cxx_qt_lib::{
};
use std::thread;
use std::{path::PathBuf, pin::Pin};
use tracing::{debug, debug_span, error, info, instrument};
use tracing::{debug, error};
use self::qobject::{
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
@ -355,7 +355,7 @@ impl qobject::SlideModel {
)
});
match result {
Ok(o) => {
Ok(_o) => {
debug!("Success in creating qt_thread")
}
Err(error) => error!(
@ -448,7 +448,7 @@ impl qobject::SlideModel {
slide: &Slide,
index: i32,
) {
let mut slide = slide.clone();
let slide = slide.clone();
// slide.slide_index = index;
debug!(?slide);
@ -695,7 +695,7 @@ impl qobject::SlideModel {
let mut slide = Slide::default();
let iter = service_item.iter();
for (key, value) in iter {
for (key, _value) in iter {
debug!(?key);
// match key.to_string().as_str() {
// "ty" => slide.ty = QString::from(value),
@ -910,9 +910,7 @@ impl qobject::SlideModel {
if let Some((i, slide)) = slides_iter
.clone()
.enumerate()
.filter(|slide| slide.1.service_item_id == source_index)
.next()
.enumerate().find(|slide| slide.1.service_item_id == source_index)
{
debug!(index = i, ?slide);
first_slide = i as i32;
@ -929,10 +927,9 @@ impl qobject::SlideModel {
.clone()
.enumerate()
.rev()
.filter(|slide| {
.find(|slide| {
slide.1.service_item_id == destination_index
})
.next()
{
dest_slide = i as i32;
dest_count = if slide.slide_count == 0 {
@ -945,22 +942,19 @@ impl qobject::SlideModel {
dest_slide, dest_count
);
}
} else {
if let Some((i, slide)) = slides_iter
.enumerate()
.filter(|slide| {
slide.1.service_item_id == destination_index
})
.next()
{
dest_slide = i as i32;
dest_count = if slide.slide_count == 0 {
1
} else {
slide.slide_count
};
debug!("RUST_dest_slide: {:?}", dest_slide);
} else if let Some((i, slide)) = slides_iter
.enumerate()
.find(|slide| {
slide.1.service_item_id == destination_index
})
{
dest_slide = i as i32;
dest_count = if slide.slide_count == 0 {
1
} else {
slide.slide_count
};
debug!("RUST_dest_slide: {:?}", dest_slide);
}
debug!(count, first_slide, dest_slide);
@ -978,7 +972,7 @@ impl qobject::SlideModel {
// self.as_mut().begin_reset_model();
// }
let rc = self.as_ref().count() - 1;
let _rc = self.as_ref().count() - 1;
let tl = &self.as_ref().index(
first_slide,
0,
@ -998,7 +992,7 @@ impl qobject::SlideModel {
if count > 1 {
if move_down {
debug!("While moving down, change service items id of moved slide");
for (i, slide) in slides_iter
for (i, _slide) in slides_iter
.clone()
.enumerate()
.filter(|x| {
@ -1022,7 +1016,7 @@ impl qobject::SlideModel {
}
} else {
debug!("While moving up, change service items id of moved slide");
for (i, slide) in slides_iter
for (i, _slide) in slides_iter
.clone()
.enumerate()
.filter(|x| x.0 >= dest_slide as usize)
@ -1040,27 +1034,25 @@ impl qobject::SlideModel {
}
}
}
} else {
if let Some(slide) = self
.as_mut()
.rust_mut()
.slides
.get_mut(dest_slide as usize)
{
debug!(
internal_slide_index = slide.slide_index,
service_item = slide.service_item_id,
destination_index,
"This is the slide who's service item needs changed"
);
slide.service_item_id = destination_index;
}
} else if let Some(slide) = self
.as_mut()
.rust_mut()
.slides
.get_mut(dest_slide as usize)
{
debug!(
internal_slide_index = slide.slide_index,
service_item = slide.service_item_id,
destination_index,
"This is the slide who's service item needs changed"
);
slide.service_item_id = destination_index;
}
// Change the service_item_id of the shifted slides, not the moved service_item
if move_down {
debug!("While moving down, change service item id");
for (i, slide) in slides_iter
for (i, _slide) in slides_iter
.clone()
.enumerate()
.filter(|x| x.1.service_item_id <= destination_index)
@ -1081,7 +1073,7 @@ impl qobject::SlideModel {
}
} else {
debug!("While moving up, change service item id");
for (i, slide) in slides_iter
for (i, _slide) in slides_iter
.clone()
.enumerate()
.filter(|x| x.0 >= (dest_slide + count) as usize)
@ -1173,7 +1165,7 @@ impl qobject::SlideModel {
}
let rn = self.as_ref().role_names();
let rn_iter = rn.iter();
if let Some(slide) = self.rust().slides.get(index as usize) {
if let Some(_slide) = self.rust().slides.get(index as usize) {
for i in rn_iter {
qvariantmap.insert(
QString::from(&i.1.to_string()),
@ -1193,9 +1185,7 @@ impl qobject::SlideModel {
debug!(service_item = index, "Getting slide from this item");
let mut id = 0;
if let Some((i, slide)) = slides_iter
.enumerate()
.filter(|(i, slide)| slide.service_item_id == index)
.next()
.enumerate().find(|(_i, slide)| slide.service_item_id == index)
{
debug!(slide_id = i, ?slide);
id = i as i32;
@ -1425,7 +1415,7 @@ impl qobject::SlideModel {
#[cfg(test)]
mod test {
use super::*;
#[test]
pub fn test_obs_setting_scene() {

View file

@ -145,11 +145,11 @@ impl qobject::SlideObject {
item: QMap_QString_QVariant,
slide_index: i32,
) {
let current_index = self.as_ref().get_ref().slide_index();
let _current_index = self.as_ref().get_ref().slide_index();
let icount_variant = item
.get(&QString::from("imageCount"))
.unwrap_or(QVariant::from(&1));
let count = icount_variant.value::<i32>().unwrap_or_default();
let _count = icount_variant.value::<i32>().unwrap_or_default();
let slindex = item
.get(&QString::from("slideIndex"))
@ -434,7 +434,7 @@ impl qobject::SlideObject {
false
}
pub fn play_pause(mut self: Pin<&mut Self>) -> bool {
let playing = self.as_ref().is_playing().clone();
let playing = *self.as_ref().is_playing();
match playing {
true => self.as_mut().set_is_playing(false),
false => self.as_mut().set_is_playing(true),

View file

@ -49,7 +49,7 @@ pub mod qobject {
// use crate::songs::song_model::qobject::SongModel;
use cxx_qt_lib::QString;
use std::{path::PathBuf, pin::Pin};
use tracing::{debug, debug_span, error, info, instrument};
use tracing::{debug};
#[derive(Clone, Debug)]
pub struct SongEditorRust {
@ -95,7 +95,7 @@ impl Default for SongEditorRust {
}
impl qobject::SongEditor {
fn idk(mut self: Pin<&mut Self>) {
fn idk(self: Pin<&mut Self>) {
// if let Some(model) = unsafe { self.song_model().as_mut() } {
// let pinned_model = unsafe { Pin::new_unchecked(model) };
// pinned_model.update_ccli(0, QString::from("idk"));
@ -105,10 +105,10 @@ impl qobject::SongEditor {
pub fn check_verse_order(mut self: Pin<&mut Self>) {
let vo = self.verse_order().to_string();
let split = vo.split(" ");
let split = vo.split(' ');
debug!(verse_order = ?vo, iterator = ?split);
for s in split {
if s.contains(",") || s.is_empty() {
if s.contains(',') || s.is_empty() {
self.as_mut().set_verse_order_error(true);
} else {
self.as_mut().set_verse_order_error(false);

View file

@ -249,7 +249,7 @@ use diesel::sqlite::SqliteConnection;
use diesel::{delete, insert_into, prelude::*, update};
use std::collections::HashMap;
use std::pin::Pin;
use tracing::{debug, debug_span, error, info, instrument};
use tracing::{debug, error};
use self::qobject::{
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
@ -465,7 +465,7 @@ impl qobject::SongModel {
}
fn get_indices(
mut self: Pin<&mut Self>,
self: Pin<&mut Self>,
song_id: i32,
role: SongRoles,
) -> (usize, QModelIndex, QVector_i32) {
@ -955,7 +955,7 @@ impl qobject::SongModel {
}
pub fn get_lyric_list(
mut self: Pin<&mut Self>,
self: Pin<&mut Self>,
index: i32,
) -> QStringList {
println!("LYRIC_LIST: {index}");
@ -980,12 +980,12 @@ impl qobject::SongModel {
"Intro 1", "Intro 2", "Ending 1", "Ending 2",
"Other 1", "Other 2", "Other 3", "Other 4",
];
let mut first_item = true;
let _first_item = true;
let mut lyric_map = HashMap::new();
let mut verse_title = String::from("");
let mut lyric = String::from("");
for (i, line) in raw_lyrics.split("\n").enumerate() {
for (i, line) in raw_lyrics.split('\n').enumerate() {
if keywords.contains(&line) {
if i != 0 {
// println!("{verse_title}");
@ -1002,13 +1002,13 @@ impl qobject::SongModel {
}
} else {
lyric.push_str(line);
lyric.push_str("\n");
lyric.push('\n');
}
}
lyric_map.insert(verse_title, lyric);
// println!("da-map: {:?}", lyric_map);
for mut verse in vorder {
for verse in vorder {
let mut verse_name = "";
// debug!(verse = verse);
for word in keywords.clone() {
@ -1033,7 +1033,7 @@ impl qobject::SongModel {
let split_lyrics: Vec<&str> =
lyric.split("\n\n").collect();
for lyric in split_lyrics {
if lyric == "" {
if lyric.is_empty() {
continue;
}
lyric_list.append(QString::from(lyric));

View file

@ -1,10 +1,9 @@
use std::pin::Pin;
use time::macros::format_description;
use tokio::runtime::Runtime;
use tracing::{debug, info, instrument::WithSubscriber};
use tracing::{debug, info};
use tracing_subscriber::{
fmt::{self, time::LocalTime},
EnvFilter,
};
@ -13,7 +12,7 @@ use self::qobject::{QString, QUrl};
mod db {
use diesel::{Connection, SqliteConnection};
use dirs::data_local_dir;
use sqlx::{Connection as SqlxConnection, Error};
pub enum Model {
Songs,
@ -97,15 +96,15 @@ impl qobject::Utils {
crate::utils::setup();
}
pub fn dbg(self: &Self, message: QString) {
pub fn dbg(&self, message: QString) {
debug!(msg = ?message);
}
pub fn inf(self: &Self, message: QString) {
pub fn inf(&self, message: QString) {
info!(msg = ?message);
}
pub fn url_to_string(self: &Self, url: QUrl) -> QString {
pub fn url_to_string(&self, url: QUrl) -> QString {
url.path()
}
}

View file

@ -176,13 +176,13 @@ mod qobject {
}
}
use crate::models::*;
use crate::schema::videos::dsl::*;
use cxx_qt::CxxQtType;
use cxx_qt_lib::{QByteArray, QModelIndex, QString, QUrl, QVariant};
use diesel::sqlite::SqliteConnection;
use diesel::{delete, insert_into, prelude::*, update};
use std::path::{Path, PathBuf};
use std::path::{PathBuf};
use std::pin::Pin;
use self::qobject::{
@ -438,7 +438,7 @@ impl qobject::VideoModel {
.iter_mut()
.filter(|x| x.id == index)
{
video.looping = loop_value.clone();
video.looping = loop_value;
println!("rust-video: {:?}", video.title);
}
self.as_mut().data_changed(
@ -477,7 +477,7 @@ impl qobject::VideoModel {
.iter_mut()
.filter(|x| x.id == index)
{
video.end_time = updated_end_time.clone();
video.end_time = updated_end_time;
}
self.as_mut().data_changed(
model_index,
@ -515,7 +515,7 @@ impl qobject::VideoModel {
.iter_mut()
.filter(|x| x.id == index)
{
video.start_time = updated_start_time.clone();
video.start_time = updated_start_time;
}
self.as_mut().data_changed(
model_index,

View file

@ -44,61 +44,59 @@ impl qobject::Ytdl {
pub fn get_video(mut self: Pin<&mut Self>, url: QUrl) -> bool {
if !url.is_valid() {
false
} else {
if let Some(mut data_dir) = dirs::data_local_dir() {
data_dir.push("lumina");
data_dir.push("ytdl");
if !data_dir.exists() {
fs::create_dir(&data_dir)
.expect("Could not create ytdl dir");
}
debug!(?data_dir);
self.as_mut().set_loading(true);
let thread = self.qt_thread();
let runtime = tokio::runtime::Runtime::new().unwrap();
runtime.spawn(async move {
let url = url.to_string();
let output_dirs = data_dir.to_str().unwrap();
debug!(output_dirs);
let ytdl = YoutubeDl::new(url)
.socket_timeout("15")
.output_directory(output_dirs)
.output_template("%(title)s.%(ext)s")
.download(true)
.run()
.unwrap();
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(),
);
let mut file = String::from(output_dirs);
file.push_str("/");
file.push_str(&output.title);
file.push_str(".");
file.push_str(&output.ext.unwrap_or_default());
debug!(file);
thread.queue(move |mut qobject_ytdl| {
qobject_ytdl.as_mut().set_loaded(true);
qobject_ytdl.as_mut().set_loading(false);
qobject_ytdl.as_mut().set_title(title);
qobject_ytdl
.as_mut()
.set_thumbnail(thumbnail);
qobject_ytdl
.as_mut()
.set_file(QUrl::from(&file));
})
});
true
} else {
false
} else if let Some(mut data_dir) = dirs::data_local_dir() {
data_dir.push("lumina");
data_dir.push("ytdl");
if !data_dir.exists() {
fs::create_dir(&data_dir)
.expect("Could not create ytdl dir");
}
debug!(?data_dir);
self.as_mut().set_loading(true);
let thread = self.qt_thread();
let runtime = tokio::runtime::Runtime::new().unwrap();
runtime.spawn(async move {
let url = url.to_string();
let output_dirs = data_dir.to_str().unwrap();
debug!(output_dirs);
let ytdl = YoutubeDl::new(url)
.socket_timeout("15")
.output_directory(output_dirs)
.output_template("%(title)s.%(ext)s")
.download(true)
.run()
.unwrap();
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(),
);
let mut file = String::from(output_dirs);
file.push('/');
file.push_str(&output.title);
file.push('.');
file.push_str(&output.ext.unwrap_or_default());
debug!(file);
thread.queue(move |mut qobject_ytdl| {
qobject_ytdl.as_mut().set_loaded(true);
qobject_ytdl.as_mut().set_loading(false);
qobject_ytdl.as_mut().set_title(title);
qobject_ytdl
.as_mut()
.set_thumbnail(thumbnail);
qobject_ytdl
.as_mut()
.set_file(QUrl::from(&file));
})
});
true
} else {
false
}
}