diff options
Diffstat (limited to 'libmat/exiftool.py')
| -rw-r--r-- | libmat/exiftool.py | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/libmat/exiftool.py b/libmat/exiftool.py index aa6849d..0e1fefd 100644 --- a/libmat/exiftool.py +++ b/libmat/exiftool.py | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ''' Care about images with help of the amazing (perl) library Exiftool. | 1 | """ Care about images with help of the amazing (perl) library Exiftool. |
| 2 | ''' | 2 | """ |
| 3 | 3 | ||
| 4 | import subprocess | 4 | import subprocess |
| 5 | 5 | ||
| @@ -7,25 +7,24 @@ import parser | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | class ExiftoolStripper(parser.GenericParser): | 9 | class ExiftoolStripper(parser.GenericParser): |
| 10 | ''' A generic stripper class using exiftool as backend | 10 | """ A generic stripper class using exiftool as backend |
| 11 | ''' | 11 | """ |
| 12 | 12 | ||
| 13 | def __init__(self, filename, parser, mime, backup, is_writable, **kwargs): | 13 | def __init__(self, filename, parser, mime, backup, is_writable, **kwargs): |
| 14 | super(ExiftoolStripper, self).__init__(filename, parser, mime, backup, is_writable, **kwargs) | 14 | super(ExiftoolStripper, self).__init__(filename, parser, mime, backup, is_writable, **kwargs) |
| 15 | self.allowed = set(['ExifTool Version Number', 'File Name', 'Directory', | 15 | self.allowed = {'ExifTool Version Number', 'File Name', 'Directory', 'File Size', 'File Modification Date/Time', |
| 16 | 'File Size', 'File Modification Date/Time', 'File Access Date/Time', 'File Permissions', | 16 | 'File Access Date/Time', 'File Permissions', 'File Type', 'File Type Extension', 'MIME Type', |
| 17 | 'File Type', 'File Type Extension', 'MIME Type', 'Image Width', 'Image Height', | 17 | 'Image Width', 'Image Height', 'Image Size', 'File Inode Change Date/Time', 'Megapixels'} |
| 18 | 'Image Size', 'File Inode Change Date/Time', 'Megapixels']) | ||
| 19 | self._set_allowed() | 18 | self._set_allowed() |
| 20 | 19 | ||
| 21 | def _set_allowed(self): | 20 | def _set_allowed(self): |
| 22 | ''' Virtual method. Set the allowed/harmless list of metadata | 21 | """ Virtual method. Set the allowed/harmless list of metadata |
| 23 | ''' | 22 | """ |
| 24 | raise NotImplementedError | 23 | raise NotImplementedError |
| 25 | 24 | ||
| 26 | def remove_all(self): | 25 | def remove_all(self): |
| 27 | ''' Remove all metadata with help of exiftool | 26 | """ Remove all metadata with help of exiftool |
| 28 | ''' | 27 | """ |
| 29 | try: | 28 | try: |
| 30 | if self.backup: | 29 | if self.backup: |
| 31 | self.create_backup_copy() | 30 | self.create_backup_copy() |
| @@ -38,16 +37,16 @@ class ExiftoolStripper(parser.GenericParser): | |||
| 38 | return False | 37 | return False |
| 39 | 38 | ||
| 40 | def is_clean(self): | 39 | def is_clean(self): |
| 41 | ''' Check if the file is clean with the help of exiftool | 40 | """ Check if the file is clean with the help of exiftool |
| 42 | ''' | 41 | """ |
| 43 | return not self.get_meta() | 42 | return not self.get_meta() |
| 44 | 43 | ||
| 45 | def get_meta(self): | 44 | def get_meta(self): |
| 46 | ''' Return every harmful meta with help of exiftool. | 45 | """ Return every harmful meta with help of exiftool. |
| 47 | Exiftool output looks like this: | 46 | Exiftool output looks like this: |
| 48 | field name : value | 47 | field name : value |
| 49 | field name : value | 48 | field name : value |
| 50 | ''' | 49 | """ |
| 51 | output = subprocess.Popen(['exiftool', self.filename], | 50 | output = subprocess.Popen(['exiftool', self.filename], |
| 52 | stdout=subprocess.PIPE).communicate()[0] | 51 | stdout=subprocess.PIPE).communicate()[0] |
| 53 | meta = {} | 52 | meta = {} |
| @@ -59,9 +58,9 @@ class ExiftoolStripper(parser.GenericParser): | |||
| 59 | 58 | ||
| 60 | 59 | ||
| 61 | class JpegStripper(ExiftoolStripper): | 60 | class JpegStripper(ExiftoolStripper): |
| 62 | ''' Care about jpeg files with help | 61 | """ Care about jpeg files with help |
| 63 | of exiftool | 62 | of exiftool |
| 64 | ''' | 63 | """ |
| 65 | def _set_allowed(self): | 64 | def _set_allowed(self): |
| 66 | self.allowed.update(['JFIF Version', 'Resolution Unit', | 65 | self.allowed.update(['JFIF Version', 'Resolution Unit', |
| 67 | 'X Resolution', 'Y Resolution', 'Encoding Process', | 66 | 'X Resolution', 'Y Resolution', 'Encoding Process', |
| @@ -69,9 +68,9 @@ class JpegStripper(ExiftoolStripper): | |||
| 69 | 68 | ||
| 70 | 69 | ||
| 71 | class PngStripper(ExiftoolStripper): | 70 | class PngStripper(ExiftoolStripper): |
| 72 | ''' Care about png files with help | 71 | """ Care about png files with help |
| 73 | of exiftool | 72 | of exiftool |
| 74 | ''' | 73 | """ |
| 75 | def _set_allowed(self): | 74 | def _set_allowed(self): |
| 76 | self.allowed.update(['Bit Depth', 'Color Type', | 75 | self.allowed.update(['Bit Depth', 'Color Type', |
| 77 | 'Compression', 'Filter', 'Interlace', 'Palette', | 76 | 'Compression', 'Filter', 'Interlace', 'Palette', |
