synced top tracks with status
This commit is contained in:
@@ -435,21 +435,38 @@ pub async fn enrich_artist(
|
||||
}
|
||||
};
|
||||
|
||||
// Cross-reference with wanted items to add status
|
||||
// Cross-reference with wanted items to add status (by MBID or by name for this artist)
|
||||
let all_wanted = queries::wanted::list(state.db.conn(), None, None).await?;
|
||||
let artist_wanted: Vec<_> = all_wanted
|
||||
.iter()
|
||||
.filter(|w| id.is_some() && w.artist_id == id)
|
||||
.collect();
|
||||
|
||||
tracks
|
||||
.iter()
|
||||
.map(|t| {
|
||||
let status = t.mbid.as_deref().and_then(|track_mbid| {
|
||||
// Try matching by MBID first
|
||||
let status = t
|
||||
.mbid
|
||||
.as_deref()
|
||||
.and_then(|track_mbid| {
|
||||
all_wanted
|
||||
.iter()
|
||||
.find(|w| w.musicbrainz_id.as_deref() == Some(track_mbid))
|
||||
})
|
||||
// Fall back to matching by title (case-insensitive) within this artist's wanted items
|
||||
.or_else(|| {
|
||||
let name_lower = t.name.to_lowercase();
|
||||
artist_wanted
|
||||
.iter()
|
||||
.find(|w| w.name.to_lowercase() == name_lower)
|
||||
.copied()
|
||||
})
|
||||
.map(|w| match w.status {
|
||||
WantedStatus::Owned => "owned",
|
||||
WantedStatus::Downloaded => "downloaded",
|
||||
WantedStatus::Wanted => "wanted",
|
||||
WantedStatus::Available => "available",
|
||||
})
|
||||
});
|
||||
serde_json::json!({
|
||||
"name": t.name,
|
||||
|
||||
Reference in New Issue
Block a user