summaryrefslogtreecommitdiff
path: root/libmat/strippers.py
blob: 4fcafe9da27254216fc1c14f973b3fa33ca2aaad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
""" Manage which fileformat can be processed
"""

#from libmat.archive import TarStripper, Bzip2Stripper, GzipStripper, ZipStripper
from libmat import mutagenstripper, misc, office
from libmat.mat import LOGGING_LEVEL
import logging
import subprocess

STRIPPERS = {
    #'application/x-tar': TarStripper,
    #'application/x-bzip2': Bzip2Stripper,
    #'application/x-gzip': GzipStripper,
    #'application/zip': ZipStripper,
    #'application/x-bittorrent': misc.TorrentStripper,
    #'application/torrent': misc.TorrentStripper,
    #'application/opendocument': office.OpenDocumentStripper,
    #'application/officeopenxml': office.OpenXmlStripper,
}

logging.basicConfig(level=LOGGING_LEVEL)

# PDF support
pdfSupport = True
try:
    import gi
    gi.require_version('Poppler', '0.18')
    from gi.repository import Poppler
except ImportError:
    logging.error('Unable to import Poppler: no PDF support')
    pdfSupport = False

try:
    import cairo
except ImportError:
    logging.error('Unable to import python-cairo: no PDF support')
    pdfSupport = False

try:
    import pdfrw
except ImportError:
    logging.error('Unable to import python-pdfrw: no PDF support')
    pdfSupport = False

if pdfSupport:
    STRIPPERS['application/x-pdf'] = office.PdfStripper
    STRIPPERS['application/pdf'] = office.PdfStripper


# audio format support with mutagen-python
try:
    import mutagen
    STRIPPERS['audio/x-flac'] = mutagenstripper.FlacStripper
    STRIPPERS['audio/flac'] = mutagenstripper.FlacStripper
    STRIPPERS['audio/vorbis'] = mutagenstripper.OggStripper
    STRIPPERS['audio/ogg'] = mutagenstripper.OggStripper
    STRIPPERS['audio/mpeg'] = mutagenstripper.MpegAudioStripper
except ImportError:
    logging.error('Unable to import python-mutagen: no audio format support')

# exiftool
try:
    subprocess.check_output(['exiftool', '-ver'])
    from libmat import exiftool
    STRIPPERS['image/jpeg'] = exiftool.JpegStripper
    STRIPPERS['image/png'] = exiftool.PngStripper
    STRIPPERS['image/tiff'] = exiftool.TiffStripper
except OSError:
    logging.error('Unable to find exiftool: no images support')