Create exif_json and start mapping dates
This commit is contained in:
parent
6bea2c0043
commit
d77f655acf
4 changed files with 49 additions and 18 deletions
|
@ -1,28 +1,13 @@
|
|||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from platformdirs import user_data_dir
|
||||
from pymongo import MongoClient
|
||||
|
||||
|
||||
def _execute_exiftool(img_file: str) -> dict:
|
||||
res = subprocess.run(
|
||||
['exiftool', img_file],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
exif_metadata = {}
|
||||
|
||||
for line in res.stdout.splitlines():
|
||||
parts = line.split(':', 1)
|
||||
exif_metadata[parts[0].strip().lower().replace(' ', '_')] = parts[1].strip()
|
||||
|
||||
return exif_metadata
|
||||
from exif_json import execute_exiftool
|
||||
|
||||
|
||||
def _load_pictures_cache() -> dict:
|
||||
|
@ -69,7 +54,7 @@ if __name__ == '__main__':
|
|||
|
||||
print(f'Uploading {filename}')
|
||||
|
||||
picture_metadata = _execute_exiftool(filename)
|
||||
picture_metadata = execute_exiftool(filename)
|
||||
metadata_pictures.append(picture_metadata)
|
||||
|
||||
# Append MongoDB identifier
|
||||
|
|
37
exif_json/__init__.py
Normal file
37
exif_json/__init__.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
import subprocess
|
||||
from datetime import datetime
|
||||
|
||||
_file_date_format = "%Y:%m:%d %H:%M:%S%z"
|
||||
_original_date_format = "%Y:%m:%d %H:%M:%S.%f%z"
|
||||
|
||||
|
||||
def execute_exiftool(img_file: str) -> dict:
|
||||
res = subprocess.run(
|
||||
['exiftool', img_file],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
if res.returncode != 0:
|
||||
raise Exception(res.stderr)
|
||||
|
||||
exif_metadata = {}
|
||||
|
||||
for line in res.stdout.splitlines():
|
||||
parts = line.split(':', 1)
|
||||
exif_metadata[parts[0].strip().lower().replace(' ', '_')] = parts[1].strip()
|
||||
|
||||
# Handle dates
|
||||
date_fields = {
|
||||
'file_modification_date/time': _file_date_format,
|
||||
'file_access_date/time': _file_date_format,
|
||||
'file_inode_change_date/time': _file_date_format,
|
||||
'date/time_original': _original_date_format,
|
||||
'create_date': _original_date_format,
|
||||
}
|
||||
|
||||
for (date_field, date_format) in date_fields.items():
|
||||
if date_field in exif_metadata:
|
||||
exif_metadata[date_field] = datetime.strptime(exif_metadata[date_field], date_format)
|
||||
|
||||
return exif_metadata
|
8
exif_json/__main__.py
Normal file
8
exif_json/__main__.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
import sys
|
||||
|
||||
from rich import print
|
||||
|
||||
from exif_json import execute_exiftool
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(execute_exiftool(sys.argv[1]))
|
|
@ -1,2 +1,3 @@
|
|||
pymongo==4.10.1
|
||||
platformdirs==4.3.6
|
||||
rich==13.9.4
|
Loading…
Add table
Add a link
Reference in a new issue