summaryrefslogtreecommitdiff
path: root/libmat/strippers.py
diff options
context:
space:
mode:
Diffstat (limited to 'libmat/strippers.py')
-rw-r--r--libmat/strippers.py70
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
4import archive
5import audio
6import gi
7import images
8import logging
9import mat
10import misc
11import office
12import subprocess
13
14STRIPPERS = {
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
25logging.basicConfig(level=mat.LOGGING_LEVEL)
26
27# PDF support
28pdfSupport = True
29try:
30 from gi.repository import Poppler
31except ImportError:
32 logging.info('Unable to import Poppler: no PDF support')
33 pdfSupport = False
34
35try:
36 import cairo
37except ImportError:
38 logging.info('Unable to import python-cairo: no PDF support')
39 pdfSupport = False
40
41try:
42 import pdfrw
43except ImportError:
44 logging.info('Unable to import python-pdfrw: no PDf support')
45 pdfSupport = False
46
47if pdfSupport:
48 STRIPPERS['application/x-pdf'] = office.PdfStripper
49 STRIPPERS['application/pdf'] = office.PdfStripper
50
51
52# audio format support with mutagen-python
53try:
54 import mutagen
55 STRIPPERS['audio/x-flac'] = audio.FlacStripper
56 STRIPPERS['audio/vorbis'] = audio.OggStripper
57 STRIPPERS['audio/mpeg'] = audio.MpegAudioStripper
58except ImportError:
59 logging.info('Unable to import python-mutagen: limited audio format support')
60
61# exiftool
62try:
63 subprocess.check_output(['exiftool', '-ver'])
64 import exiftool
65 STRIPPERS['image/jpeg'] = exiftool.JpegStripper
66 STRIPPERS['image/png'] = exiftool.PngStripper
67except 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