diff --git a/src/library/mod.rs b/src/library/mod.rs index 1024fb1..1448cf0 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -173,7 +173,9 @@ impl Library { let lib = self.get_video_paths(dir).await; for path in lib { - Video::insert_path_to_db(&path).await; + if !Video::has_path(&path.display().to_string()).await { + Video::insert_path_to_db(&path).await; + } } log::info!("Finished scanning {dir:?}"); diff --git a/src/library/video.rs b/src/library/video.rs index 8476aef..f8357b3 100644 --- a/src/library/video.rs +++ b/src/library/video.rs @@ -67,6 +67,15 @@ impl Video { .unwrap() } + pub async fn has_path(path: &str) -> bool { + sqlx::query("SELECT id FROM videos WHERE path = $1") + .bind(path) + .fetch_optional(get_pg!()) + .await + .unwrap() + .is_some() + } + pub async fn insert_path_to_db(v: &PathBuf) -> Option { let db = get_pg!();