diff options
| author | jvoisin | 2015-11-02 18:23:57 +0100 |
|---|---|---|
| committer | jvoisin | 2015-11-02 18:23:57 +0100 |
| commit | d87711e172d215198f1831cad85e7bbdae727093 (patch) | |
| tree | 31e0b979546cd9c314f336dffe082e9bf9ed6e5a /libmat | |
| parent | f5a39ac0b6ddc9154b1b1b55d255074d6dd4eecd (diff) | |
Add support for TIFF file
Diffstat (limited to 'libmat')
| -rw-r--r-- | libmat/exiftool.py | 39 | ||||
| -rw-r--r-- | libmat/strippers.py | 2 |
2 files changed, 28 insertions, 13 deletions
diff --git a/libmat/exiftool.py b/libmat/exiftool.py index 0e1fefd..07ef06b 100644 --- a/libmat/exiftool.py +++ b/libmat/exiftool.py | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | """ | 2 | """ |
| 3 | 3 | ||
| 4 | import subprocess | 4 | import subprocess |
| 5 | |||
| 6 | import parser | 5 | import parser |
| 7 | 6 | ||
| 8 | 7 | ||
| @@ -29,11 +28,12 @@ class ExiftoolStripper(parser.GenericParser): | |||
| 29 | if self.backup: | 28 | if self.backup: |
| 30 | self.create_backup_copy() | 29 | self.create_backup_copy() |
| 31 | # Note: '-All=' must be followed by a known exiftool option. | 30 | # Note: '-All=' must be followed by a known exiftool option. |
| 32 | subprocess.call(['exiftool', '-m', '-all=', | 31 | # Also, '-CommonIFD0' is needed for .tiff files |
| 33 | '-adobe=', '-overwrite_original', self.filename], | 32 | subprocess.call(['exiftool', '-all=', '-adobe=', '-exif:all=', '-Time:All=', '-m', |
| 34 | stdout=open('/dev/null')) | 33 | '-CommonIFD0=', '-overwrite_original', self.filename], |
| 34 | stdout=open('/dev/null')) | ||
| 35 | return True | 35 | return True |
| 36 | except: | 36 | except OSError: |
| 37 | return False | 37 | return False |
| 38 | 38 | ||
| 39 | def is_clean(self): | 39 | def is_clean(self): |
| @@ -48,7 +48,7 @@ class ExiftoolStripper(parser.GenericParser): | |||
| 48 | field name : value | 48 | field name : value |
| 49 | """ | 49 | """ |
| 50 | output = subprocess.Popen(['exiftool', self.filename], | 50 | output = subprocess.Popen(['exiftool', self.filename], |
| 51 | stdout=subprocess.PIPE).communicate()[0] | 51 | stdout=subprocess.PIPE).communicate()[0] |
| 52 | meta = {} | 52 | meta = {} |
| 53 | for i in output.split('\n')[:-1]: # chop last char ('\n') | 53 | for i in output.split('\n')[:-1]: # chop last char ('\n') |
| 54 | key = i.split(':')[0].strip() | 54 | key = i.split(':')[0].strip() |
| @@ -61,19 +61,34 @@ class JpegStripper(ExiftoolStripper): | |||
| 61 | """ Care about jpeg files with help | 61 | """ Care about jpeg files with help |
| 62 | of exiftool | 62 | of exiftool |
| 63 | """ | 63 | """ |
| 64 | |||
| 64 | def _set_allowed(self): | 65 | def _set_allowed(self): |
| 65 | self.allowed.update(['JFIF Version', 'Resolution Unit', | 66 | self.allowed.update(['JFIF Version', 'Resolution Unit', |
| 66 | 'X Resolution', 'Y Resolution', 'Encoding Process', | 67 | 'X Resolution', 'Y Resolution', 'Encoding Process', |
| 67 | 'Bits Per Sample', 'Color Components', 'Y Cb Cr Sub Sampling']) | 68 | 'Bits Per Sample', 'Color Components', 'Y Cb Cr Sub Sampling']) |
| 68 | 69 | ||
| 69 | 70 | ||
| 70 | class PngStripper(ExiftoolStripper): | 71 | class PngStripper(ExiftoolStripper): |
| 71 | """ Care about png files with help | 72 | """ Care about png files with help |
| 72 | of exiftool | 73 | of exiftool |
| 73 | """ | 74 | """ |
| 75 | |||
| 74 | def _set_allowed(self): | 76 | def _set_allowed(self): |
| 75 | self.allowed.update(['Bit Depth', 'Color Type', | 77 | self.allowed.update(['Bit Depth', 'Color Type', |
| 76 | 'Compression', 'Filter', 'Interlace', 'Palette', | 78 | 'Compression', 'Filter', 'Interlace', 'Palette', |
| 77 | 'Pixels Per Unit X', | 79 | 'Pixels Per Unit X', |
| 78 | 'Pixels Per Unit Y', 'Pixel Units', 'Significant Bits', | 80 | 'Pixels Per Unit Y', 'Pixel Units', 'Significant Bits', |
| 79 | 'Background Color', 'SRGB Rendering']) | 81 | 'Background Color', 'SRGB Rendering']) |
| 82 | |||
| 83 | |||
| 84 | class TiffStripper(ExiftoolStripper): | ||
| 85 | """ Care about tiff files with help | ||
| 86 | of exiftool | ||
| 87 | """ | ||
| 88 | |||
| 89 | def _set_allowed(self): | ||
| 90 | # Todo: it would be awesome to detect the Resolution Unit, and to transform it in centimeter if it's in inches. | ||
| 91 | self.allowed.update(['X Resolution', 'Y Resolution', 'Compression', 'Bits Per Sample', | ||
| 92 | 'Strip Offsets', 'Photometric Interpretation', 'Strip Byte Counts', | ||
| 93 | 'Resolution Unit', 'Exif Byte Order', 'Samples Per Pixel', 'Rows Per Strip', | ||
| 94 | 'Orientation']) | ||
diff --git a/libmat/strippers.py b/libmat/strippers.py index d9a8706..3aca04f 100644 --- a/libmat/strippers.py +++ b/libmat/strippers.py | |||
| @@ -3,7 +3,6 @@ | |||
| 3 | 3 | ||
| 4 | import archive | 4 | import archive |
| 5 | import audio | 5 | import audio |
| 6 | import gi | ||
| 7 | import images | 6 | import images |
| 8 | import logging | 7 | import logging |
| 9 | import mat | 8 | import mat |
| @@ -67,6 +66,7 @@ try: | |||
| 67 | import exiftool | 66 | import exiftool |
| 68 | STRIPPERS['image/jpeg'] = exiftool.JpegStripper | 67 | STRIPPERS['image/jpeg'] = exiftool.JpegStripper |
| 69 | STRIPPERS['image/png'] = exiftool.PngStripper | 68 | STRIPPERS['image/png'] = exiftool.PngStripper |
| 69 | STRIPPERS['image/tiff'] = exiftool.TiffStripper | ||
| 70 | except OSError: # if exiftool is not installed, use hachoir instead | 70 | except OSError: # if exiftool is not installed, use hachoir instead |
| 71 | logging.info('Unable to find exiftool: limited images support') | 71 | logging.info('Unable to find exiftool: limited images support') |
| 72 | STRIPPERS['image/jpeg'] = images.JpegStripper | 72 | STRIPPERS['image/jpeg'] = images.JpegStripper |
