'zipfile and shutil not keeping the file exif data

I have a .zip archive and within it a single .dng image file with metadata about exposure time, etc. When unpacking this achive using either shutil.unpack_archive or ZipFile.extractall(), the .dng is extracted but the metadata is gone.

if file_ext == '.zip':
    with tempfile.TemporaryDirectory() as local_dir_unzip:
        with zipfile.ZipFile(local_file.name, 'r') as zip_file:
            zip_file.extractall(local_dir_unzip)
        unpacked_files = os.listdir(local_dir_unzip)
        dng_file_name = [f for f in unpacked_files if f.endswith('.dng')][0]

This file has no metadata. But if I unpack this archive using macOS's archive utility the extracted file has all the metadata.

EDIT: Using exiftool I was able to see that in fact the unpacked file did have all the EXIF information, but for some reason it is inaccessible to both the OS's get info function and to the exifread python package:

[ExifTool]      ExifToolVersion                 : 12.30
[ExifTool]      Now                             : 2022:04:05 19:59:38+03:00
[ExifTool]      NewGUID                         : 20220405-1959-3800-71AE-CDAFBE855D39
[ExifTool]      FileSequence                    : 0
[ExifTool]      ProcessingTime                  : 0.509 s
[File]          FileName                        : 20220404170458.dng
[File]          BaseName                        : 20220404170458
[File]          Directory                       : .
[File]          FilePath                        : /private/var/folders/ng/jsgvdn7s4w3gffffmfwmx9s80000gn/T/tmpbta5zv01/20220404170458.dng
[File]          FileSize                        : 10 MiB
[File]          FileModifyDate                  : 2022:04:05 19:58:56+03:00
[File]          FileAccessDate                  : 2022:04:05 19:58:56+03:00
[File]          FileInodeChangeDate             : 2022:04:05 19:58:56+03:00
[File]          FilePermissions                 : -rw-r--r--
[File]          FileAttributes                  : Regular; (none)
[File]          FileDeviceNumber                : 16777221
[File]          FileInodeNumber                 : 28568573
[File]          FileHardLinks                   : 1
[File]          FileUserID                      : yarden
[File]          FileGroupID                     : staff
[File]          FileDeviceID                    : 0.0
[File]          FileBlockSize                   : 4096
[File]          FileBlockCount                  : 20968
[File]          FileCreateDate                  : 2022:04:05 19:58:56+03:00
[File]          MDItemFSContentChangeDate       : 2022:04:05 19:58:56+03:00
[File]          MDItemFSCreationDate            : 2022:04:05 19:58:56+03:00
[File]          MDItemFSCreatorCode             :
[File]          MDItemFSFinderFlags             : 0
[File]          MDItemFSHasCustomIcon           : 0
[File]          MDItemFSInvisible               : 0
[File]          MDItemFSIsExtensionHidden       : 0
[File]          MDItemFSIsStationery            : 0
[File]          MDItemFSLabel                   : 0 (none)
[File]          MDItemFSName                    : 20220404170458.dng
[File]          MDItemFSNodeCount               : 10733045
[File]          MDItemFSOwnerGroupID            : 20
[File]          MDItemFSOwnerUserID             : 501
[File]          MDItemFSSize                    : 10733045
[File]          MDItemFSTypeCode                :
[File]          FileType                        : DNG
[File]          FileTypeExtension               : dng
[File]          MIMEType                        : image/x-adobe-dng
[File]          ExifByteOrder                   : Big-endian (Motorola, MM)
[EXIF]          SubfileType                     : Full-resolution image
[EXIF]          ImageWidth                      : 4224
[EXIF]          ImageHeight                     : 3024
[EXIF]          BitsPerSample                   : 16
[EXIF]          Compression                     : JPEG
[EXIF]          PhotometricInterpretation       : Color Filter Array
[EXIF]          Make                            : Apple
[EXIF]          Model                           : iPhone 13 mini
[EXIF]          Orientation                     : Horizontal (normal)
[EXIF]          SamplesPerPixel                 : 1
[EXIF]          PlanarConfiguration             : Chunky
[EXIF]          Software                        : 15.2.1
[EXIF]          ModifyDate                      : 2022:04:04 17:04:58
[EXIF]          TileWidth                       : 264
[EXIF]          TileLength                      : 378
[EXIF]          TileOffsets                     : (Binary data 1017 bytes, use -b option to extract)
[EXIF]          TileByteCounts                  : (Binary data 770 bytes, use -b option to extract)
[EXIF]          CFARepeatPatternDim             : 2 2
[EXIF]          CFAPattern2                     : 0 1 1 2
[EXIF]          ExposureTime                    : 1/120
[EXIF]          FNumber                         : 2.4
[EXIF]          ExposureProgram                 : Manual
[EXIF]          ISO                             : 100
[EXIF]          ExifVersion                     : 0232
[EXIF]          DateTimeOriginal                : 2022:04:04 17:04:58
[EXIF]          CreateDate                      : 2022:04:04 17:04:58
[EXIF]          OffsetTime                      : +03:00
[EXIF]          OffsetTimeOriginal              : +03:00
[EXIF]          OffsetTimeDigitized             : +03:00
[EXIF]          ShutterSpeedValue               : 1/120
[EXIF]          ApertureValue                   : 2.4
[EXIF]          BrightnessValue                 : 3.266772747
[EXIF]          ExposureCompensation            : 0
[EXIF]          MeteringMode                    : Multi-segment
[EXIF]          Flash                           : Off, Did not fire
[EXIF]          FocalLength                     : 1.5 mm
[EXIF]          SubSecTimeOriginal              : 470
[EXIF]          SubSecTimeDigitized             : 470
[EXIF]          ExifImageWidth                  : 4224
[EXIF]          ExifImageHeight                 : 3024
[EXIF]          SensingMethod                   : One-chip color area
[EXIF]          SceneType                       : Directly photographed
[EXIF]          ExposureMode                    : Manual
[EXIF]          WhiteBalance                    : Auto
[EXIF]          DigitalZoomRatio                : 1.031377899
[EXIF]          FocalLengthIn35mmFormat         : 14 mm
[EXIF]          LensInfo                        : 1.539999962mm f/2.4
[EXIF]          LensMake                        : Apple
[EXIF]          LensModel                       : iPhone 13 mini back camera 1.54mm f/2.4
[EXIF]          DNGVersion                      : 1.6.0.0
[EXIF]          DNGBackwardVersion              : 1.3.0.0
[EXIF]          UniqueCameraModel               : iPhone14,4 back ultra wide camera
[EXIF]          CFAPlaneColor                   : Red,Green,Blue
[EXIF]          BlackLevelRepeatDim             : 1 1
[EXIF]          BlackLevel                      : 528
[EXIF]          WhiteLevel                      : 4095
[EXIF]          DefaultCropOrigin               : 0 0
[EXIF]          DefaultCropSize                 : 4032 3024
[EXIF]          ColorMatrix1                    : 1.200746655 -0.5329620838 -0.2371858805 -0.4524382055 1.501772404 -0.004542022012 -0.03874496371 0.1614724994 0.6470876932
[EXIF]          ColorMatrix2                    : 0.8832943439 -0.3023501933 -0.1193092167 -0.4258989692 1.299629331 0.101080738 -0.1047417223 0.2313982993 0.4722827077
[EXIF]          AsShotNeutral                   : 0.5384514332 1 0.5940536857
[EXIF]          BaselineExposure                : 0.01105523016
[EXIF]          CalibrationIlluminant1          : Standard Light A
[EXIF]          CalibrationIlluminant2          : D65
[EXIF]          ActiveArea                      : 0 96 3024 4128
[EXIF]          NoiseReductionApplied           : undef
[EXIF]          OpcodeList3                     : [opcode 14], FixVignetteRadial
[EXIF]          NoiseProfile                    : 0.00019817037529 2.21563225e-06
[MakerNotes]    RunTimeFlags                    : Valid
[MakerNotes]    RunTimeValue                    : 352844527447041
[MakerNotes]    RunTimeEpoch                    : 0
[MakerNotes]    RunTimeScale                    : 1000000000
[MakerNotes]    AccelerationVector              : -0.9574939019 0.02597124688 0.3083640337
[Composite]     RunTimeSincePowerUp             : 4 days 2:00:45
[Composite]     Aperture                        : 2.4
[Composite]     CFAPattern                      : [Red,Green][Green,Blue]
[Composite]     ImageSize                       : 4224x3024
[Composite]     Megapixels                      : 12.8
[Composite]     ScaleFactor35efl                : 9.1
[Composite]     ShutterSpeed                    : 1/120
[Composite]     SubSecCreateDate                : 2022:04:04 17:04:58.470+03:00
[Composite]     SubSecDateTimeOriginal          : 2022:04:04 17:04:58.470+03:00
[Composite]     SubSecModifyDate                : 2022:04:04 17:04:58+03:00
[Composite]     CircleOfConfusion               : 0.003 mm
[Composite]     FOV                             : 104.3 deg
[Composite]     FocalLength35efl                : 1.5 mm (35 mm equivalent: 14.0 mm)
[Composite]     HyperfocalDistance              : 0.30 m
[Composite]     LightValue                      : 9.4
[Composite]     LensID                          : iPhone 13 mini back camera 1.54mm f/2.4


Solution 1:[1]

Turns out, I was reading the .zip with exifread instead of the unpacked DNG file within. My bad. I still can't explain why the OSs get info has a hard time with the metadata of the unpacked file, but exifread works as expected. Thanks for all the help that got me to this point.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yarden