Question

I'm using python-extractor to work with libextractor3. I can not find any examples of it. Does any one have any documentations or examples?

Was it helpful?

Solution

Source package of python-extractor contains a file named extract.py which has a small demo on how to use libextractor Python binding.

Content from extract.py

import extractor
import sys
from ctypes import *
import struct

xtract = extractor.Extractor()

def print_k(xt, plugin, type, format, mime, data, datalen):
    mstr = cast (data, c_char_p)
# FIXME: this ignores 'datalen', not that great...
# (in general, depending on the mime type and format, only
# the first 'datalen' bytes in 'data' should be used).
    if (format == extractor.EXTRACTOR_METAFORMAT_UTF8):
        print "%s - %s" % (xtract.keywordTypes()[type],  mstr.value)
    return 0


for arg in sys.argv[1:]:
    print "Keywords from %s:" % arg
    xtract.extract(print_k, None, arg)

To have better understanding of python-extractor go through source code in extractor.py.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top