@@ -12,7 +12,6 @@ use walkdir::WalkDir;
1212use crate :: prisma_main_client:: { directory, file} ;
1313use crate :: utils:: app:: AppState ;
1414use crate :: utils:: audio_utils:: get_audio_metadata;
15- use crate :: utils:: extractor_music:: extractor_music;
1615
1716#[ tauri:: command]
1817pub async fn create_directory (
@@ -209,130 +208,6 @@ pub async fn open_in_finder(path: String) {
209208 }
210209}
211210
212- #[ tauri:: command]
213- pub async fn analyze_file (
214- app_handle : & tauri:: AppHandle ,
215- path_dir : String ,
216- ) -> Result < Value , std:: io:: Error > {
217- let mut output_path = app_handle. path_resolver ( ) . app_data_dir ( ) . unwrap ( ) ;
218- output_path. push ( "extractor_music.temp.json" ) ;
219-
220- extractor_music ( path_dir, output_path. to_string_lossy ( ) . to_string ( ) ) . await
221- }
222-
223- #[ derive( Clone , serde:: Serialize ) ]
224- struct Payload {
225- processing : bool ,
226- file : Option < String > ,
227- }
228-
229- #[ tauri:: command]
230- pub async fn analyze_directory (
231- app_handle : tauri:: AppHandle ,
232- path_dir : String ,
233- state : tauri:: State < ' _ , AppState > ,
234- ) -> Result < ( ) , String > {
235- directory:: include!( ( filter: Vec <file:: WhereParam >) => directory_files {
236- files( filter)
237- } ) ;
238-
239- let directory = state
240- . prisma_client
241- . directory ( )
242- . find_unique ( directory:: path:: equals ( path_dir. clone ( ) ) )
243- . include ( directory_files:: include ( vec ! [ file:: analyzed:: equals(
244- false ,
245- ) ] ) )
246- . exec ( )
247- . await
248- . unwrap ( ) ;
249-
250- match directory {
251- Some ( directory_data) => {
252- let files_unanalized = directory_data. files ;
253-
254- let mut files_unanalized_iter = files_unanalized. into_iter ( ) ;
255-
256- let break_loop_flag = Arc :: new ( AtomicBool :: new ( false ) ) ;
257- let break_loop_flag_clone = Arc :: clone ( & break_loop_flag) ;
258-
259- app_handle. once_global ( "stop-analyze-directory-files" . to_string ( ) , move |_| {
260- break_loop_flag_clone. store ( true , Ordering :: SeqCst ) ;
261- } ) ;
262-
263- while !break_loop_flag. load ( Ordering :: SeqCst ) {
264- if let Some ( file_unanalyzed) = files_unanalized_iter. next ( ) {
265- let file_name = file_unanalyzed. name ;
266-
267- app_handle
268- . emit_all (
269- "analyze-directory-files" ,
270- Payload {
271- processing : true ,
272- file : Some ( file_name. clone ( ) ) ,
273- } ,
274- )
275- . unwrap ( ) ;
276-
277- match analyze_file ( & app_handle, file_unanalyzed. path . clone ( ) ) . await {
278- Ok ( output) => {
279- match state
280- . prisma_client
281- . file ( )
282- . update (
283- file:: path:: equals ( file_unanalyzed. path . to_string ( ) ) ,
284- vec ! [
285- file:: bpm:: set( Some ( output[ "rhythm" ] [ "bpm" ] . as_f64( ) . unwrap( ) ) ) ,
286- file:: danceability:: set( Some (
287- output[ "rhythm" ] [ "danceability" ] . as_f64( ) . unwrap( ) ,
288- ) ) ,
289- file:: chords_key:: set( Some (
290- output[ "tonal" ] [ "chords_key" ] . as_str( ) . unwrap( ) . to_owned( ) ,
291- ) ) ,
292- file:: chords_scale:: set( Some (
293- output[ "tonal" ] [ "chords_scale" ] . as_str( ) . unwrap( ) . to_owned( ) ,
294- ) ) ,
295- file:: analyzed:: set( true ) ,
296- ] ,
297- )
298- . exec ( )
299- . await
300- {
301- Ok ( _) => { }
302- Err ( error) => {
303- return Err ( format ! (
304- "Error update file '{}': {}" ,
305- file_name,
306- error. to_string( )
307- ) )
308- }
309- }
310- }
311- Err ( error) => return Err ( format ! ( "Erreur : {:?}" , error) ) ,
312- }
313- } else {
314- break ;
315- }
316- }
317-
318- app_handle
319- . emit_all (
320- "analyze-directory-files" ,
321- Payload {
322- processing : false ,
323- file : None ,
324- } ,
325- )
326- . unwrap ( ) ;
327-
328- Ok ( ( ) )
329- }
330- None => {
331- return Err ( format ! ( "Error analyze file '{}'" , path_dir) ) ;
332- }
333- }
334- }
335-
336211#[ tauri:: command]
337212pub async fn scan_directory (
338213 app_handle : tauri:: AppHandle ,
0 commit comments