Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 05756d95cc |
+28
-4
@@ -1,4 +1,4 @@
|
||||
use sea_orm::{ActiveValue::NotSet, ActiveValue::Set, DatabaseConnection};
|
||||
use sea_orm::{ActiveModelTrait, ActiveValue::NotSet, ActiveValue::Set, DatabaseConnection};
|
||||
use shanty_data::{MetadataFetcher as MetadataProvider, RecordingDetails, ReleaseRef};
|
||||
use shanty_db::entities::track;
|
||||
use shanty_db::queries;
|
||||
@@ -78,6 +78,22 @@ pub async fn tag_track(
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
// If the resolved MBID differs from the track's original MBID, update the wanted_item
|
||||
// so the cleanup step doesn't delete files whose MBID changed during tagging
|
||||
if let Some(ref old_mbid) = track.musicbrainz_id
|
||||
&& old_mbid != &details.mbid
|
||||
&& let Ok(Some(wanted)) = queries::wanted::find_by_mbid(conn, old_mbid).await
|
||||
{
|
||||
let mut active: shanty_db::entities::wanted_item::ActiveModel = wanted.into();
|
||||
active.musicbrainz_id = Set(Some(details.mbid.clone()));
|
||||
let _ = active.update(conn).await;
|
||||
tracing::info!(
|
||||
old_mbid = %old_mbid,
|
||||
new_mbid = %details.mbid,
|
||||
"updated wanted_item MBID after tagger fallback"
|
||||
);
|
||||
}
|
||||
|
||||
// Use existing artist_id if already set (e.g., from download pipeline).
|
||||
// Only upsert from MB when the track has no artist association yet.
|
||||
let artist_id = if track.artist_id.is_some() {
|
||||
@@ -121,14 +137,22 @@ pub async fn tag_track(
|
||||
|
||||
let genre = details.genres.first().cloned();
|
||||
|
||||
// Update track metadata
|
||||
// Update track metadata — preserve artist name when artist_id was already set
|
||||
let artist_name_for_track = if track.artist_id.is_some() {
|
||||
track
|
||||
.artist
|
||||
.clone()
|
||||
.or_else(|| Some(details.artist.clone()))
|
||||
} else {
|
||||
Some(details.artist.clone())
|
||||
};
|
||||
let active = track::ActiveModel {
|
||||
id: Set(track.id),
|
||||
file_path: Set(track.file_path.clone()),
|
||||
title: Set(Some(details.title.clone())),
|
||||
artist: Set(Some(details.artist.clone())),
|
||||
artist: Set(artist_name_for_track.clone()),
|
||||
album: Set(album_name),
|
||||
album_artist: Set(Some(details.artist.clone())),
|
||||
album_artist: Set(artist_name_for_track),
|
||||
musicbrainz_id: Set(Some(details.mbid.clone())),
|
||||
artist_id: Set(artist_id),
|
||||
album_id: Set(album_id),
|
||||
|
||||
Reference in New Issue
Block a user