문제

I'd like to be able to read in the first couple kilobytes of unknown file types and see if it matches any known file types (i.e. mp3 file, jpeg, etc...). I was thinking of trying to load meta data from files from libraries like PIL, sndhdr, py264, etc... and see if they picked up any valid formats but I thought this must have been a problem someone has solved before.

Is there one library or a gist showing the usage of multiple libraries which would do this?

도움이 되었습니까?

해결책

Use python-magic to do the fingerprinting.

The library can determine file type from bytes data only:

import magic
magic.from_buffer(start_data_from_something)

The library provides access to the libmagic file type identification library, which also drives the UNIX file command.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top