Skip to content
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

Allow passing encoding to EasyID3.RegisterTXXXKey #263

gdelfresno opened this issue Jul 10, 2016 · 1 comment

Allow passing encoding to EasyID3.RegisterTXXXKey #263

gdelfresno opened this issue Jul 10, 2016 · 1 comment


Copy link

@gdelfresno gdelfresno commented Jul 10, 2016


Now the default encoding when you register a custom text field in EasyID3 is Latin1, except if the value you set for the first time requires UTF8.

This leads to an error when you first set the field with a non UTF8 value and then later you want to update the field with a UTF8 value. This is because the frame was added with latin1 encoding at the first time.

I guess there could be reasons to keep the current way working, but I think that developers should be able to specify the encoding of the new frame.

I think passing an optional parameter to the method should be enough to achieve that. If no encoding is passed old way will be used.

I already implemented it an it would be ready to push if you want.

Thats how the method will look:

    def RegisterTXXXKey(cls, key, desc, enc=None):
        """Register a user-defined text frame key.

        Some ID3 tags are stored in TXXX frames, which allow a
        freeform 'description' which acts as a subkey,
        e.g. TXXX:BARCODE.::

            EasyID3.RegisterTXXXKey('barcode', 'BARCODE').
        frameid = "TXXX:" + desc
        encoding = enc

        def getter(id3, key):
            return list(id3[frameid])

        def setter(id3, key, value):
                frame = id3[frameid]
            except KeyError:
                if not encoding:
                    _enc = 0
                    # Store 8859-1 if we can, per MusicBrainz spec.
                    for v in value:
                        if v and max(v) > u'\x7f':
                            _enc = 3
                    _enc = encoding

                id3.add(mutagen.id3.TXXX(encoding=_enc, text=value, desc=desc))
                frame.text = value

        def deleter(id3, key):

        cls.RegisterKey(key, getter, setter, deleter)

Regards and thanks for your great work.

@lazka lazka added the bug label Jul 11, 2016

This comment has been minimized.

Copy link

@lazka lazka commented Jul 11, 2016


@lazka lazka closed this in 7e49872 Jul 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.