File: strippers.py

package info (click to toggle)
mat 0.6.1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,888 kB
  • ctags: 263
  • sloc: python: 1,629; makefile: 7; sh: 6
file content (44 lines) | stat: -rw-r--r-- 1,418 bytes parent folder | download
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
""" Manage which fileformat can be processed
"""

import archive
import mutagenstripper
import logging
import mat
import misc
import office
import subprocess

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

logging.basicConfig(level=mat.LOGGING_LEVEL)

# 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'])
    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')