extract.py (1663B)
1 #!/usr/bin/env python 2 """extract.py 3 4 This file is part of libextractor. 5 (C) 2002, 2003, 2004, 2005 Vidyut Samanta and Christian Grothoff 6 (C) 2017 Nikita Gillmann <nikita@n0.is> 7 8 libextractor is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published 10 by the Free Software Foundation; either version 3, or (at your 11 option) any later version. 12 13 libextractor is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with libextractor; see the file COPYING. If not, write to the 20 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 Boston, MA 02111-1307, USA. 22 23 Little demo how to use the libextractor Python binding. 24 25 """ 26 from __future__ import print_function 27 from libextractor import extractor 28 import sys 29 from ctypes import * 30 import struct 31 32 xtract = extractor.Extractor() 33 34 35 def print_k(xt, plugin, type, format, mime, data, datalen): 36 mstr = cast(data, c_char_p) 37 # FIXME: this ignores 'datalen', not that great... 38 # (in general, depending on the mime type and format, only 39 # the first 'datalen' bytes in 'data' should be used). 40 if (format == extractor.EXTRACTOR_METAFORMAT_UTF8): 41 print("%s - %s" % (xtract.keywordTypes()[type], mstr.value)) 42 return 0 43 44 45 for arg in sys.argv[1:]: 46 print("Keywords from %s:" % arg) 47 xtract.extract(print_k, None, arg)