cdgriffith / puremagic

Pure python implementation of identifying files based off their magic numbers
MIT License
158 stars 34 forks source link

For Python 3.13: A drop-in replacement for `sndhdr.what()` and `sndhdr.whathdr()` #85

Open cclauss opened 2 months ago

cclauss commented 2 months ago

Like #72 but for sndhdr instead of imghdr. Given that puremagic.what() is now mentioned in What's new in Python 3.13 should we do something for the sound file formats in https://docs.python.org/3/library/sndhdr.html that will also be removed in Python 3.13? Does puremagic have support for the twelve sound file formats that sndhdr supports?

It might be quite helpful to have a drop-in replacement for sndhdr.what(). It would provide a smooth transition to Py3.13 if developers could confidently replace all instances of sndhdr.what() with puremagic.what() -- same args, same results.

@NebularNerd

NebularNerd commented 2 months ago

I feel a PR coming on 😁

sndhdr.py

sndhdr unlike imghdr seems to perform some fancier tests to test/provide better information. We can look to borrow some of this especially for #70 and #69. With the current state of PureMagic we can certainly make a good job of identifying them with decent confidence.

sndhdr support these formats:

Notes:

This is going to be a trickier PR, realistically we can at least try to ensure PureMagic can understand the files to a basic level, but the advanced tests will be reliant on how V2.0 testing logic pans out.

NebularNerd commented 1 month ago

Hi @cclauss, my PR #87 has been merged with updates for most of the missing sound formats from sndhdr. Unlike imghdr it's not a complete replacement for a few reasons mentioned in the PR. Hopefully once v2 is in progress we can look at ways to handle more esoteric formats 🙂

cclauss commented 1 month ago

Awesome! I did not see that PR. I agree that when I looked into sndhdr, I knew that making a complete replacement would be much more difficult than the relatively simple imghdr module. I see two things that should be added.

  1. A section in README.rst like https://github.com/cdgriffith/puremagic?tab=readme-ov-file#imghdr-replacement
    • Or a separate imghdr_and_sndhdr_replacements.rst file that goes into more detail like your commit messages in #87
  2. A pull request like:
    • python/cpython#120871 but focused on sndhdr.