Skip to content

Delete the SYLT frame by its HashKey - #112

Open
stefanvanburen wants to merge 1 commit into
beetbox:masterfrom
stefanvanburen:sylt-delete
Open

stefanvanburen wants to merge 1 commit into
beetbox:masterfrom
stefanvanburen:sylt-delete

Conversation

@stefanvanburen

Copy link
Copy Markdown

synced_lyrics can be written but not deleted. Mutagen stores the SYLT frame under the HashKey SYLT::XXX, while MP3SYLTStorageStyle inherits a delete() that looks for a bare SYLT key, so it never matches and the deletion is a silent no-op.

Repro

from mediafile import MediaFile
import mutagen.id3

mf = MediaFile("x.mp3")
mf.synced_lyrics = [("hello", 1000)]
mf.save()

mf = MediaFile("x.mp3")
del mf.synced_lyrics                      # or mf.update({"synced_lyrics": None})
mf.save()

mutagen.id3.ID3("x.mp3").getall("SYLT")   # still there

MediaFile.update() is affected too, since it calls delattr for any key whose value is None — so its documented "if a key has the value None, the corresponding property is deleted" doesn't hold for this field.

Why it was missed

The class already gets this right in store(), which clears with delall("SYLT"); only the delete path was missing. Assignment-clearing (mf.synced_lyrics = None) routes through store(), which is why the existing test_clear passes and this went unnoticed.

Sibling styles whose frames carry a non-bare HashKey all override delete for the same reason — MP3DescStorageStyle (USLT) deletes via frame.HashKey, and MP3ImageStorageStyle (APIC) uses delall.

Fix

Three lines, mirroring MP3ImageStorageStyle:

def delete(self, mutagen_file):
    mutagen_file.tags.delall("SYLT")

Tests

Four added to TestSyncedLyrics, all of which fail without the fix and pass with it:

  • test_delete[mp3], test_delete[aiff] — del removes the frame
  • test_update_with_none_clears — update({"synced_lyrics": None}) removes it
  • test_delete_leaves_plain_lyrics — deleting SYLT doesn't disturb USLT

Full suite is 491 passed, 1 failed: OpusTest::test_read_audio_properties, which fails identically on unmodified master (#109). ruff check and ruff format --check are clean.

How I hit it

Turning on beets' lyrics.synced and then turning it back off. USLT reverts, but every MP3 keeps a stale SYLT frame that beets has no way to remove.

Mutagen stores SYLT under the HashKey "SYLT::XXX", but
MP3SYLTStorageStyle inherited a delete() that looked for a bare "SYLT"
key, so it never matched. Deleting the field was a silent no-op:

    mf = MediaFile("x.mp3")           # has a SYLT frame
    del mf.synced_lyrics              # or update({"synced_lyrics": None})
    mf.save()                         # SYLT::XXX still present

The class already had this right in store(), which clears with
delall("SYLT"); only the delete path was missing. Every sibling style
whose frames carry a non-bare HashKey overrides delete for the same
reason -- MP3DescStorageStyle deletes via frame.HashKey, and
MP3ImageStorageStyle uses delall.

Assignment-clearing (mf.synced_lyrics = None) went through store() and
so already worked, which is why the existing test_clear passed.
stefanvanburen added a commit to stefanvanburen/dotfiles that referenced this pull request Sep 8, 2026
LRClib serves timestamped lyrics, but beets writes the LRC text
*including* timestamps into the ordinary `lyrics` field and only passes
the parsed timing to SYLT on top. SYLT is an mp3-only MediaField, and
none of the players here read it: Cog exposes only `unsyncedlyrics`,
Swinsian keeps a single plain `lyrics TEXT` column, Music.app hands back
the raw timestamped string, and VLC and IINA have no lyrics UI at all.
So turning it on only prefixes every line with "[00:20.53] ".

It is also close to a one-way door, since beets can write SYLT but not
delete it (beetbox/mediafile#112). Record all of that next to the two
options rather than rediscovering it.

This branch has not been deployed

No deployments
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.

1 participant