Fix single import: prefer tag data over weak metadata/AcoustID matches
Files with embedded tags (artist+title from post-processing) were failing import because the metadata search scored low (66%) and the AcoustID result returned before the tag-preference code could run. - Tag-based identification now returns 85% confidence when embedded tags have an artist field, borrowing album art from weak metadata - AcoustID search result only accepted at 80%+ confidence, otherwise kept as fallback (doesn't short-circuit past tag preference) - AcoustID None artist/title falls back to tag data via 'or' operator - Stop retrying failed/unidentified items every scan cycle
This commit is contained in:
parent
7bad4a4fa9
commit
6d5538de74
1 changed files with 48 additions and 17 deletions
|
|
@ -486,40 +486,71 @@ class AutoImportWorker:
|
||||||
|
|
||||||
# Search metadata source for track
|
# Search metadata source for track
|
||||||
result = self._search_single_track(artist, title, album)
|
result = self._search_single_track(artist, title, album)
|
||||||
if result:
|
if result and result.get('identification_confidence', 0) >= 0.8:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# Fallback: AcoustID fingerprint
|
# Fallback: AcoustID fingerprint (also used when metadata match is weak)
|
||||||
try:
|
try:
|
||||||
from core.acoustid_client import AcoustIDClient
|
from core.acoustid_client import AcoustIDClient
|
||||||
client = AcoustIDClient()
|
client = AcoustIDClient()
|
||||||
fp_result = client.fingerprint_and_lookup(file_path)
|
fp_result = client.fingerprint_and_lookup(file_path)
|
||||||
if fp_result and fp_result.get('recordings'):
|
if fp_result and fp_result.get('recordings'):
|
||||||
best = fp_result['recordings'][0]
|
best = fp_result['recordings'][0]
|
||||||
fp_artist = best.get('artist', artist)
|
# AcoustID can return None for artist/title on new releases —
|
||||||
fp_title = best.get('title', title)
|
# fall back to tag data we already have
|
||||||
|
fp_artist = best.get('artist') or artist
|
||||||
|
fp_title = best.get('title') or title
|
||||||
if fp_artist and fp_title:
|
if fp_artist and fp_title:
|
||||||
result = self._search_single_track(fp_artist, fp_title, '')
|
fp_result2 = self._search_single_track(fp_artist, fp_title, '')
|
||||||
if result:
|
if fp_result2 and fp_result2.get('identification_confidence', 0) >= 0.8:
|
||||||
result['method'] = 'acoustid'
|
fp_result2['method'] = 'acoustid'
|
||||||
return result
|
return fp_result2
|
||||||
|
# Keep weak AcoustID result as fallback
|
||||||
|
if fp_result2 and (not result or fp_result2.get('identification_confidence', 0) > result.get('identification_confidence', 0)):
|
||||||
|
result = fp_result2
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# If we have artist and title but no metadata match, still return basic identification
|
# If we have good tag data (artist + title), prefer tag-based identification
|
||||||
if artist and title:
|
# over a weak metadata/AcoustID result — tags from post-processed files are reliable
|
||||||
return {
|
if artist and title and tags.get('artist'):
|
||||||
'album_id': None,
|
tag_conf = 0.85 # High confidence for files with proper embedded tags
|
||||||
'album_name': album or title, # Use title as album name for singles
|
# Use the metadata result's image/album data if available, but trust tag identity
|
||||||
|
tag_result = {
|
||||||
|
'album_id': result.get('album_id') if result else None,
|
||||||
|
'album_name': album or (result.get('album_name') if result else None) or title,
|
||||||
'artist_name': artist,
|
'artist_name': artist,
|
||||||
'track_name': title,
|
'track_name': title,
|
||||||
'image_url': '',
|
'image_url': result.get('image_url', '') if result else '',
|
||||||
'release_date': tags.get('year', '') or '',
|
'release_date': tags.get('year', '') or (result.get('release_date', '') if result else ''),
|
||||||
'track_number': tags.get('track_number', 1),
|
'track_number': tags.get('track_number', 1),
|
||||||
|
'total_tracks': result.get('total_tracks', 1) if result else 1,
|
||||||
|
'source': result.get('source', 'tags') if result else 'tags',
|
||||||
|
'method': 'tags',
|
||||||
|
'identification_confidence': tag_conf,
|
||||||
|
'is_single': True,
|
||||||
|
'track_id': result.get('track_id', '') if result else '',
|
||||||
|
}
|
||||||
|
return tag_result
|
||||||
|
|
||||||
|
# If AcoustID didn't help but we had a weak metadata match, use it
|
||||||
|
if result:
|
||||||
|
return result
|
||||||
|
|
||||||
|
# Last resort: filename-only identification
|
||||||
|
if title:
|
||||||
|
return {
|
||||||
|
'album_id': None,
|
||||||
|
'album_name': title,
|
||||||
|
'artist_name': artist or 'Unknown Artist',
|
||||||
|
'track_name': title,
|
||||||
|
'image_url': '',
|
||||||
|
'release_date': '',
|
||||||
|
'track_number': 1,
|
||||||
'total_tracks': 1,
|
'total_tracks': 1,
|
||||||
'source': 'tags',
|
'source': 'tags',
|
||||||
'method': 'tags' if tags.get('artist') else 'filename',
|
'method': 'filename',
|
||||||
'identification_confidence': 0.7 if tags.get('artist') else 0.5,
|
'identification_confidence': 0.5,
|
||||||
'is_single': True,
|
'is_single': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue