diff --git a/database/music_database.py b/database/music_database.py index 03936c14..023177c0 100644 --- a/database/music_database.py +++ b/database/music_database.py @@ -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: diff --git a/web_server.py b/web_server.py index 922fc9e5..a18f7e8b 100644 --- a/web_server.py +++ b/web_server.py @@ -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