Fix cache option for exiftool
This commit is contained in:
parent
957e436309
commit
ea37849eae
|
@ -96,6 +96,7 @@ class ReadExif(ExifMetadata):
|
|||
self,
|
||||
file_path,
|
||||
exif_metadata=None,
|
||||
cache=True,
|
||||
ignore_tags=None,
|
||||
):
|
||||
|
||||
|
@ -103,11 +104,14 @@ class ReadExif(ExifMetadata):
|
|||
|
||||
# Options
|
||||
self.log = LOG.getChild(self.__class__.__name__)
|
||||
self.cache = cache
|
||||
|
||||
if exif_metadata:
|
||||
self.exif_metadata = exif_metadata
|
||||
else:
|
||||
elif self.cache:
|
||||
self.exif_metadata = self.get_exif_metadata_caching()
|
||||
else:
|
||||
self.exif_metadata = self.get_exif_metadata()
|
||||
|
||||
def get_exif_metadata(self):
|
||||
"""Get metadata from exiftool."""
|
||||
|
@ -264,11 +268,13 @@ class Media(ReadExif):
|
|||
album_from_folder=False,
|
||||
ignore_tags=None,
|
||||
interactive=False,
|
||||
cache=True,
|
||||
use_date_filename=False,
|
||||
use_file_dates=False,
|
||||
):
|
||||
super().__init__(
|
||||
file_path,
|
||||
cache=True,
|
||||
ignore_tags=ignore_tags,
|
||||
)
|
||||
|
||||
|
@ -278,6 +284,7 @@ class Media(ReadExif):
|
|||
self.interactive = interactive
|
||||
self.log = LOG.getChild(self.__class__.__name__)
|
||||
self.metadata = None
|
||||
self.cache = cache
|
||||
self.use_date_filename = use_date_filename
|
||||
self.use_file_dates = use_file_dates
|
||||
|
||||
|
@ -651,6 +658,7 @@ class Medias:
|
|||
self.album_from_folder,
|
||||
self.ignore_tags,
|
||||
self.interactive,
|
||||
self.exif_opt['cache'],
|
||||
self.exif_opt['use_date_filename'],
|
||||
self.exif_opt['use_file_dates'],
|
||||
)
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
from datetime import datetime
|
||||
import os
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from ordigi import constants
|
||||
import pytest
|
||||
|
||||
from ordigi.media import Media
|
||||
from ordigi.exiftool import ExifTool, ExifToolCaching
|
||||
from ordigi.utils import get_date_from_string
|
||||
|
@ -19,13 +16,23 @@ class TestMedia:
|
|||
@pytest.fixture(autouse=True)
|
||||
def setup_class(cls, sample_files_paths):
|
||||
cls.src_path, cls.file_paths = sample_files_paths
|
||||
cls.ignore_tags = ('EXIF:CreateDate', 'File:FileModifyDate',
|
||||
'File:FileAccessDate', 'EXIF:Make', 'Composite:LightValue')
|
||||
cls.ignore_tags = (
|
||||
'EXIF:CreateDate',
|
||||
'File:FileModifyDate',
|
||||
'File:FileAccessDate',
|
||||
'EXIF:Make',
|
||||
'Composite:LightValue'
|
||||
)
|
||||
|
||||
def get_media(self):
|
||||
for file_path in self.file_paths:
|
||||
self.exif_data = ExifTool(file_path).asdict()
|
||||
yield file_path, Media(file_path, self.src_path, album_from_folder=True, ignore_tags=self.ignore_tags)
|
||||
yield file_path, Media(
|
||||
file_path,
|
||||
self.src_path,
|
||||
album_from_folder=True,
|
||||
cache=False,
|
||||
ignore_tags=self.ignore_tags,
|
||||
)
|
||||
|
||||
def test_get_metadata(self, tmp_path):
|
||||
for file_path, media in self.get_media():
|
||||
|
@ -68,14 +75,15 @@ class TestMedia:
|
|||
has_exif_data = True
|
||||
assert media.has_exif_data()
|
||||
break
|
||||
if has_exif_data == False:
|
||||
if not has_exif_data:
|
||||
assert not media.has_exif_data()
|
||||
|
||||
def test_get_date_media(self):
|
||||
for file_path in self.file_paths:
|
||||
exif_data = ExifToolCaching(str(file_path)).asdict()
|
||||
media = Media(file_path, self.src_path, use_date_filename=True,
|
||||
use_file_dates=True)
|
||||
media = Media(
|
||||
file_path, self.src_path, use_date_filename=True, use_file_dates=True
|
||||
)
|
||||
media.get_metadata(self.src_path)
|
||||
date_media = media.get_date_media()
|
||||
|
||||
|
|
Loading…
Reference in New Issue