update
This commit is contained in:
parent
952129d454
commit
8c2b0cfdf1
5 changed files with 168 additions and 29 deletions
|
@ -56,6 +56,7 @@ impl Libary {
|
|||
if let Some(_) = Track::find_one_partial(doc! { "path": path }, json!({})).await {
|
||||
return;
|
||||
}
|
||||
log::info!("Adding {path} to library");
|
||||
|
||||
// add track to library
|
||||
let metadata = metadata::get_metadata(path);
|
||||
|
@ -72,6 +73,8 @@ impl Libary {
|
|||
.as_object_mut()
|
||||
.unwrap()
|
||||
.insert("artist_id".into(), artist_id.into());
|
||||
} else {
|
||||
log::warn!("{path} has no artist");
|
||||
}
|
||||
|
||||
if let Some(album) = meta.album() {
|
||||
|
@ -89,6 +92,8 @@ impl Libary {
|
|||
.as_object_mut()
|
||||
.unwrap()
|
||||
.insert("album_id".into(), album_id.into());
|
||||
} else {
|
||||
log::warn!("{path} has no album and will be treated as single");
|
||||
}
|
||||
|
||||
if let Some(title) = meta.title() {
|
||||
|
@ -156,17 +161,15 @@ impl Libary {
|
|||
}
|
||||
|
||||
pub async fn rescan(&self) {
|
||||
log::info!("Rescanning library");
|
||||
for entry in WalkDir::new(self.root_dir.clone())
|
||||
.follow_links(true)
|
||||
.into_iter()
|
||||
.take(30) // todo : remove
|
||||
.into_iter() // todo : remove
|
||||
.filter_map(|e| e.ok())
|
||||
{
|
||||
let path = entry.path();
|
||||
if path.is_file() && is_music_file(path) {
|
||||
let path = path.to_string_lossy().to_string();
|
||||
|
||||
println!("Found {path}");
|
||||
self.add_path_to_library(&path).await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ use mongod::{
|
|||
derive::{Model, Referencable},
|
||||
Model, Referencable, Reference, Validate,
|
||||
};
|
||||
use mongodb::bson::doc;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
|
||||
|
@ -62,6 +63,14 @@ impl Track {
|
|||
|
||||
transcoded
|
||||
}
|
||||
|
||||
/// Find tracks with no album or artist
|
||||
pub async fn get_orphans() -> Vec<Track> {
|
||||
Self::find(doc! {
|
||||
"artist_id": None::<String>,
|
||||
"album_id": None::<String>
|
||||
}, None).await.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAPI for Track {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue