Python doesn't work properly with exiftool

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

Previous topic - Next topic

Faramy

Hello.

The script has this line:
subprocess.run(f'exiftool.exe -Description="{result}" -overwrite_original "{image}"')
Some sites display Description normally.
And some sites (as I calculated by the number of characters) remove spaces, and show spaces instead of characters (by the number of characters.
That is, instead of
Curvy road with a sign in the middle of it.shows
                               
If you directly write the Description to the file, then everything is fine.

Is there a solution?

Faramy

Maybe there is some way to fix this?

I tried to resave, but to no avail.
exiftool.exe -P -overwrite_original "-Description<${Description}" "D:\."
How else can you overwrite the Description so that it is correctly saved?

Malus

This code is running fine on my site:

import subprocess
result = 'myresult'
image = r'd:\test\file.jpg'
_r = subprocess.run(f'exiftool.exe -Description="{result}" -overwrite_original "{image}"')
_r = subprocess.run(f'exiftool.exe -Description "{image}"', capture_output=True, text=True)
print(_r.stdout)
print(_r.stderr)

What's the value of your string "result".

Last, let me encourage you to try pyExiftool. It's using stay_open and much faster then running "subprocess.run(f'exiftool.exe . . .". several times in a loop.



Thanks for reading, malus



Faramy

Malus, thanks for the tip about pyExiftool. I will try it.
As for result, everything is recorded normally.
And Description is visible in exif. But here are some sites that do not see the Description, which was written in this way.

StarGeek

Quote from: Faramy on March 07, 2023, 08:36:51 AMAnd Description is visible in exif. But here are some sites that do not see the Description, which was written in this way.

Description is not an EXIF tag, it is an XMP tag, specifically a Dublin Core XMP-dc tag.  All EXIF data is metadata, but not all metadata is EXIF data.

Otherwise, this is FAQ #3. Exiftool has no control over what tags some website reads. Find a file that reads the data you want correctly and use the command in FAQ #3 to figure out what the actual tag you want to write is.
"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

Is it possible to simply resave the meta-information in the file? This should fix the bug.

It would be great if there was such a command.

Faramy

Now I looked more closely.
The uncorrected file has only "Description"
And in the corrected one, this name is still in the "Image Description"
I'll try the command:
exiftool.exe -P -overwrite_original "-Image Description<${Description}" "D:\."Warning: Invalid tag name 'image description' :(

Faramy

Tried -P -overwrite_original "-Description<${Title}" Output:
QuoteIPTCDigest is not current. XMP may be out of sync

Faramy

If I apply this JS, then the whole file is corrected:
        btnSave.onClick = function()
        {
            if ( app.document.selections.length == 1 )
            {
                editTitle = wrapper.editTitleRefs[0];
                new_title = editTitle.text;
                editDescr = wrapper.editDescrRefs[0];
                new_descr = editDescr.text;
                DescrToTitle = wrapper.chkCloneDescrBox[0];
                TitleToDescr = wrapper.chkCloneTitleBox[0];
                if ( DescrToTitle.value == true )
                    new_title = new_desct;
                if ( TitleToDescr.value == true )               
                    new_title = new_descr;
                editKeywords =  wrapper.editKeywordsRefs[0];
                new_subject = editKeywords.text.split(",");
                for (var k  =0 ; k < new_subject.length; k++)
                {
                        new_subject[k] = new_subject[k].trim();
                }
                saveMetadata(app.document.selections[0],
                                    new_title,
                                    new_descr,
                                    new_subject,
                                    { sort:wrapper.chkSortBox[0].value,
                                    append:false } );
                reselectFiles();
            }
            else
            {
                alert("Metadata save only for one file", "Error", errorIcon)
            }           
        }   

But I can only apply to one file.
I have to come up with something to apply to the whole folder.

Phil Harvey

Quote from: Faramy on March 08, 2023, 03:42:34 AMexiftool.exe -P -overwrite_original "-Image Description<${Description}" "D:\."Warning: Invalid tag name 'image description' :(

See FAQ 2.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Faramy

First of all, this is the error:
QuoteWarning: IPTCDigest is not current. XMP may be out of sync
Most likely, python somehow crookedly writes:
subprocess.run(f'exiftool.exe -Description="{result}" -overwrite_original "{image}"')

Faramy

In general, I found a way out. What is called - with crutches.
Suddenly someone will need it too. I leave it here:
1. In the same script that sends files to the server, I form a csv file from jpg files:
exiftool.exe -T -csv -Filename -Description -Subject ./*.jpg > CSV.csv2. I send this file along with pictures.
3. On the server, the csv file is processed and the Description is now normally visible!

Phil Harvey

The -T option has no effect when combined with -csv

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Quote from: Faramy on March 08, 2023, 03:18:30 AMThis should fix the bug.

Failing to see where you have shown there is a bug.

It appears more that you don't know what is the correct tag you want to write. Which is understandable given the complete mess of competing standards that is image metadata.

Obligatory xkcd
"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

#14
Thanks everyone for the help, but choosing with an intermediate csv works fine.

Now there is another problem:

    subprocess.run(f'C:/exiftool.exe -P -overwrite_original -Title="{result}" "{image}"')
    subprocess.run(f'C:/exiftool.exe -P -overwrite_original -Description="{result}" "{image}"')

If the file is .jpg, then it normally writes both in the Title and in the Description.

If the file is .mov - writes only in the Title. And the Description in the file remains empty. :(

And if I change places - it is written only in Description
    subprocess.run(f'C:/exiftool.exe -P -overwrite_original -Description="{result}" "{image}"')
    subprocess.run(f'C:/exiftool.exe -P -overwrite_original -Title="{result}" "{image}"')

The 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?