Python doesn't work properly with exiftool

Started by Faramy, March 07, 2023, 01:19:38 AM

Previous topic - Next topic

StarGeek

Quote from: Faramy on March 09, 2023, 11:32:51 AMThe problem, as I understand it, is the inability to create a second temporary file, since it already exists:
Error renaming temporary file

Only I don't understand why it creates a temporary file. Isn't it possible to write directly to a file?

Exiftool always creates a new file and renames the old one once it the write returns that the operation has been successfully completed.  See FAQ #31.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Faramy

Like another crutch - put between them
if os.path.exists(mov_file):
    time.sleep(10)

It works now.

StarGeek

You should probably look into PyExifTool.  It is a wrapper around exiftool that keeps exiftool running in the background.  This can speed up the process, especially where there are a lot of files.  You should also try condensing the writes.  For example, rather than write Title and Description separately, write them both at the same time.

See the second paragraph in this post.  tl;dr, it took an hour for a person running exiftool once per file on 5k files, while my single command took only 6 minutes.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Faramy

Thank you for your advice.
Unfortunately, I did not see an example there, how you managed to run exiftool before the start of the loop, and just execute scripts in the loop.

Faramy

It turns out that everything is very simple:

with ExifToolHelper() as et:
    et.set_tags(image,
        tags={"XMP:Title": result, "XMP:Description": result},
        params=["-P", "-overwrite_original"]
    )

Thank you again. Now I will try it in practice. :)