I am writing a script to determine if a file is a valid MP3 using python-magic
. With some files, the magic.from_file()
function returns use count (30) exceeded
. Is it possible to raise the limit similar to the command line program: file --parameter name=40
? If this is not possible with python-magic
, is it possible with filemagic
?
Asked
Active
Viewed 445 times
-1
1 Answers
1
After navigating my way through ctypes, I found a solution:
import magic
MAGIC_PARAM_NAME_MAX = 1 # definition from magic.h
name_max = magic.c_void_p(40) # new use count, can also be c_size_t
name_max_ref = magic.ctypes.byref(name_max)
s = magic.Magic()
magic.libmagic.magic_setparam(s.cookie, MAGIC_PARAM_NAME_MAX, name_max_ref)
print s.from_file('file.jpg')

mrtasktat
- 323
- 1
- 4
- 12
-
For some reason this did not work for me. Python exited with a segmentation fault. I am new to python so any help is greatly appreciated. I am using Python 3.x and using the latest magic library from python – Shiven Jan 06 '17 at 17:52