Allow to handle multiple extensions

This commit is contained in:
Aloïs Micard 2024-11-15 10:14:22 +01:00
parent 967dbd8d4f
commit 93525005db
2 changed files with 27 additions and 10 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
*.pyc *.pyc
.venv

View file

@ -9,29 +9,42 @@ from pymongo import MongoClient
from exif_json import execute_exiftool from exif_json import execute_exiftool
_allowed_extensions = [
'.ARW',
'.NEF',
]
def _load_pictures_cache() -> dict: def _load_pictures_cache() -> dict:
file_path = _get_make_pictures_cache_path() _file_path = _get_make_pictures_cache_path()
try: try:
with open(file_path, 'r') as f: with open(_file_path, 'r') as f:
return json.load(f) return json.load(f)
except FileNotFoundError: except FileNotFoundError:
return {} return {}
def _save_pictures_cache(pictures: dict): def _save_pictures_cache(_pictures: dict):
file_path = _get_make_pictures_cache_path() _file_path = _get_make_pictures_cache_path()
with open(file_path, 'w') as f: with open(_file_path, 'w') as f:
json.dump(pictures, f) json.dump(_pictures, f)
def _get_make_pictures_cache_path(): def _get_make_pictures_cache_path():
data_dir = user_data_dir('exif-database', 'creekorful') _data_dir = user_data_dir('exif-database', 'creekorful')
Path(data_dir).mkdir(parents=True, exist_ok=True) Path(_data_dir).mkdir(parents=True, exist_ok=True)
return os.path.join(data_dir, 'exif-database.json') return os.path.join(_data_dir, 'exif-database.json')
def _is_extension_allowed(_filename: str) -> bool:
for _allowed_extension in _allowed_extensions:
if _filename.endswith(_allowed_extension):
return True
return False
if __name__ == '__main__': if __name__ == '__main__':
@ -49,9 +62,12 @@ if __name__ == '__main__':
processed_pictures = 0 processed_pictures = 0
max_processed_pictures = None if len(sys.argv) < 3 else int(sys.argv[2]) max_processed_pictures = None if len(sys.argv) < 3 else int(sys.argv[2])
for file in Path(sys.argv[1]).rglob("*.ARW"): for file in Path(sys.argv[1]).rglob("*.*"):
filename = os.fsdecode(file) filename = os.fsdecode(file)
if not _is_extension_allowed(filename):
continue
if filename in saved_pictures: if filename in saved_pictures:
print(f'Skipping {filename}') print(f'Skipping {filename}')
continue continue