From f62505d25cce0576d0fa38c7d38b8582fcc0c938 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 22 Sep 2011 18:08:10 +0200 Subject: Support of png + cleanup --- mat/exiftool.py | 66 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file 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 @@ ''' import subprocess -import images +import parser -class JpegStripper(images.JpegStripper): +class ExiftoolStripper(parser.GenericParser): ''' - Care about jpeg files with help - of exiftool + A generic stripper class using exiftool as backend ''' - ALLOWED = ['ExifTool Version Number', 'File Name', 'Directory', - 'File Size', 'File Modification Date/Time', 'File Permissions', - 'File Type', 'MIME Type', 'JFIF Version', 'Resolution Unit', - 'X Resolution', 'Y Resolution', 'Image Width', 'Image Height', - 'Encoding Process', 'Bits Per Sample', 'Color Components', - 'Y Cb Cr Sub Sampling', 'Image Size'] + + def __init__(self, filename, parser, mime, backup, add2archive): + super(ExiftoolStripper, self).__init__(filename, parser, mime, + backup, add2archive) + self.allowed = ['ExifTool Version Number', 'File Name', 'Directory', + 'File Size', 'File Modification Date/Time', 'File Permissions', + 'File Type', 'MIME Type', 'Image Width', 'Image Height', + 'Image Size'] + self._set_allowed() + + def _set_allowed(self): + ''' + Set the allowed/harmless list of metadata + ''' + raise NotImplementedError def remove_all(self): ''' @@ -24,33 +32,57 @@ class JpegStripper(images.JpegStripper): ''' if self.backup: process = subprocess.Popen(['exiftool', '-all=', - '-o %s' % self.output, self.filename]) - #, stdout=open('/dev/null')) + '-o %s' % self.output, self.filename], + stdout=open('/dev/null')) process.wait() else: process = subprocess.Popen(['exiftool', '-overwrite_original', - '-all=', self.filename]) # , stdout=open('/dev/null')) + '-all=', self.filename], stdout=open('/dev/null')) process.wait() def is_clean(self): ''' - Check if the file is clean + Check if the file is clean with help of exiftool ''' out = subprocess.Popen(['exiftool', self.filename], stdout=subprocess.PIPE).communicate()[0] out = out.split('\n') for i in out[:-1]: - if i.split(':')[0].strip() not in self.ALLOWED: + if i.split(':')[0].strip() not in self.allowed: return False return True - def get_meta(self): # FIXME: UGLY + def get_meta(self): + ''' + Return every harmful meta with help of exiftool + ''' out = subprocess.Popen(['exiftool', self.filename], stdout=subprocess.PIPE).communicate()[0] out = out.split('\n') meta = {} for i in out[:-1]: key = i.split(':')[0].strip() - if key not in self.ALLOWED: + if key not in self.allowed: meta[key] = i.split(':')[1].strip() return meta + + +class JpegStripper(ExiftoolStripper): + ''' + Care about jpeg files with help + of exiftool + ''' + def _set_allowed(self): + self.allowed.extend(['JFIF Version', 'Resolution Unit', + 'X Resolution', 'Y Resolution', 'Encoding Process', 'Bits Per Sample', + 'Color Components', 'Y Cb Cr Sub Sampling']) + +class PngStripper(ExiftoolStripper): + ''' + Care about png files with help + of exiftool + ''' + def _set_allowed(self): + self.allowed.extend(['Bit Depth', 'Color Type', 'Compression', + 'Filter', 'Interlace', 'Pixels Per Unit X', 'Pixels Per Unit Y', + 'Pixel Units']) -- cgit v1.3