Using exiftool to read exif data from files

This commit is contained in:
Felipe Martin 2018-09-29 23:55:20 +02:00
parent 6d193318c9
commit 86f8da7f3b
Signed by: fmartingr
GPG Key ID: 716BC147715E716F
1 changed files with 11 additions and 2 deletions

13
porg.py
View File

@ -3,9 +3,9 @@ from datetime import datetime
import hashlib
import mimetypes
import os.path
import subprocess
from typing import Text
import exifread
import mutagen
@ -17,6 +17,15 @@ TARGET_PATH = '/Volumes/MEDIA/Pictures'
file_list = []
def read_exif(path):
output = {}
with subprocess.Popen(['exiftool', path], stdout=subprocess.PIPE) as proc:
for line in proc.stdout.readlines():
key, value = line.decode('utf-8').strip().split(':', maxsplit=1)
output[key.strip()] = value.strip()
return output
@dataclass
class File:
path: str
@ -44,7 +53,7 @@ class File:
Retrieve EXIF data from the file and merge it with wathever mutagen finds in there for video files.
"""
if not getattr(self, '_exif', False):
self._exif = exifread.process_file(open(self.path, 'rb'))
self._exif = read_exif(self.path)
if self.is_video:
self._exif.update(mutagen.File(self.path))
return self._exif