Search code examples
windowsmetadataexiftool

save tags in windows without manually setting at least one


I have this code to save the tags in 'tags' in "Details" tab in property of file of windows):

import exiftool

def add_tag_to_file(file_path, new_tag):
    with exiftool.ExifTool() as et:
        # Get existing tags
        metadata = et.execute_json("-j", file_path)
        if metadata:
            existing_tags = metadata[0].get("QuickTime:Category", '')
            if isinstance(existing_tags, str):
                existing_tags=existing_tags.split(";")
        else:
            existing_tags = []

        # Print existing tags
        print(f"Existing tags for {file_path}: {', '.join(existing_tags)}")
        saveTheTags=False
        if '' in existing_tags:
            existing_tags.remove('')
            saveTheTags=True
        if new_tag not in existing_tags:
            existing_tags.append(new_tag)
            saveTheTags=True
        else:
            print(f"Tag '{new_tag}' already exists in {file_path}.")
        if saveTheTags:
            formatted_tags = ";".join(existing_tags)
    
            # Save the new tags to the file
            et.execute(f"-QuickTime:Category={formatted_tags}", "-overwrite_original", file_path)
            print(f"Tag '{new_tag}' added to {file_path}.")

this code sets the tags to metadata[0]["QuickTime:Category"] of file. but doesnt show tags in 'tags' in "Details" tab in property of file when the at least one tag isnot manually set.

for i.e. if some tag like 'faf' is manually entered from windows ui, after adding tags with this code, they would be shown in 'tags' in "Details" tab in property of file. but otherwise the tags wont been shown even they have been set with this code to metadata[0]["QuickTime:Category"]

if you tried this code please tell me are you experiencing the same thing or not?

any other code with for setting 'tags' in "Details" tab in property of file of windows and doesnt have this problem, image and video files, are also appreciated.


Solution

  • You are setting the wrong tag. For Windows to fill the "Tags" property for videos, you want to set the Microsoft:Category tag, not the Quicktime:Category tag.

    See this exiftool forum post to see what tags Windows will read/write and the corresponding Property Details.