# EXIF Metadata photo merger and organiser (Chrome Extension)

**Version 5.0.6** — EXIF Metadata photo merger and organiser. Organize Google Takeout exports locally: extract zips, merge JSON metadata into photos (EXIF), organize by year and albums. Runs entirely in the browser; no server, no app download.

## What it does

- **Extract** Takeout ZIPs into your chosen output (Lake folder).
- **Merge** metadata from Google JSON into JPEG (date, GPS, comment); copy videos and other files.
- **Organize** by year and Google albums; optionally create album folders with manifest and maps.
- **Map** — World map of photo locations (OpenStreetMap) with **clustered markers** for fast loading. Map and location DB (`map_data.json`) **accumulate** when you run Start Processing again with more photos.
- All processing is **local**; your files never leave your computer.

## How to use

1. **Install** the extension: [Chrome Web Store](https://chromewebstore.google.com/detail/exif-metadata-photo-merge/cchhnocflgfioicpcefcbbfbpgohgdkn) (Add to Chrome) or load unpacked from this folder.
2. Click the extension icon — the UI opens in a **new tab**.
3. **Select Input Folder** — choose the folder that contains your Takeout zips and/or already-extracted media and JSON.
4. Optionally open **Advanced options** to set output folder, extract/delete options, album maps, **World map**, duplicate detection, verbose logging.
5. Click **Start Processing**. Progress and summary appear in the right panel. When done, open `Processed/map.html` from your output folder to view the photo map (clustered).

**Map and DB accumulation:** If you run Start Processing again (e.g. after adding more photos), the extension loads existing `map_data.json`, merges new locations, dedupes, and writes updated `map_data.json` and `map.html`. The map stays fast thanks to **Leaflet.markercluster**.

## Tech stack

- **ZIP:** [fflate](https://github.com/101arrowz/fflate) — unzip in the browser.
- **EXIF:** Custom inject — build EXIF from Google JSON (`photoTakenTime`, `geoDataExif`), inject into JPEG.
- **Map:** Leaflet 1.9.4 + Leaflet.markercluster 1.5.3 (clustered markers, chunked loading).
- **File access:** File System Access API — user selects folder(s) via picker; no arbitrary disk access.

## Project structure

```
Gphoto_organiser_JS/
├── manifest.json         # Chrome Extension Manifest V3
├── background.js         # Opens UI in new tab on icon click
├── popup/
│   ├── popup.html        # Main UI (opened in tab)
│   ├── popup.css
│   └── popup.js
├── lib/
│   ├── exif.js           # EXIF inject / read from JSON and JPEG
│   ├── media-index.js    # Media/metadata index
│   ├── pipeline.js       # Orchestration
│   ├── pipeline/         # Extract, index, merge, report, albums-maps
│   ├── zip.js
│   └── fflate.min.js
├── web/                  # About, index, ratings; extension zip output
├── scripts/
│   ├── pack-extension.js # Build extension zip for Netlify/Chrome Web Store
│   ├── build-photo-db.js # Node: scan Processed folder → photo_db.json + map_data.json
│   ├── generate-test-map.js # Node: map_data.json → map.html (clustered)
│   └── README-build-photo-db.md
├── docs/                 # TO_DO.md, PHOTO_MAP_PHASE.md, etc.
└── icons/
```

## Development

### Load unpacked

1. Chrome → `chrome://extensions` → enable **Developer mode**.
2. **Load unpacked** → select this folder (with `manifest.json`).
3. Click the extension icon to open the UI in a new tab.

After code changes: reload the extension on `chrome://extensions`, then refresh the UI tab.

### Scripts (Node, from repo root)

- **Build photo DB** from a Processed folder (e.g. for testing map without running the full pipeline):
  ```bash
  node scripts/build-photo-db.js [pathToProcessed]
  ```
  Writes `photo_db.json` and `map_data.json` in that folder. Use `--skip-exif` to use only JSON for geo (faster).

- **Generate map.html** (clustered map) from `map_data.json`:
  ```bash
  node scripts/generate-test-map.js [pathToProcessed]
  ```
  Writes `map.html` in that folder. Open in a browser (keep file in Processed so image paths work).

- **Pack extension** for distribution:
  ```bash
  npm run pack
  ```
  Writes `web/EXIF Metadata photo merger_extension.zip`.

### Tests

```bash
npm install
npm test
```

## Privacy

All processing is local. No server calls for core logic; no upload of photos or metadata.
