smarnach / pyexiftool

a Python library to communicate with an instance of Phil Harvey's excellent ExifTool command-line application.
Other
270 stars 111 forks source link

execute() runs but doesn't write tags #38

Open martimpassos opened 2 years ago

martimpassos commented 2 years ago

Hello, I'm using the following code to embed metadata to JPEGs:

def embed_metadata(self):
        with ExifTool(executable_=os.environ["EXIFTOOL"]) as et:
            for param in self.__metadata:
                param = param.encode(encoding="utf-8")
                dest = os.path.join(os.environ["JPG"], self.__jpg).encode(
                    encoding="utf-8"
                )
                et.execute(param, dest)

It runs fine, but nothing really happens. No tags get embedded and no jpg_original files are created, as it happened before with an almost identical function. I have checked the tags content and the destination is built correctly. What am I missing here?

martimpassos commented 2 years ago

I'm running this code on WSL but pointing to the Windows executable. Could this be the issue?

EXIFTOOL=/mnt/c/exiftool.exe

This was the case before too though. I'm just refactoring some code, but locations remain the same.

sylikc commented 2 years ago

There might be some problems with your self.__metadata. Also, this isn't the most efficient way to do this... you should embed the metadata all at once one one execute instead of doing like len(self.__metadata) disk writes.

martimpassos commented 2 years ago

Hi @sylikc thanks for getting back. I'll probably substitute my exiftool.py for your branch's.

However, I have checked the values inside self.__metadata and they're all strings exactly equal to the ones I've been using this far (such as "-GPSLatitudeRef=S"). As for the most efficient way to call execute, can you please confirm this is what I'm looking for? The documentation isn't really clear about how to set tags rather than getting them...

execute(["list","of","params"],dest)

If

This is considered a low-level method, and should rarely be needed by application developers.

, what is the best way to write tags to files?

sylikc commented 2 years ago

So... that .execute() comment... you can safely ignore it for setting tags... I think to set tags, that's the best way to do it...

you should be probably doing .execute(*self.__metadata, dest)

That will make exiftool do it all at once, instead of writing to the file like a zillion times. You'll probably have to encode individual parameters though.