Compare commits
1 Commits
5786cc89e5
...
7d2d6f021d
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d2d6f021d |
+28
-9
@@ -416,27 +416,38 @@ async fn process_tag(
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
// Ensure a wanted_item exists for this track (marks imported files as Owned)
|
// Ensure a wanted_item exists for this track (marks imported files as Owned).
|
||||||
// Check by MBID first, then by name+artist to avoid duplicates from MBID mismatches
|
// Check by MBID first, then by name+artist to avoid duplicates from MBID mismatches.
|
||||||
let has_wanted = if let Some(ref mbid) = track.musicbrainz_id {
|
// When found, link the wanted_item to this track via track_id so cleanup never
|
||||||
|
// deletes it (track_id is a direct link that can't break from MBID mismatches).
|
||||||
|
let found_wanted = if let Some(ref mbid) = track.musicbrainz_id {
|
||||||
queries::wanted::find_by_mbid(conn, mbid)
|
queries::wanted::find_by_mbid(conn, mbid)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?
|
.map_err(|e| e.to_string())?
|
||||||
.is_some()
|
|
||||||
} else {
|
} else {
|
||||||
false
|
None
|
||||||
};
|
};
|
||||||
let has_wanted = has_wanted || {
|
let found_wanted = if found_wanted.is_some() {
|
||||||
|
found_wanted
|
||||||
|
} else {
|
||||||
// Also check by name + artist_id (normalize unicode dashes and case)
|
// Also check by name + artist_id (normalize unicode dashes and case)
|
||||||
let all_wanted = queries::wanted::list(conn, None, None)
|
let all_wanted = queries::wanted::list(conn, None, None)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let title_norm = normalize_for_match(track.title.as_deref().unwrap_or(""));
|
let title_norm = normalize_for_match(track.title.as_deref().unwrap_or(""));
|
||||||
all_wanted
|
all_wanted
|
||||||
.iter()
|
.into_iter()
|
||||||
.any(|w| w.artist_id == track.artist_id && normalize_for_match(&w.name) == title_norm)
|
.find(|w| w.artist_id == track.artist_id && normalize_for_match(&w.name) == title_norm)
|
||||||
};
|
};
|
||||||
if !has_wanted {
|
|
||||||
|
// Link the wanted_item to this track so get_unwanted() won't delete it
|
||||||
|
if let Some(ref wanted) = found_wanted {
|
||||||
|
if wanted.track_id != Some(track.id) {
|
||||||
|
let _ = queries::wanted::update_track_id(conn, wanted.id, track.id).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if found_wanted.is_none() {
|
||||||
let item = queries::wanted::add(
|
let item = queries::wanted::add(
|
||||||
conn,
|
conn,
|
||||||
queries::wanted::AddWantedItem {
|
queries::wanted::AddWantedItem {
|
||||||
@@ -511,6 +522,14 @@ async fn trigger_pipeline_completion(state: &web::Data<AppState>, pipeline_id: &
|
|||||||
Ok(unwanted) if !unwanted.is_empty() => {
|
Ok(unwanted) if !unwanted.is_empty() => {
|
||||||
let count = unwanted.len();
|
let count = unwanted.len();
|
||||||
for track in &unwanted {
|
for track in &unwanted {
|
||||||
|
tracing::info!(
|
||||||
|
id = track.id,
|
||||||
|
path = %track.file_path,
|
||||||
|
artist = ?track.artist,
|
||||||
|
title = ?track.title,
|
||||||
|
mbid = ?track.musicbrainz_id,
|
||||||
|
"deleting unwanted track"
|
||||||
|
);
|
||||||
let path = std::path::Path::new(&track.file_path);
|
let path = std::path::Path::new(&track.file_path);
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
if let Err(e) = std::fs::remove_file(path) {
|
if let Err(e) = std::fs::remove_file(path) {
|
||||||
|
|||||||
Reference in New Issue
Block a user