diff options
Diffstat (limited to 'libmat/strippers.py')
| -rw-r--r-- | libmat/strippers.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/libmat/strippers.py b/libmat/strippers.py new file mode 100644 index 0000000..aea98da --- /dev/null +++ b/libmat/strippers.py | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | ''' Manage which fileformat can be processed | ||
| 2 | ''' | ||
| 3 | |||
| 4 | import archive | ||
| 5 | import audio | ||
| 6 | import gi | ||
| 7 | import images | ||
| 8 | import logging | ||
| 9 | import mat | ||
| 10 | import misc | ||
| 11 | import office | ||
| 12 | import subprocess | ||
| 13 | |||
| 14 | STRIPPERS = { | ||
| 15 | 'application/x-tar': archive.TarStripper, | ||
| 16 | 'application/x-bzip2': archive.Bzip2Stripper, | ||
| 17 | 'application/x-gzip': archive.GzipStripper, | ||
| 18 | 'application/zip': archive.ZipStripper, | ||
| 19 | 'audio/mpeg': audio.MpegAudioStripper, | ||
| 20 | 'application/x-bittorrent': misc.TorrentStripper, | ||
| 21 | 'application/opendocument': office.OpenDocumentStripper, | ||
| 22 | 'application/officeopenxml': office.OpenXmlStripper, | ||
| 23 | } | ||
| 24 | |||
| 25 | logging.basicConfig(level=mat.LOGGING_LEVEL) | ||
| 26 | |||
| 27 | # PDF support | ||
| 28 | pdfSupport = True | ||
| 29 | try: | ||
| 30 | from gi.repository import Poppler | ||
| 31 | except ImportError: | ||
| 32 | logging.info('Unable to import Poppler: no PDF support') | ||
| 33 | pdfSupport = False | ||
| 34 | |||
| 35 | try: | ||
| 36 | import cairo | ||
| 37 | except ImportError: | ||
| 38 | logging.info('Unable to import python-cairo: no PDF support') | ||
| 39 | pdfSupport = False | ||
| 40 | |||
| 41 | try: | ||
| 42 | import pdfrw | ||
| 43 | except ImportError: | ||
| 44 | logging.info('Unable to import python-pdfrw: no PDf support') | ||
| 45 | pdfSupport = False | ||
| 46 | |||
| 47 | if pdfSupport: | ||
| 48 | STRIPPERS['application/x-pdf'] = office.PdfStripper | ||
| 49 | STRIPPERS['application/pdf'] = office.PdfStripper | ||
| 50 | |||
| 51 | |||
| 52 | # audio format support with mutagen-python | ||
| 53 | try: | ||
| 54 | import mutagen | ||
| 55 | STRIPPERS['audio/x-flac'] = audio.FlacStripper | ||
| 56 | STRIPPERS['audio/vorbis'] = audio.OggStripper | ||
| 57 | STRIPPERS['audio/mpeg'] = audio.MpegAudioStripper | ||
| 58 | except ImportError: | ||
| 59 | logging.info('Unable to import python-mutagen: limited audio format support') | ||
| 60 | |||
| 61 | # exiftool | ||
| 62 | try: | ||
| 63 | subprocess.check_output(['exiftool', '-ver']) | ||
| 64 | import exiftool | ||
| 65 | STRIPPERS['image/jpeg'] = exiftool.JpegStripper | ||
| 66 | STRIPPERS['image/png'] = exiftool.PngStripper | ||
| 67 | except OSError: # if exiftool is not installed, use hachoir instead | ||
| 68 | logging.info('Unable to find exiftool: limited images support') | ||
| 69 | STRIPPERS['image/jpeg'] = images.JpegStripper | ||
| 70 | STRIPPERS['image/png'] = images.PngStripper | ||
