Skip to content

Commit

Permalink
Fixed bug w/ overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsakkos committed Dec 24, 2024
1 parent e44f7de commit 140f17c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,32 @@ source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e ".[dev]"
```

3. Download the Foundation List file and place it in the project directory.

## Usage
## CLI Usage

1. Close Lightroom Classic if it's running

2. Modify the catalog path in the script to point to your Lightroom catalog:
```python
catalog_path = "path/to/your/catalog.lrcat"
2. Run the CLI and point to your Lightroom catalog file or directory of images:
```bash
lr-autotag --catalog "path/to/catalog.lrcat"
```

3. Run the script:
```bash
python lightroom-tagger.py
lr-autotag --images "path/to/images"
```

The script will:
- Scan your Lightroom catalog for images
- Generate AI keywords for each image
- Create or update XMP sidecar files with the new keywords
- Save a JSON report of all suggestions
3. Open Lightroom Classic and wait for the catalog to reload
4. Load the XMP sidecar files to see the generated keywords
5. Enjoy your newly tagged images!

### Options

- `--catalog` or `-c`: Path to the Lightroom catalog file
- `--images` or `-i`: Path to a directory of images
- `--threshold` or `-t`: Confidence threshold for keyword suggestions (default: 0.5)
- `--max_keywords` or `-m`: Maximum number of keywords per image (default: 20)
- `--max_size` or `-s`: Maximum image dimension for processing (default: 1024)
- `--help` or `-h`: Show help message


### Important Notes
- Always ensure you have enough disk space for catalog backups
Expand Down
7 changes: 4 additions & 3 deletions src/lr_autotag/tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,16 @@ def update_xmp_sidecar(self, image_path, keywords, overwrite=False):
bag = ET.SubElement(
subject, "{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Bag"
)

# Get existing keywords
existing_keywords = set()
if overwrite:
# Clear all existing keywords
for item in bag.findall("{http://www.w3.org/1999/02/22-rdf-syntax-ns#}li"):
bag.remove(item)
all_keywords = set(keyword for keyword, _ in keywords)
new_keywords = all_keywords
else:
# Get existing keywords
existing_keywords = set()

for item in bag.findall("{http://www.w3.org/1999/02/22-rdf-syntax-ns#}li"):
if item.text:
existing_keywords.add(item.text.strip())
Expand Down

0 comments on commit 140f17c

Please sign in to comment.