-
Notifications
You must be signed in to change notification settings - Fork 607
Open
Description
Summary:
There is a subtle but important ID3 tagging bug in Ampache when updating tags using the VaInfo/getID3 integration. If a file's TRCK tag initially contains a value like 1/15 (track 1 of 15), Ampache's current tag writing logic can cause the /15 (totaltracks) to be lost on subsequent writes.
How to reproduce:
- Add an audio file with an ID3v2 TRCK tag of
1/15to your Ampache library. - The tag is read correctly and both
track_numberandtotaltracksare stored in the database. - Rate the track or perform any update that causes Ampache to rewrite tags.
- On the next read, the TRCK tag is now just
1-- the total track count is lost.
Root Cause:
- When updating tags, Ampache re-reads all fields from the file using getID3, which splits TRCK into
track_numberandtotaltracks. - The write logic writes only
track_numberback to TRCK, unless additional handling is added. - This causes the
/totaltracksportion to be lost on the next write (and permanently if not fixed).
Impact:
- Users lose important metadata about total track count for albums, impacting library sorting, display, and syncing.
- Any repeated tag write (such as when rating or updating a field) can cause permanent data loss for the TRCK tag.
Working Solution (Patch):
Before writing tags, ensure both track_number and totaltracks are recombined into the correct TRCK value, like so:
if (!empty($ndata['track_number'][0])) {
$track = $ndata['track_number'][0];
if (!empty($ndata['totaltracks'][0])) {
$totaltracks = $ndata['totaltracks'][0];
$ndata['track_number'] = [$track . '/' . $totaltracks];
$this->logger->debug('Writing TRCK as: ' . $track . '/' . $totaltracks . ' (from tag read values)', [LegacyLogger::CONTEXT_TYPE => self::class]);
} else {
$ndata['track_number'] = [$track];
$this->logger->debug('Writing TRCK as: ' . $track . ' (no totaltracks present)', [LegacyLogger::CONTEXT_TYPE => self::class]);
}
}Recommendation:
- Place this code immediately before
$vainfo->write_id3($ndata);in your tag writing functions. - Remove any previous attempts to split or merge TRCK elsewhere in the code to avoid conflicts.
Note; you must also undo the commit here :d28a036 to get the data to store in the first place.
Metadata
Metadata
Assignees
Labels
No labels