public function getUUID($generate = false, $write = false)
    {
        if ($this->uuid && !$write) {
            return $this->uuid;
        }

        $availableUUIDs = [
            'XMP-exif:ImageUniqueID',
            'SigmaRaw:ImageUniqueID',
            'IPTC:UniqueDocumentID',
            'ExifIFD:ImageUniqueID',
            'Canon:ImageUniqueID',
            'XMP-xmpMM:DocumentID',
        ];

        if (!$this->uuid) {
            $metadatas = $this->media->getMetadatas();

            $uuid = null;

            foreach ($availableUUIDs as $meta) {
                if ($metadatas->containsKey($meta)) {
                    $candidate = $metadatas->get($meta)->getValue()->asString();
                    if(in_array($meta, self::$xmpTag)){
                        $candidate = self::sanitizeXmpUuid($candidate);
                    }
                    if (Uuid::isValid($candidate)) {
                        $uuid = $candidate;
                        break;
                    }
                }
            }

            if (!$uuid && $generate) {
                $uuid = Uuid::uuid4();
            }

            $this->uuid = $uuid;
        }

        if ($write) {
            $value = new MonoValue($this->uuid);
            $metadatas = new ExiftoolMetadataBag();

            foreach ($availableUUIDs as $tagname) {
                $metadatas->add(new Metadata(TagFactory::getFromRDFTagname($tagname), $value));
            }

            try {
                $writer = $this->app['exiftool.writer'];
                $writer->reset();
                $writer->write($this->getFile()->getRealPath(), $metadatas);
            } catch (PHPExiftoolException $e) {
                // PHPExiftool throws exception on some files not supported
            }
        }

        return $this->uuid;
    }