skorokithakis / photocopy

A script to archive photos off a camera to a directory.
MIT License
10 stars 7 forks source link

Dpesn't read EXIF created date from Fuji RAF raw files #2

Open ilium007 opened 7 months ago

ilium007 commented 7 months ago

Any Fuji raf files I have are imported as todays date.

ilium007 commented 7 months ago
>>> image = open("/Users/xxx/Downloads/Exports/DSCF0535.raf", "rb")
>>> tags = exifread.process_file(image, details=False, stop_tag="Image DateTime")
File format not recognized.
ilium007 commented 7 months ago

I will probably re-write to make use of the exif library (exifread is deprecated I think) https://pypi.org/project/exif/

>>> from exif import Image
>>> image = open("/Users/xxxx/Downloads/Exports/DSCF0535.raf", 'rb')
>>> image2 = Image(image)
>>> image2.list_all()
['make', 'model', 'orientation', 'x_resolution', 'y_resolution', 'resolution_unit', 'software', 'datetime', 'artist', 'y_and_c_positioning', 'copyright', '_exif_ifd_pointer', 'compression', 'jpeg_interchange_format', 'jpeg_interchange_format_length', 'exposure_time', 'f_number', 'exposure_program', 'photographic_sensitivity', 'sensitivity_type', 'exif_version', 'datetime_original', 'datetime_digitized', 'components_configuration', 'compressed_bits_per_pixel', 'shutter_speed_value', 'aperture_value', 'brightness_value', 'exposure_bias_value', 'max_aperture_value', 'metering_mode', 'light_source', 'flash', 'focal_length', 'maker_note', 'user_comment', 'flashpix_version', 'color_space', 'pixel_x_dimension', 'pixel_y_dimension', '_interoperability_ifd_Pointer', 'focal_plane_x_resolution', 'focal_plane_y_resolution', 'focal_plane_resolution_unit', 'sensing_method', 'file_source', 'scene_type', 'custom_rendered', 'exposure_mode', 'white_balance', 'scene_capture_type', 'sharpness', 'subject_distance_range', 'body_serial_number']
>>> image2.model
image2.model
>>> image2.model
'X100F'
>>> image2.datetime_original
'2019:01:29 08:08:31'
>>>
ilium007 commented 7 months ago

I have it working now for Fuji RAF raw files using the exif library (instead of exifread)

Different import:

from exif import Image

Change to this function:

def get_created_date(filename):
    created_date = None
    if re.search("\.(jpeg|jpg|%s)$" % "|".join(RAW_EXTENSIONS), filename.lower()):
        logger.debug("  File probably has an EXIF tag, checking...")
        source_image = open(filename, "rb")
        image = Image(source_image)
        read_date = (
            image.datetime
            or image.datetime_digitized
            or image.datetime_original
        )
        if read_date:
            created_date = datetime.datetime.strptime(read_date, "%Y:%m:%d %H:%M:%S")

    if not created_date:
        created_date = datetime.datetime.fromtimestamp(os.path.getmtime(filename))
    return created_date
skorokithakis commented 7 months ago

This looks good, thanks! Would you be interested in opening a PR?