Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing xmp file read results in fallback to native exif extraction #596

Closed
tmp-hallenser opened this issue May 24, 2020 · 5 comments
Closed

Comments

@tmp-hallenser
Copy link
Contributor

tmp-hallenser commented May 24, 2020

The current extraction of the xmp meta data reads like this:

try {
			// this can throw an exception in the case of Exiftool adapter!
			$exif = $reader->read($filename);


			// if readlink($filename) == False then $realFile = $filename.
			// if readlink($filename) != False then $realFile = readlink($filename)
			$realFile = readlink($filename) ?: $filename;
			if (Configs::hasExiftool() && file_exists($realFile . '.xmp')) {
				// Don't use the same reader as the file in case it's a video
				$sidecarReader = Reader::factory(Reader::TYPE_EXIFTOOL);
				$sidecarData = $sidecarReader->read($realFile . '.xmp')->getData();


				// We don't want to overwrite the media's type with the mimetype of the sidecar file
				unset($sidecarData['type']);
			}
		} catch (\Exception $e) {
			// Use Php native tools
			Logs::error(__METHOD__, __LINE__, $e->getMessage());
			$reader = Reader::factory(Reader::TYPE_NATIVE);
			$exif = $reader->read($filename);
		}

If now the any of the following lines fails, we fall back to native exif data extraction.

			// if readlink($filename) == False then $realFile = $filename.
			// if readlink($filename) != False then $realFile = readlink($filename)
			$realFile = readlink($filename) ?: $filename;
			if (Configs::hasExiftool() && file_exists($realFile . '.xmp')) {
				// Don't use the same reader as the file in case it's a video
				$sidecarReader = Reader::factory(Reader::TYPE_EXIFTOOL);
				$sidecarData = $sidecarReader->read($realFile . '.xmp')->getData();


				// We don't want to overwrite the media's type with the mimetype of the sidecar file
				unset($sidecarData['type']);
			}

This is not, what we want (at least imho). I'd prefer the following fallbacks:

  1. If exif data extraction (from image) fails using the defined extraction tool, we fall back to the native tool
  2. If the sidecar data extraction tool fails, we simply do nothing. The already extracted data should remain untouched.

The current behavior causes some troubles for the heic support #574 .

@alex-phillips @ildyria What do you think?

@ildyria
Copy link
Member

ildyria commented May 24, 2020

I'd prefer the following fallbacks:

  1. If exif data extraction (from image) fails using the defined extraction tool, we fall back to the native tool
  2. If the sidecar data extraction tool fails, we simply do nothing. The already extracted data should remain untouched.

No strong opinion from my side. I'm fine with your fallback.

@d7415
Copy link
Contributor

d7415 commented May 24, 2020

2. If the sidecar data extraction tool fails, we simply do nothing. The already extracted data should remain untouched.

If it exists, yes. On first pass it should probably fall back to the image metadata though?

@alex-phillips
Copy link
Contributor

@tmp-hallenser That's a good point. If the EXIF succeeds but sidecar fails, it reverts falls into the catch. I can submit a PR with modified changes so that each of the 'try' extractions are self-contained.

@alex-phillips
Copy link
Contributor

PR here: #597

@ildyria
Copy link
Member

ildyria commented May 26, 2020

done.

@ildyria ildyria closed this as completed May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants