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
?
问问题
407 次
1 回答
1
在浏览 ctypes 之后,我找到了一个解决方案:
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')
于 2015-04-20T02:04:23.667 回答