Skip to content

Preserve order of APIC frames relative to each other when saving. #676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

obskyr
Copy link
Contributor

@obskyr obskyr commented Apr 5, 2025

At the time of writing, Mutagen reorders APIC frames upon save without the user being able to influence the order, which causes issues with many players (including iTunes – which is Mutagen’s main compatibility target for MP4 files, though I’m not sure whether it is for ID3 tags) as discussed in issue #436. This implements the closest to a consensus reached in #436: APIC frames are stored last, and not reordered.

This pull request conflicts with #539, as both modify the ID3 sort_key function – so allow me to provide a merged version of that as well:

        def sort_key(items):
            i, (frame, data) = items

            if frame.FrameID == "APIC":
                # The order among APIC frames is preserved, as their order
                # can influence, say, what image is chosen as cover image
                # in many players.
                secondary_key = i
                frame_key = frame.HashKey
            elif frame.FrameID == "CHAP":
                # Chapters are ordered by their `start_time`, as this is
                # also significant in many players.
                secondary_key = frame.start_time
                frame_key = frame.FrameID
            else:
                secondary_key = len(data)
                frame_key = frame.HashKey

            return (get_prio(frame), secondary_key, frame_key)

@obskyr obskyr force-pushed the preserve-apic-order branch 2 times, most recently from c997dfa to ec608b9 Compare April 5, 2025 11:48
@obskyr obskyr force-pushed the preserve-apic-order branch from ec608b9 to 107bafd Compare April 5, 2025 11:48
Copy link
Collaborator

@phw phw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this. I'm very happy this will be fixed.

The code looks good and clean. I'd like to give this a short test run before merging, will do so later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants