Skip to content

Commit

Permalink
fix: remove binary extractor music
Browse files Browse the repository at this point in the history
  • Loading branch information
vincehi committed Jun 10, 2024
1 parent 15dc58f commit 6fdcd85
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 163 deletions.
125 changes: 0 additions & 125 deletions src-tauri/src/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use walkdir::WalkDir;
use crate::prisma_main_client::{directory, file};
use crate::utils::app::AppState;
use crate::utils::audio_utils::get_audio_metadata;
use crate::utils::extractor_music::extractor_music;

#[tauri::command]
pub async fn create_directory(
Expand Down Expand Up @@ -209,130 +208,6 @@ pub async fn open_in_finder(path: String) {
}
}

#[tauri::command]
pub async fn analyze_file(
app_handle: &tauri::AppHandle,
path_dir: String,
) -> Result<Value, std::io::Error> {
let mut output_path = app_handle.path_resolver().app_data_dir().unwrap();
output_path.push("extractor_music.temp.json");

extractor_music(path_dir, output_path.to_string_lossy().to_string()).await
}

#[derive(Clone, serde::Serialize)]
struct Payload {
processing: bool,
file: Option<String>,
}

#[tauri::command]
pub async fn analyze_directory(
app_handle: tauri::AppHandle,
path_dir: String,
state: tauri::State<'_, AppState>,
) -> Result<(), String> {
directory::include!((filter: Vec<file::WhereParam>) => directory_files {
files(filter)
});

let directory = state
.prisma_client
.directory()
.find_unique(directory::path::equals(path_dir.clone()))
.include(directory_files::include(vec![file::analyzed::equals(
false,
)]))
.exec()
.await
.unwrap();

match directory {
Some(directory_data) => {
let files_unanalized = directory_data.files;

let mut files_unanalized_iter = files_unanalized.into_iter();

let break_loop_flag = Arc::new(AtomicBool::new(false));
let break_loop_flag_clone = Arc::clone(&break_loop_flag);

app_handle.once_global("stop-analyze-directory-files".to_string(), move |_| {
break_loop_flag_clone.store(true, Ordering::SeqCst);
});

while !break_loop_flag.load(Ordering::SeqCst) {
if let Some(file_unanalyzed) = files_unanalized_iter.next() {
let file_name = file_unanalyzed.name;

app_handle
.emit_all(
"analyze-directory-files",
Payload {
processing: true,
file: Some(file_name.clone()),
},
)
.unwrap();

match analyze_file(&app_handle, file_unanalyzed.path.clone()).await {
Ok(output) => {
match state
.prisma_client
.file()
.update(
file::path::equals(file_unanalyzed.path.to_string()),
vec![
file::bpm::set(Some(output["rhythm"]["bpm"].as_f64().unwrap())),
file::danceability::set(Some(
output["rhythm"]["danceability"].as_f64().unwrap(),
)),
file::chords_key::set(Some(
output["tonal"]["chords_key"].as_str().unwrap().to_owned(),
)),
file::chords_scale::set(Some(
output["tonal"]["chords_scale"].as_str().unwrap().to_owned(),
)),
file::analyzed::set(true),
],
)
.exec()
.await
{
Ok(_) => {}
Err(error) => {
return Err(format!(
"Error update file '{}': {}",
file_name,
error.to_string()
))
}
}
}
Err(error) => return Err(format!("Erreur : {:?}", error)),
}
} else {
break;
}
}

app_handle
.emit_all(
"analyze-directory-files",
Payload {
processing: false,
file: None,
},
)
.unwrap();

Ok(())
}
None => {
return Err(format!("Error analyze file '{}'", path_dir));
}
}
}

#[tauri::command]
pub async fn scan_directory(
app_handle: tauri::AppHandle,
Expand Down
26 changes: 0 additions & 26 deletions src-tauri/src/utils/extractor_music.rs

This file was deleted.

1 change: 0 additions & 1 deletion src-tauri/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod app;
pub mod audio_utils;
pub mod extractor_music;
12 changes: 1 addition & 11 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,10 @@
},
"package": {
"productName": "pulp",
"version": "1.2.0"
"version": "1.1.1"
},
"tauri": {
"allowlist": {
"shell": {
"sidecar": true,
"scope": [
{
"name": "binaries/streaming_extractor_music",
"sidecar": true
}
]
},
"all": true,
"fs": {
"all": true,
Expand Down Expand Up @@ -52,7 +43,6 @@
"deb": {
"depends": []
},
"externalBin": ["binaries/streaming_extractor_music"],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
Expand Down

0 comments on commit 6fdcd85

Please sign in to comment.