summaryrefslogtreecommitdiff
path: root/MAT/exiftool.py
diff options
context:
space:
mode:
authorjvoisin2013-08-11 18:00:59 +0200
committerjvoisin2013-08-11 18:00:59 +0200
commitcdcb25efcca990a2a8b1cf47ab709de30b0f6e7e (patch)
tree92c4961427a51e73ada1bbc40b3af736d9c31281 /MAT/exiftool.py
parent30beecd0b61687ef3fe7a773c04696e44581d687 (diff)
Refactoring of exiftool.py
Diffstat (limited to 'MAT/exiftool.py')
-rw-r--r--MAT/exiftool.py37
1 files changed, 15 insertions, 22 deletions
diff --git a/MAT/exiftool.py b/MAT/exiftool.py
index d2d177c..16e383f 100644
--- a/MAT/exiftool.py
+++ b/MAT/exiftool.py
@@ -14,10 +14,10 @@ class ExiftoolStripper(parser.GenericParser):
14 14
15 def __init__(self, filename, parser, mime, backup, **kwargs): 15 def __init__(self, filename, parser, mime, backup, **kwargs):
16 super(ExiftoolStripper, self).__init__(filename, parser, mime, backup, **kwargs) 16 super(ExiftoolStripper, self).__init__(filename, parser, mime, backup, **kwargs)
17 self.allowed = ['ExifTool Version Number', 'File Name', 'Directory', 17 self.allowed = set(['ExifTool Version Number', 'File Name', 'Directory',
18 'File Size', 'File Modification Date/Time', 'File Access Date/Time', 'File Permissions', 18 'File Size', 'File Modification Date/Time', 'File Access Date/Time', 'File Permissions',
19 'File Type', 'MIME Type', 'Image Width', 'Image Height', 19 'File Type', 'MIME Type', 'Image Width', 'Image Height',
20 'Image Size'] 20 'Image Size', 'File Inode Change Date/Time'])
21 self._set_allowed() 21 self._set_allowed()
22 22
23 def _set_allowed(self): 23 def _set_allowed(self):
@@ -34,10 +34,9 @@ class ExiftoolStripper(parser.GenericParser):
34 if self.backup: 34 if self.backup:
35 self.create_backup_copy() 35 self.create_backup_copy()
36 # Note: '-All=' must be followed by a known exiftool option. 36 # Note: '-All=' must be followed by a known exiftool option.
37 process = subprocess.Popen( ['exiftool', '-m', '-all=', 37 subprocess.call(['exiftool', '-m', '-all=',
38 '-adobe=', '-overwrite_original', self.filename ], 38 '-adobe=', '-overwrite_original', self.filename],
39 stdout=open('/dev/null')) 39 stdout=open('/dev/null'))
40 process.wait()
41 return True 40 return True
42 except: 41 except:
43 return False 42 return False
@@ -46,13 +45,7 @@ class ExiftoolStripper(parser.GenericParser):
46 ''' 45 '''
47 Check if the file is clean with help of exiftool 46 Check if the file is clean with help of exiftool
48 ''' 47 '''
49 out = subprocess.Popen(['exiftool', self.filename], 48 return self.get_meta() == {}
50 stdout=subprocess.PIPE).communicate()[0]
51 out = out.split('\n')
52 for i in out[:-1]:
53 if i.split(':')[0].strip() not in self.allowed:
54 return False
55 return True
56 49
57 def get_meta(self): 50 def get_meta(self):
58 ''' 51 '''
@@ -61,11 +54,10 @@ class ExiftoolStripper(parser.GenericParser):
61 field name : value 54 field name : value
62 field name : value 55 field name : value
63 ''' 56 '''
64 out = subprocess.Popen(['exiftool', self.filename], 57 output = subprocess.Popen(['exiftool', self.filename],
65 stdout=subprocess.PIPE).communicate()[0] 58 stdout=subprocess.PIPE).communicate()[0]
66 out = out.split('\n')
67 meta = {} 59 meta = {}
68 for i in out[:-1]: 60 for i in output.split('\n')[:-1]:
69 key = i.split(':')[0].strip() 61 key = i.split(':')[0].strip()
70 if key not in self.allowed: 62 if key not in self.allowed:
71 meta[key] = i.split(':')[1].strip() # add the field name to the metadata set 63 meta[key] = i.split(':')[1].strip() # add the field name to the metadata set
@@ -78,9 +70,10 @@ class JpegStripper(ExiftoolStripper):
78 of exiftool 70 of exiftool
79 ''' 71 '''
80 def _set_allowed(self): 72 def _set_allowed(self):
81 self.allowed.extend(['JFIF Version', 'Resolution Unit', 73 self.allowed.update(['JFIF Version', 'Resolution Unit',
82 'X Resolution', 'Y Resolution', 'Encoding Process', 'Bits Per Sample', 74 'X Resolution', 'Y Resolution', 'Encoding Process',
83 'Color Components', 'Y Cb Cr Sub Sampling']) 75 'Bits Per Sample', 'Color Components', 'Y Cb Cr Sub Sampling'])
76
84 77
85class PngStripper(ExiftoolStripper): 78class PngStripper(ExiftoolStripper):
86 ''' 79 '''
@@ -88,7 +81,7 @@ class PngStripper(ExiftoolStripper):
88 of exiftool 81 of exiftool
89 ''' 82 '''
90 def _set_allowed(self): 83 def _set_allowed(self):
91 self.allowed.extend(['Bit Depth', 'Color Type', 'Compression', 84 self.allowed.update(['Bit Depth', 'Color Type',
92 'Filter', 'Interlace', 'Pixels Per Unit X', 'Pixels Per Unit Y', 85 'Compression', 'Filter', 'Interlace', 'Pixels Per Unit X',
93 'Pixel Units', 'Significant Bits' ,'Background Color', 86 'Pixels Per Unit Y', 'Pixel Units', 'Significant Bits',
94 'SRGB Rendering',]) 87 'Background Color', 'SRGB Rendering'])