Preserve track provenance through lossy transcoding (#245)

- Update provenance file_path when Blasphemy Mode deletes the original
  FLAC and replaces it with a lossy copy — provenance now points to
  the transcoded file instead of the deleted original
- New update_provenance_file_path() database method
- Non-blocking: wrapped in try/except, never interrupts transcode flow
- Downsample (hi-res → CD quality) is unaffected — replaces in-place
  with same filename, provenance stays valid
This commit is contained in:
Broque Thomas 2026-04-02 15:14:27 -07:00
parent c67ca40b08
commit c7d6cc21e8
2 changed files with 20 additions and 0 deletions

View file

@ -8667,6 +8667,20 @@ class MusicDatabase:
logger.error(f"Error getting track downloads: {e}")
return []
def update_provenance_file_path(self, old_path: str, new_path: str) -> bool:
"""Update file_path in provenance records when a file is transcoded/moved."""
try:
conn = self._get_connection()
cursor = conn.cursor()
cursor.execute("""
UPDATE track_downloads SET file_path = ? WHERE file_path = ?
""", (new_path, old_path))
conn.commit()
return cursor.rowcount > 0
except Exception as e:
logger.error(f"Error updating provenance file path: {e}")
return False
def get_download_by_file_path(self, file_path: str) -> Optional[dict]:
"""Find the most recent download record for a file path."""
try:

View file

@ -16520,6 +16520,12 @@ def _create_lossy_copy(final_path):
from mutagen import File as MutagenFile
test_audio = MutagenFile(out_path)
if test_audio is not None:
# Update provenance record to point to the new transcoded file
try:
db = get_database()
db.update_provenance_file_path(final_path, out_path)
except Exception:
pass
os.remove(final_path)
print(f"🔥 [Blasphemy Mode] Deleted original: {os.path.basename(final_path)}")
# Rename lyrics sidecar file to match the output filename