MCPcopy Create free account
hub / github.com/Moosync/Moosync / start_scan_inner

Function start_scan_inner

src-tauri/src/scanner/mod.rs:88–148  ·  view source on GitHub ↗
(app: AppHandle, mut paths: Option<Vec<String>>)

Source from the content-addressed store, hash-verified

86
87#[cfg(desktop)]
88pub fn start_scan_inner(app: AppHandle, mut paths: Option<Vec<String>>) -> Result<()> {
89 let preferences = app.state::<PreferenceConfig>();
90 if paths.is_none() {
91 paths = Some(get_scan_paths(&preferences)?);
92 }
93
94 let thumbnail_dir: String = preferences.load_selective("thumbnail_path".to_string())?;
95 tracing::debug!("Got thumbnail dir {:?}", thumbnail_dir);
96
97 let artist_split: String = preferences
98 .load_selective("artist_splitter".to_string())
99 .unwrap_or(";".to_string());
100
101 let scan_threads: f64 = preferences
102 .load_selective("scan_threads".to_string())
103 .unwrap_or(-1f64);
104
105 for path in paths.unwrap() {
106 tracing::info!("Scanning path: {}", path);
107
108 let (playlist_tx, playlist_rx) = channel();
109 let (song_tx, song_rx) = channel::<(Option<String>, Vec<Song>)>();
110
111 let app_clone = app.clone();
112 thread::spawn(move || {
113 let app = app_clone;
114 let database = app.state::<Database>();
115 for item in playlist_rx {
116 for playlist in item {
117 let _ = database.create_playlist(playlist);
118 }
119 }
120
121 for (playlist_id, songs) in song_rx {
122 let res = database.insert_songs(songs);
123 if let Ok(res) = res {
124 if let Some(playlist_id) = playlist_id.as_ref() {
125 for song in res {
126 if let Some(song_id) = song.song._id {
127 let _ =
128 database.add_to_playlist_bridge(playlist_id.clone(), song_id);
129 }
130 }
131 }
132 }
133 }
134 });
135
136 let scanner = app.state::<ScannerHolder>();
137 scanner.start_scan(
138 path,
139 thumbnail_dir.clone(),
140 artist_split.clone(),
141 scan_threads,
142 song_tx,
143 playlist_tx,
144 )?;
145 }

Callers 1

start_scanFunction · 0.85

Calls 9

get_scan_pathsFunction · 0.85
load_selectiveMethod · 0.80
cloneMethod · 0.80
create_playlistMethod · 0.80
insert_songsMethod · 0.80
file_scannerMethod · 0.80
scan_musicMethod · 0.80
start_scanMethod · 0.45

Tested by

no test coverage detected