Fix cache option for exiftool

This commit is contained in:
Cédric Leporcq 2022-01-29 15:19:37 +01:00
parent 957e436309
commit ea37849eae
2 changed files with 31 additions and 15 deletions

View File

@ -96,6 +96,7 @@ class ReadExif(ExifMetadata):
self, self,
file_path, file_path,
exif_metadata=None, exif_metadata=None,
cache=True,
ignore_tags=None, ignore_tags=None,
): ):
@ -103,11 +104,14 @@ class ReadExif(ExifMetadata):
# Options # Options
self.log = LOG.getChild(self.__class__.__name__) self.log = LOG.getChild(self.__class__.__name__)
self.cache = cache
if exif_metadata: if exif_metadata:
self.exif_metadata = exif_metadata self.exif_metadata = exif_metadata
else: elif self.cache:
self.exif_metadata = self.get_exif_metadata_caching() self.exif_metadata = self.get_exif_metadata_caching()
else:
self.exif_metadata = self.get_exif_metadata()
def get_exif_metadata(self): def get_exif_metadata(self):
"""Get metadata from exiftool.""" """Get metadata from exiftool."""
@ -264,11 +268,13 @@ class Media(ReadExif):
album_from_folder=False, album_from_folder=False,
ignore_tags=None, ignore_tags=None,
interactive=False, interactive=False,
cache=True,
use_date_filename=False, use_date_filename=False,
use_file_dates=False, use_file_dates=False,
): ):
super().__init__( super().__init__(
file_path, file_path,
cache=True,
ignore_tags=ignore_tags, ignore_tags=ignore_tags,
) )
@ -278,6 +284,7 @@ class Media(ReadExif):
self.interactive = interactive self.interactive = interactive
self.log = LOG.getChild(self.__class__.__name__) self.log = LOG.getChild(self.__class__.__name__)
self.metadata = None self.metadata = None
self.cache = cache
self.use_date_filename = use_date_filename self.use_date_filename = use_date_filename
self.use_file_dates = use_file_dates self.use_file_dates = use_file_dates
@ -651,6 +658,7 @@ class Medias:
self.album_from_folder, self.album_from_folder,
self.ignore_tags, self.ignore_tags,
self.interactive, self.interactive,
self.exif_opt['cache'],
self.exif_opt['use_date_filename'], self.exif_opt['use_date_filename'],
self.exif_opt['use_file_dates'], self.exif_opt['use_file_dates'],
) )

View File

@ -1,12 +1,9 @@
from datetime import datetime from datetime import datetime
import os
import pytest
from pathlib import Path from pathlib import Path
import re import re
import shutil
import tempfile
from ordigi import constants import pytest
from ordigi.media import Media from ordigi.media import Media
from ordigi.exiftool import ExifTool, ExifToolCaching from ordigi.exiftool import ExifTool, ExifToolCaching
from ordigi.utils import get_date_from_string from ordigi.utils import get_date_from_string
@ -19,13 +16,23 @@ class TestMedia:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup_class(cls, sample_files_paths): def setup_class(cls, sample_files_paths):
cls.src_path, cls.file_paths = sample_files_paths cls.src_path, cls.file_paths = sample_files_paths
cls.ignore_tags = ('EXIF:CreateDate', 'File:FileModifyDate', cls.ignore_tags = (
'File:FileAccessDate', 'EXIF:Make', 'Composite:LightValue') 'EXIF:CreateDate',
'File:FileModifyDate',
'File:FileAccessDate',
'EXIF:Make',
'Composite:LightValue'
)
def get_media(self): def get_media(self):
for file_path in self.file_paths: for file_path in self.file_paths:
self.exif_data = ExifTool(file_path).asdict() yield file_path, Media(
yield file_path, Media(file_path, self.src_path, album_from_folder=True, ignore_tags=self.ignore_tags) file_path,
self.src_path,
album_from_folder=True,
cache=False,
ignore_tags=self.ignore_tags,
)
def test_get_metadata(self, tmp_path): def test_get_metadata(self, tmp_path):
for file_path, media in self.get_media(): for file_path, media in self.get_media():
@ -68,14 +75,15 @@ class TestMedia:
has_exif_data = True has_exif_data = True
assert media.has_exif_data() assert media.has_exif_data()
break break
if has_exif_data == False: if not has_exif_data:
assert not media.has_exif_data() assert not media.has_exif_data()
def test_get_date_media(self): def test_get_date_media(self):
for file_path in self.file_paths: for file_path in self.file_paths:
exif_data = ExifToolCaching(str(file_path)).asdict() exif_data = ExifToolCaching(str(file_path)).asdict()
media = Media(file_path, self.src_path, use_date_filename=True, media = Media(
use_file_dates=True) file_path, self.src_path, use_date_filename=True, use_file_dates=True
)
media.get_metadata(self.src_path) media.get_metadata(self.src_path)
date_media = media.get_date_media() date_media = media.get_date_media()