summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2011-09-22 18:08:10 +0200
committerjvoisin2011-09-22 18:08:10 +0200
commitf62505d25cce0576d0fa38c7d38b8582fcc0c938 (patch)
tree6eafcedb877be4c76f1e88f6c109654c866c01c5
parent86731d6a984347fa1460f19f3accaf26744b58b1 (diff)
Support of png + cleanup
-rw-r--r--mat/exiftool.py66
1 files changed, 49 insertions, 17 deletions
diff --git a/mat/exiftool.py b/mat/exiftool.py
index 7cd279a..f1bc350 100644
--- a/mat/exiftool.py
+++ b/mat/exiftool.py
@@ -3,20 +3,28 @@
3''' 3'''
4 4
5import subprocess 5import subprocess
6import images 6import parser
7 7
8 8
9class JpegStripper(images.JpegStripper): 9class ExiftoolStripper(parser.GenericParser):
10 ''' 10 '''
11 Care about jpeg files with help 11 A generic stripper class using exiftool as backend
12 of exiftool
13 ''' 12 '''
14 ALLOWED = ['ExifTool Version Number', 'File Name', 'Directory', 13
15 'File Size', 'File Modification Date/Time', 'File Permissions', 14 def __init__(self, filename, parser, mime, backup, add2archive):
16 'File Type', 'MIME Type', 'JFIF Version', 'Resolution Unit', 15 super(ExiftoolStripper, self).__init__(filename, parser, mime,
17 'X Resolution', 'Y Resolution', 'Image Width', 'Image Height', 16 backup, add2archive)
18 'Encoding Process', 'Bits Per Sample', 'Color Components', 17 self.allowed = ['ExifTool Version Number', 'File Name', 'Directory',
19 'Y Cb Cr Sub Sampling', 'Image Size'] 18 'File Size', 'File Modification Date/Time', 'File Permissions',
19 'File Type', 'MIME Type', 'Image Width', 'Image Height',
20 'Image Size']
21 self._set_allowed()
22
23 def _set_allowed(self):
24 '''
25 Set the allowed/harmless list of metadata
26 '''
27 raise NotImplementedError
20 28
21 def remove_all(self): 29 def remove_all(self):
22 ''' 30 '''
@@ -24,33 +32,57 @@ class JpegStripper(images.JpegStripper):
24 ''' 32 '''
25 if self.backup: 33 if self.backup:
26 process = subprocess.Popen(['exiftool', '-all=', 34 process = subprocess.Popen(['exiftool', '-all=',
27 '-o %s' % self.output, self.filename]) 35 '-o %s' % self.output, self.filename],
28 #, stdout=open('/dev/null')) 36 stdout=open('/dev/null'))
29 process.wait() 37 process.wait()
30 else: 38 else:
31 process = subprocess.Popen(['exiftool', '-overwrite_original', 39 process = subprocess.Popen(['exiftool', '-overwrite_original',
32 '-all=', self.filename]) # , stdout=open('/dev/null')) 40 '-all=', self.filename], stdout=open('/dev/null'))
33 process.wait() 41 process.wait()
34 42
35 def is_clean(self): 43 def is_clean(self):
36 ''' 44 '''
37 Check if the file is clean 45 Check if the file is clean with help of exiftool
38 ''' 46 '''
39 out = subprocess.Popen(['exiftool', self.filename], 47 out = subprocess.Popen(['exiftool', self.filename],
40 stdout=subprocess.PIPE).communicate()[0] 48 stdout=subprocess.PIPE).communicate()[0]
41 out = out.split('\n') 49 out = out.split('\n')
42 for i in out[:-1]: 50 for i in out[:-1]:
43 if i.split(':')[0].strip() not in self.ALLOWED: 51 if i.split(':')[0].strip() not in self.allowed:
44 return False 52 return False
45 return True 53 return True
46 54
47 def get_meta(self): # FIXME: UGLY 55 def get_meta(self):
56 '''
57 Return every harmful meta with help of exiftool
58 '''
48 out = subprocess.Popen(['exiftool', self.filename], 59 out = subprocess.Popen(['exiftool', self.filename],
49 stdout=subprocess.PIPE).communicate()[0] 60 stdout=subprocess.PIPE).communicate()[0]
50 out = out.split('\n') 61 out = out.split('\n')
51 meta = {} 62 meta = {}
52 for i in out[:-1]: 63 for i in out[:-1]:
53 key = i.split(':')[0].strip() 64 key = i.split(':')[0].strip()
54 if key not in self.ALLOWED: 65 if key not in self.allowed:
55 meta[key] = i.split(':')[1].strip() 66 meta[key] = i.split(':')[1].strip()
56 return meta 67 return meta
68
69
70class JpegStripper(ExiftoolStripper):
71 '''
72 Care about jpeg files with help
73 of exiftool
74 '''
75 def _set_allowed(self):
76 self.allowed.extend(['JFIF Version', 'Resolution Unit',
77 'X Resolution', 'Y Resolution', 'Encoding Process', 'Bits Per Sample',
78 'Color Components', 'Y Cb Cr Sub Sampling'])
79
80class PngStripper(ExiftoolStripper):
81 '''
82 Care about png files with help
83 of exiftool
84 '''
85 def _set_allowed(self):
86 self.allowed.extend(['Bit Depth', 'Color Type', 'Compression',
87 'Filter', 'Interlace', 'Pixels Per Unit X', 'Pixels Per Unit Y',
88 'Pixel Units'])