summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MAT/exiftool.py34
1 files changed, 12 insertions, 22 deletions
diff --git a/MAT/exiftool.py b/MAT/exiftool.py
index 9803aa9..86a5be9 100644
--- a/MAT/exiftool.py
+++ b/MAT/exiftool.py
@@ -1,15 +1,12 @@
1''' 1''' Care about images with help of the amazing (perl) library Exiftool.
2 Care about images with help of the amazing (perl) library Exiftool.
3''' 2'''
4 3
5import subprocess
6import parser 4import parser
7import shutil 5import subprocess
8 6
9 7
10class ExiftoolStripper(parser.GenericParser): 8class ExiftoolStripper(parser.GenericParser):
11 ''' 9 ''' A generic stripper class using exiftool as backend
12 A generic stripper class using exiftool as backend
13 ''' 10 '''
14 11
15 def __init__(self, filename, parser, mime, backup, is_writable, **kwargs): 12 def __init__(self, filename, parser, mime, backup, is_writable, **kwargs):
@@ -21,35 +18,30 @@ class ExiftoolStripper(parser.GenericParser):
21 self._set_allowed() 18 self._set_allowed()
22 19
23 def _set_allowed(self): 20 def _set_allowed(self):
24 ''' 21 ''' Virtual method. Set the allowed/harmless list of metadata
25 Set the allowed/harmless list of metadata
26 ''' 22 '''
27 raise NotImplementedError 23 raise NotImplementedError
28 24
29 def remove_all(self): 25 def remove_all(self):
30 ''' 26 ''' Remove all metadata with help of exiftool
31 Remove all metadata with help of exiftool
32 ''' 27 '''
33 try: 28 try:
34 if self.backup: 29 if self.backup:
35 self.create_backup_copy() 30 self.create_backup_copy()
36 # Note: '-All=' must be followed by a known exiftool option. 31 # Note: '-All=' must be followed by a known exiftool option.
37 subprocess.call(['exiftool', '-m', '-all=', 32 return subprocess.call(['exiftool', '-m', '-all=',
38 '-adobe=', '-overwrite_original', self.filename], 33 '-adobe=', '-overwrite_original', self.filename],
39 stdout=open('/dev/null')) 34 stdout=open('/dev/null'))
40 return True
41 except: 35 except:
42 return False 36 return False
43 37
44 def is_clean(self): 38 def is_clean(self):
39 ''' Check if the file is clean with the help of exiftool
45 ''' 40 '''
46 Check if the file is clean with help of exiftool 41 return not self.get_meta()
47 '''
48 return self.get_meta() == {}
49 42
50 def get_meta(self): 43 def get_meta(self):
51 ''' 44 ''' Return every harmful meta with help of exiftool.
52 Return every harmful meta with help of exiftool.
53 Exiftool output looks like this: 45 Exiftool output looks like this:
54 field name : value 46 field name : value
55 field name : value 47 field name : value
@@ -57,7 +49,7 @@ class ExiftoolStripper(parser.GenericParser):
57 output = subprocess.Popen(['exiftool', self.filename], 49 output = subprocess.Popen(['exiftool', self.filename],
58 stdout=subprocess.PIPE).communicate()[0] 50 stdout=subprocess.PIPE).communicate()[0]
59 meta = {} 51 meta = {}
60 for i in output.split('\n')[:-1]: 52 for i in output.split('\n')[:-1]: # chop last char ('\n')
61 key = i.split(':')[0].strip() 53 key = i.split(':')[0].strip()
62 if key not in self.allowed: 54 if key not in self.allowed:
63 meta[key] = i.split(':')[1].strip() # add the field name to the metadata set 55 meta[key] = i.split(':')[1].strip() # add the field name to the metadata set
@@ -65,8 +57,7 @@ class ExiftoolStripper(parser.GenericParser):
65 57
66 58
67class JpegStripper(ExiftoolStripper): 59class JpegStripper(ExiftoolStripper):
68 ''' 60 ''' Care about jpeg files with help
69 Care about jpeg files with help
70 of exiftool 61 of exiftool
71 ''' 62 '''
72 def _set_allowed(self): 63 def _set_allowed(self):
@@ -76,8 +67,7 @@ class JpegStripper(ExiftoolStripper):
76 67
77 68
78class PngStripper(ExiftoolStripper): 69class PngStripper(ExiftoolStripper):
79 ''' 70 ''' Care about png files with help
80 Care about png files with help
81 of exiftool 71 of exiftool
82 ''' 72 '''
83 def _set_allowed(self): 73 def _set_allowed(self):