mirror of https://github.com/fmartingr/porg.git
Using exiftool to read exif data from files
This commit is contained in:
parent
6d193318c9
commit
86f8da7f3b
13
porg.py
13
porg.py
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue