-
Notifications
You must be signed in to change notification settings - Fork 26
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
Replace deprecated imghdr
package with filetype
#75
Conversation
mediafile.py
Outdated
|
||
|
||
def image_extension(data): | ||
ext = _imghdr_what_wrapper(data) | ||
ext = filetype.guess_extension(data) | ||
return PREFERRED_IMAGE_EXTENSIONS.get(ext, ext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is PREFERRED_IMAGE_EXTENSIONS
still needed? filetype
already returns jpg
for JPEG files:
$ python3 -c 'import filetype; print(filetype.guess("./only-magic-bytes.jpg").extension)'
jpg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You’re right! Good catch
The `imghdr` package from the Python standard library is [deprecated and will be removed in Python 3.13][1]. The deprecated PEP suggests packages filetype, puremagic, python-magic as replacements. I chose filetype because it has a [larger user-base][2] than puremagic and does not have a C dependency, like python-magic. [1]: https://peps.python.org/pep-0594/#deprecated-modules [2]: https://libraries.io/pypi/filetype
ed852fc
to
49da972
Compare
It seems like there are quite a few changes to the return values of
The majority of unrecognized types are ones that are less likely to be used, but it seems like the file extension for |
For those looking to run beets in python3.13, the following command is a good workaround until this gets merged:
|
This has been patched in Fedora 41.
|
I've added a change to preserve the
I think this is good enough - the only mismatch is |
Thanks @geigerzaehler! |
The
imghdr
package from the Python standard library is deprecated and will be removed in Python 3.13. The deprecated PEP suggests packages filetype, puremagic, python-magic as replacements. I chose filetype because it has a larger user-base than puremagic and does not have a C dependency, like python-magic.