From c577363160ee075260a7d423a30e2f3c4219d0e1 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 21 Sep 2011 13:09:23 +0200 Subject: Exiftool powered support for jpeg format --- mat/exiftool.py | 44 ++++++++++++++++++++++++++++++++++++++++---- mat/mat.py | 9 ++++----- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/mat/exiftool.py b/mat/exiftool.py index d9c938a..7cd279a 100644 --- a/mat/exiftool.py +++ b/mat/exiftool.py @@ -4,17 +4,53 @@ import subprocess import images -import parser -class Jpeg_Stripper(images.JpegStripper): + +class JpegStripper(images.JpegStripper): ''' Care about jpeg files with help of exiftool ''' + 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 remove_all(self): ''' Remove all metadata with help of exiftool ''' - subprocess.Popen(['exiftool', '-filename=', self.output, - '-all= ', self.filename]) + if self.backup: + process = subprocess.Popen(['exiftool', '-all=', + '-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')) + process.wait() + + def is_clean(self): + ''' + Check if the file is clean + ''' + 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: + return False + return True + def get_meta(self): # FIXME: UGLY + 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: + meta[key] = i.split(':')[1].strip() + return meta diff --git a/mat/mat.py b/mat/mat.py index 0b75ba6..1700561 100644 --- a/mat/mat.py +++ b/mat/mat.py @@ -54,13 +54,12 @@ except ImportError: print('Unable to import python-mutagen: limited audio format support') try: - #FIXME : WIP - subprocess.Popen('exiftool_', stdout=open('/dev/null')) + subprocess.Popen('exiftool', stdout=open('/dev/null')) import exiftool - #STRIPPERS['image/jpeg'] = exiftool.JpegStripper - #STRIPPERS['image/png'] = exiftool.PngStripper + STRIPPERS['image/jpeg'] = exiftool.JpegStripper + STRIPPERS['image/png'] = images.PngStripper except: - #print('Unable to find exiftool: limited images support') + print('Unable to find exiftool: limited images support') STRIPPERS['image/jpeg'] = images.JpegStripper STRIPPERS['image/png'] = images.PngStripper -- cgit v1.3