Allow to handle multiple extensions
This commit is contained in:
parent
967dbd8d4f
commit
93525005db
2 changed files with 27 additions and 10 deletions
|
@ -9,29 +9,42 @@ from pymongo import MongoClient
|
|||
|
||||
from exif_json import execute_exiftool
|
||||
|
||||
_allowed_extensions = [
|
||||
'.ARW',
|
||||
'.NEF',
|
||||
]
|
||||
|
||||
|
||||
def _load_pictures_cache() -> dict:
|
||||
file_path = _get_make_pictures_cache_path()
|
||||
_file_path = _get_make_pictures_cache_path()
|
||||
|
||||
try:
|
||||
with open(file_path, 'r') as f:
|
||||
with open(_file_path, 'r') as f:
|
||||
return json.load(f)
|
||||
except FileNotFoundError:
|
||||
return {}
|
||||
|
||||
|
||||
def _save_pictures_cache(pictures: dict):
|
||||
file_path = _get_make_pictures_cache_path()
|
||||
def _save_pictures_cache(_pictures: dict):
|
||||
_file_path = _get_make_pictures_cache_path()
|
||||
|
||||
with open(file_path, 'w') as f:
|
||||
json.dump(pictures, f)
|
||||
with open(_file_path, 'w') as f:
|
||||
json.dump(_pictures, f)
|
||||
|
||||
|
||||
def _get_make_pictures_cache_path():
|
||||
data_dir = user_data_dir('exif-database', 'creekorful')
|
||||
Path(data_dir).mkdir(parents=True, exist_ok=True)
|
||||
_data_dir = user_data_dir('exif-database', 'creekorful')
|
||||
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__':
|
||||
|
@ -49,9 +62,12 @@ if __name__ == '__main__':
|
|||
processed_pictures = 0
|
||||
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)
|
||||
|
||||
if not _is_extension_allowed(filename):
|
||||
continue
|
||||
|
||||
if filename in saved_pictures:
|
||||
print(f'Skipping {filename}')
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue