This commit is contained in:
JMARyA 2024-10-07 09:27:49 +02:00
parent 224bdf77ab
commit 31a5271e6e
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
2 changed files with 12 additions and 1 deletions

View file

@ -173,8 +173,10 @@ impl Library {
let lib = self.get_video_paths(dir).await; let lib = self.get_video_paths(dir).await;
for path in lib { for path in lib {
if !Video::has_path(&path.display().to_string()).await {
Video::insert_path_to_db(&path).await; Video::insert_path_to_db(&path).await;
} }
}
log::info!("Finished scanning {dir:?}"); log::info!("Finished scanning {dir:?}");
} }

View file

@ -67,6 +67,15 @@ impl Video {
.unwrap() .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<Self> { pub async fn insert_path_to_db(v: &PathBuf) -> Option<Self> {
let db = get_pg!(); let db = get_pg!();