v0.8.1: improve XMP sidecars
This commit is contained in:
@@ -14,4 +14,7 @@
|
|||||||
- XMP sidecars are opt-in via `--sidecar xmp`; default must remain `none`.
|
- XMP sidecars are opt-in via `--sidecar xmp`; default must remain `none`.
|
||||||
- Reverse geocoding is opt-in via `--reverse-geocode`, uses MapKit on macOS 26+, and must fail safely on older macOS without failing export.
|
- Reverse geocoding is opt-in via `--reverse-geocode`, uses MapKit on macOS 26+, and must fail safely on older macOS without failing export.
|
||||||
- Do not claim Photos people/animal/object labels are exported unless Vision/Core ML analysis is explicitly implemented.
|
- Do not claim Photos people/animal/object labels are exported unless Vision/Core ML analysis is explicitly implemented.
|
||||||
|
- Roadmap: keep `0.8.x` focused on making XMP sidecars as rich, standard-compatible, and complete as possible from public PhotoKit metadata.
|
||||||
|
- Roadmap: use `0.9.0` through `0.9.5` for checksums, deep verification, manifest repair, cleanup, doctor, and backup-integrity hardening.
|
||||||
|
- Roadmap: start Vision/Core ML analysis only after `0.9.5`; keep it opt-in and label it as photoscli-generated analysis, not Apple Photos metadata.
|
||||||
- Do not commit generated artifacts from `bin/` or coverage files.
|
- Do not commit generated artifacts from `bin/` or coverage files.
|
||||||
|
|||||||
@@ -2,6 +2,16 @@
|
|||||||
|
|
||||||
This changelog is maintained from git history plus the published Gitea release series. Future releases should update this file and publish matching release notes on the release page.
|
This changelog is maintained from git history plus the published Gitea release series. Future releases should update this file and publish matching release notes on the release page.
|
||||||
|
|
||||||
|
## v0.8.1
|
||||||
|
|
||||||
|
XMP standards and sidecar verification release.
|
||||||
|
|
||||||
|
- Add XMP schema version metadata for generated sidecars.
|
||||||
|
- Add standard XMP fields for rating, metadata date, creation date, Photoshop date created, and EXIF GPS coordinates.
|
||||||
|
- Add `dc:subject` keywords from album/folder context.
|
||||||
|
- Add sidecar generator and generated timestamp metadata.
|
||||||
|
- Add `verify --sidecar` to check missing, zero-byte, unreadable, and asset-ID mismatched XMP sidecars.
|
||||||
|
|
||||||
## v0.8.0
|
## v0.8.0
|
||||||
|
|
||||||
Rich PhotoKit metadata and reverse-geocoded XMP release.
|
Rich PhotoKit metadata and reverse-geocoded XMP release.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
BINARY := ./bin/photoscli
|
BINARY := ./bin/photoscli
|
||||||
MODULE := gitea.k3s.k0.nu/tools/photocli
|
MODULE := gitea.k3s.k0.nu/tools/photocli
|
||||||
VERSION := 0.8.0
|
VERSION := 0.8.1
|
||||||
RELEASE_ZIP := ./bin/photoscli-$(VERSION)-macos-arm64.zip
|
RELEASE_ZIP := ./bin/photoscli-$(VERSION)-macos-arm64.zip
|
||||||
RELEASE_NOTES := RELEASE_NOTES.md
|
RELEASE_NOTES := RELEASE_NOTES.md
|
||||||
BRIDGE_DIR := bridge
|
BRIDGE_DIR := bridge
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ For a practical step-by-step manual with recommended backup workflows, recovery
|
|||||||
- Failure tracking with `failures.jsonl` and `retry-failed`.
|
- Failure tracking with `failures.jsonl` and `retry-failed`.
|
||||||
- Deduplicated failure management with `failures list`, `failures clear`, and `retry-failed --clear-on-success`.
|
- Deduplicated failure management with `failures list`, `failures clear`, and `retry-failed --clear-on-success`.
|
||||||
- Verification, reporting, and diff commands for backup integrity.
|
- Verification, reporting, and diff commands for backup integrity.
|
||||||
|
- Optional XMP sidecar verification with `verify --sidecar`.
|
||||||
- Status command for quick backup summaries.
|
- Status command for quick backup summaries.
|
||||||
- Opt-in rich XMP sidecar metadata with `--sidecar xmp`.
|
- Opt-in rich XMP sidecar metadata with `--sidecar xmp`.
|
||||||
- Optional Apple MapKit reverse geocoding for GPS assets on macOS 26+ with `--reverse-geocode`.
|
- Optional Apple MapKit reverse geocoding for GPS assets on macOS 26+ with `--reverse-geocode`.
|
||||||
@@ -269,6 +270,7 @@ Common flags for `export` and `backup-all`:
|
|||||||
- `--dry-run`: print planned exports without writing files, manifests, or logs.
|
- `--dry-run`: print planned exports without writing files, manifests, or logs.
|
||||||
- `--json`: print a machine-readable summary to stdout.
|
- `--json`: print a machine-readable summary to stdout.
|
||||||
- `--verify`: run manifest/file verification after export.
|
- `--verify`: run manifest/file verification after export.
|
||||||
|
- `--sidecar` with `verify`: also verify expected `.xmp` sidecars.
|
||||||
- `--log`: enable structured export logging.
|
- `--log`: enable structured export logging.
|
||||||
- `--manifest jsonl|sqlite`: choose manifest backend, default `jsonl`.
|
- `--manifest jsonl|sqlite`: choose manifest backend, default `jsonl`.
|
||||||
- `--no-manifest`: disable manifest reads/writes.
|
- `--no-manifest`: disable manifest reads/writes.
|
||||||
@@ -351,7 +353,13 @@ IMG_0001.HEIC -> IMG_0001.xmp
|
|||||||
|
|
||||||
The XMP contains photoscli metadata such as asset ID, filenames, album, manifest path, media type, dimensions, favorite state, cloud state, export mode, version, exported timestamp, size, and creation date when available. If `--sidecar xmp` is explicitly selected and the sidecar cannot be written, that asset is treated as failed.
|
The XMP contains photoscli metadata such as asset ID, filenames, album, manifest path, media type, dimensions, favorite state, cloud state, export mode, version, exported timestamp, size, and creation date when available. If `--sidecar xmp` is explicitly selected and the sidecar cannot be written, that asset is treated as failed.
|
||||||
|
|
||||||
In v0.8.0, sidecars also include richer public PhotoKit metadata where available: modification date, duration, hidden state, adjustment state, media subtypes, source type, playback style, burst data, GPS coordinates, adjustment info, and structured asset resources. Add `--reverse-geocode` to include cached address fields from Apple MapKit for assets with GPS coordinates. Reverse geocoding requires macOS 26 or newer; on older macOS versions the export continues and XMP still includes GPS coordinates.
|
Sidecars also include richer public PhotoKit metadata where available: modification date, duration, hidden state, adjustment state, media subtypes, source type, playback style, burst data, GPS coordinates, adjustment info, structured asset resources, standard XMP dates, EXIF GPS coordinates, favorite rating, and album/folder keywords. Add `--reverse-geocode` to include cached address fields from Apple MapKit for assets with GPS coordinates. Reverse geocoding requires macOS 26 or newer; on older macOS versions the export continues and XMP still includes GPS coordinates.
|
||||||
|
|
||||||
|
Verify generated sidecars with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
photoscli verify --out ./backup --sidecar
|
||||||
|
```
|
||||||
|
|
||||||
## Failure Tracking
|
## Failure Tracking
|
||||||
|
|
||||||
@@ -464,3 +472,9 @@ Objective-C returns JSON to Go. Tests use the stub bridge and do not require rea
|
|||||||
- Album title lookup uses exact title matching. Use PhotoKit local identifiers when names are ambiguous.
|
- Album title lookup uses exact title matching. Use PhotoKit local identifiers when names are ambiguous.
|
||||||
- iCloud-backed assets may trigger downloads and can fail due to network or account state.
|
- iCloud-backed assets may trigger downloads and can fail due to network or account state.
|
||||||
- `--min-size` and `--max-size` currently use estimated pixel count from dimensions, not encoded file size.
|
- `--min-size` and `--max-size` currently use estimated pixel count from dimensions, not encoded file size.
|
||||||
|
|
||||||
|
## Roadmap
|
||||||
|
|
||||||
|
- `0.8.x`: make XMP sidecars as rich, standard-compatible, and complete as possible from public PhotoKit metadata.
|
||||||
|
- `0.9.0` through `0.9.5`: checksums, deep verification, manifest repair, cleanup, doctor, and backup-integrity hardening.
|
||||||
|
- After `0.9.5`: opt-in Vision/Core ML analysis for photoscli-generated face/object/animal/scene metadata.
|
||||||
|
|||||||
+9
-9
@@ -1,20 +1,20 @@
|
|||||||
# v0.8.0
|
# v0.8.1
|
||||||
|
|
||||||
This release expands XMP sidecars with richer public PhotoKit metadata and adds optional reverse geocoding through Apple MapKit on macOS 26 or newer.
|
This release improves XMP sidecar standards compatibility and adds sidecar verification.
|
||||||
|
|
||||||
## Highlights
|
## Highlights
|
||||||
|
|
||||||
- XMP sidecars now include richer public PhotoKit metadata: modification date, duration, hidden state, adjustment state, media subtypes, source type, playback style, burst data, GPS coordinates, adjustment info, and structured asset resources when available.
|
- Add `photoscli:xmpSchemaVersion="2"` to generated XMP sidecars.
|
||||||
- Add `--reverse-geocode` to enrich GPS assets with cached address metadata from Apple MapKit on macOS 26+.
|
- Add standard XMP mappings for favorite rating, metadata date, Photoshop date created, and EXIF GPS coordinates.
|
||||||
- On older macOS versions, reverse geocoding is skipped safely; export continues and GPS coordinates remain in XMP.
|
- Add `dc:subject` keywords from album/folder context.
|
||||||
- Reverse-geocode cache is stored under `.photoscli/geocode-cache.jsonl` in the backup root.
|
- Add sidecar generator and generated timestamp metadata.
|
||||||
- Existing `--sidecar xmp` behavior remains opt-in and atomic; sidecar write failure still fails that asset.
|
- Add `verify --sidecar` for missing, zero-byte, unreadable, and asset-ID mismatched XMP sidecars.
|
||||||
- Vision/Core ML people, animal, object, and scene analysis is not included in this release.
|
- Keep Vision/Core ML people, animal, object, and scene analysis out of this release.
|
||||||
|
|
||||||
## Assets
|
## Assets
|
||||||
|
|
||||||
- `photoscli`: Apple Silicon macOS binary (`darwin/arm64`).
|
- `photoscli`: Apple Silicon macOS binary (`darwin/arm64`).
|
||||||
- `photoscli-0.8.0-macos-arm64.zip`: Apple Silicon binary plus README, USERGUIDE, and CHANGELOG.
|
- `photoscli-0.8.1-macos-arm64.zip`: Apple Silicon binary plus README, USERGUIDE, and CHANGELOG.
|
||||||
- `USERGUIDE.md`: standalone user guide.
|
- `USERGUIDE.md`: standalone user guide.
|
||||||
|
|
||||||
Intel Macs are not currently a supported release target.
|
Intel Macs are not currently a supported release target.
|
||||||
|
|||||||
+9
-1
@@ -555,7 +555,7 @@ IMG_0001.jpg -> IMG_0001.xmp
|
|||||||
IMG_0001.HEIC -> IMG_0001.xmp
|
IMG_0001.HEIC -> IMG_0001.xmp
|
||||||
```
|
```
|
||||||
|
|
||||||
The XMP includes photoscli archive metadata such as asset ID, original filename, exported filename, album, manifest path, media type, dimensions, favorite state, hidden state, cloud state, export mode, version, exported time, size, creation date, modification date, duration, adjustment state, media subtypes, source type, playback style, burst data, GPS coordinates, adjustment info, and structured asset resources when PhotoKit exposes them.
|
The XMP includes photoscli archive metadata such as asset ID, original filename, exported filename, album, manifest path, media type, dimensions, favorite state, hidden state, cloud state, export mode, version, exported time, size, creation date, modification date, duration, adjustment state, media subtypes, source type, playback style, burst data, GPS coordinates, adjustment info, structured asset resources, standard XMP date fields, EXIF GPS fields, favorite rating, and album/folder keywords when PhotoKit exposes them.
|
||||||
|
|
||||||
For address metadata from GPS coordinates, opt in to Apple's reverse geocoder:
|
For address metadata from GPS coordinates, opt in to Apple's reverse geocoder:
|
||||||
|
|
||||||
@@ -565,6 +565,14 @@ For address metadata from GPS coordinates, opt in to Apple's reverse geocoder:
|
|||||||
|
|
||||||
Reverse geocoding uses Apple MapKit and requires macOS 26 or newer. It can require network access and may be rate-limited by Apple, so results are cached in `.photoscli/geocode-cache.jsonl` under the backup root. On older macOS versions, `--reverse-geocode` is treated as unavailable: the export continues, no address fields are added, and the XMP still contains GPS coordinates.
|
Reverse geocoding uses Apple MapKit and requires macOS 26 or newer. It can require network access and may be rate-limited by Apple, so results are cached in `.photoscli/geocode-cache.jsonl` under the backup root. On older macOS versions, `--reverse-geocode` is treated as unavailable: the export continues, no address fields are added, and the XMP still contains GPS coordinates.
|
||||||
|
|
||||||
|
Verify sidecars after an export:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./bin/photoscli verify --out ./PhotosBackup --sidecar
|
||||||
|
```
|
||||||
|
|
||||||
|
This reports missing, zero-byte, unreadable, or asset-ID mismatched `.xmp` files.
|
||||||
|
|
||||||
If you explicitly request `--sidecar xmp` and the XMP file cannot be written, the asset is counted as failed.
|
If you explicitly request `--sidecar xmp` and the XMP file cannot be written, the asset is counted as failed.
|
||||||
|
|
||||||
## Configuration File
|
## Configuration File
|
||||||
|
|||||||
+75
-2
@@ -25,6 +25,8 @@ var (
|
|||||||
mkdirTempFunc = os.MkdirTemp
|
mkdirTempFunc = os.MkdirTemp
|
||||||
createTempFunc = os.CreateTemp
|
createTempFunc = os.CreateTemp
|
||||||
writeFileFunc = os.WriteFile
|
writeFileFunc = os.WriteFile
|
||||||
|
readFileFunc = os.ReadFile
|
||||||
|
statFunc = os.Stat
|
||||||
renameFunc = os.Rename
|
renameFunc = os.Rename
|
||||||
openFileFunc = os.OpenFile
|
openFileFunc = os.OpenFile
|
||||||
removeFunc = os.Remove
|
removeFunc = os.Remove
|
||||||
@@ -165,6 +167,7 @@ COMMANDS
|
|||||||
verify --out <dir> [--manifest jsonl|sqlite]
|
verify --out <dir> [--manifest jsonl|sqlite]
|
||||||
Verify that manifest entries point to files that exist on disk. Missing
|
Verify that manifest entries point to files that exist on disk. Missing
|
||||||
files are printed as <asset-id><TAB><filename>. Exits 2 on missing files.
|
files are printed as <asset-id><TAB><filename>. Exits 2 on missing files.
|
||||||
|
Add --sidecar to verify expected XMP sidecars too.
|
||||||
|
|
||||||
retry-failed --out <dir>
|
retry-failed --out <dir>
|
||||||
Retry assets previously written to failures.jsonl.
|
Retry assets previously written to failures.jsonl.
|
||||||
@@ -752,6 +755,7 @@ type xmpSidecarData struct {
|
|||||||
ExportedFilename string
|
ExportedFilename string
|
||||||
Album string
|
Album string
|
||||||
AlbumPath string
|
AlbumPath string
|
||||||
|
Keywords []string
|
||||||
ManifestPath string
|
ManifestPath string
|
||||||
MediaType string
|
MediaType string
|
||||||
MediaSubtypes []string
|
MediaSubtypes []string
|
||||||
@@ -843,6 +847,7 @@ func sidecarPath(exportedPath string) string {
|
|||||||
|
|
||||||
func renderXMP(d xmpSidecarData) []byte {
|
func renderXMP(d xmpSidecarData) []byte {
|
||||||
attrs := []struct{ key, val string }{
|
attrs := []struct{ key, val string }{
|
||||||
|
{"photoscli:xmpSchemaVersion", "2"},
|
||||||
{"photoscli:assetID", d.AssetID},
|
{"photoscli:assetID", d.AssetID},
|
||||||
{"photoscli:originalFilename", d.OriginalFilename},
|
{"photoscli:originalFilename", d.OriginalFilename},
|
||||||
{"photoscli:exportedFilename", d.ExportedFilename},
|
{"photoscli:exportedFilename", d.ExportedFilename},
|
||||||
@@ -866,9 +871,18 @@ func renderXMP(d xmpSidecarData) []byte {
|
|||||||
{"photoscli:exportedAt", d.ExportedAt},
|
{"photoscli:exportedAt", d.ExportedAt},
|
||||||
{"photoscli:size", fmt.Sprintf("%d", d.Size)},
|
{"photoscli:size", fmt.Sprintf("%d", d.Size)},
|
||||||
{"dc:title", d.ExportedFilename},
|
{"dc:title", d.ExportedFilename},
|
||||||
|
{"xmp:MetadataDate", d.ExportedAt},
|
||||||
|
{"photoscli:sidecarGeneratedAt", d.ExportedAt},
|
||||||
|
{"photoscli:sidecarGenerator", "photoscli " + d.PhotoscliVersion},
|
||||||
|
}
|
||||||
|
if d.IsFavorite {
|
||||||
|
attrs = append(attrs, struct{ key, val string }{"xmp:Rating", "5"})
|
||||||
}
|
}
|
||||||
if d.CreateDate != "" {
|
if d.CreateDate != "" {
|
||||||
attrs = append(attrs, struct{ key, val string }{"xmp:CreateDate", d.CreateDate})
|
attrs = append(attrs,
|
||||||
|
struct{ key, val string }{"xmp:CreateDate", d.CreateDate},
|
||||||
|
struct{ key, val string }{"photoshop:DateCreated", d.CreateDate},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if d.ModifyDate != "" {
|
if d.ModifyDate != "" {
|
||||||
attrs = append(attrs, struct{ key, val string }{"xmp:ModifyDate", d.ModifyDate})
|
attrs = append(attrs, struct{ key, val string }{"xmp:ModifyDate", d.ModifyDate})
|
||||||
@@ -879,6 +893,9 @@ func renderXMP(d xmpSidecarData) []byte {
|
|||||||
struct{ key, val string }{"photoscli:longitude", fmt.Sprintf("%.8f", d.Location.Longitude)},
|
struct{ key, val string }{"photoscli:longitude", fmt.Sprintf("%.8f", d.Location.Longitude)},
|
||||||
struct{ key, val string }{"photoscli:altitude", fmt.Sprintf("%.3f", d.Location.Altitude)},
|
struct{ key, val string }{"photoscli:altitude", fmt.Sprintf("%.3f", d.Location.Altitude)},
|
||||||
struct{ key, val string }{"photoscli:horizontalAccuracy", fmt.Sprintf("%.3f", d.Location.HorizontalAccuracy)},
|
struct{ key, val string }{"photoscli:horizontalAccuracy", fmt.Sprintf("%.3f", d.Location.HorizontalAccuracy)},
|
||||||
|
struct{ key, val string }{"exif:GPSLatitude", fmt.Sprintf("%.8f", d.Location.Latitude)},
|
||||||
|
struct{ key, val string }{"exif:GPSLongitude", fmt.Sprintf("%.8f", d.Location.Longitude)},
|
||||||
|
struct{ key, val string }{"exif:GPSAltitude", fmt.Sprintf("%.3f", d.Location.Altitude)},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if d.Placemark != nil {
|
if d.Placemark != nil {
|
||||||
@@ -906,7 +923,7 @@ func renderXMP(d xmpSidecarData) []byte {
|
|||||||
sb.WriteString("<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n")
|
sb.WriteString("<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n")
|
||||||
sb.WriteString("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\">\n")
|
sb.WriteString("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\">\n")
|
||||||
sb.WriteString(" <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n")
|
sb.WriteString(" <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n")
|
||||||
sb.WriteString(" <rdf:Description xmlns:photoscli=\"https://gitea.k3s.k0.nu/tools/photocli/ns/1.0/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\"")
|
sb.WriteString(" <rdf:Description xmlns:photoscli=\"https://gitea.k3s.k0.nu/tools/photocli/ns/1.0/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\" xmlns:exif=\"http://ns.adobe.com/exif/1.0/\" xmlns:photoshop=\"http://ns.adobe.com/photoshop/1.0/\"")
|
||||||
for _, a := range attrs {
|
for _, a := range attrs {
|
||||||
sb.WriteString("\n ")
|
sb.WriteString("\n ")
|
||||||
sb.WriteString(a.key)
|
sb.WriteString(a.key)
|
||||||
@@ -915,6 +932,7 @@ func renderXMP(d xmpSidecarData) []byte {
|
|||||||
sb.WriteString("\"")
|
sb.WriteString("\"")
|
||||||
}
|
}
|
||||||
sb.WriteString(" >\n")
|
sb.WriteString(" >\n")
|
||||||
|
writeStringSeq(&sb, "dc:subject", d.Keywords)
|
||||||
writeStringSeq(&sb, "photoscli:mediaSubtypes", d.MediaSubtypes)
|
writeStringSeq(&sb, "photoscli:mediaSubtypes", d.MediaSubtypes)
|
||||||
writeStringSeq(&sb, "photoscli:burstSelectionTypes", d.BurstSelectionTypes)
|
writeStringSeq(&sb, "photoscli:burstSelectionTypes", d.BurstSelectionTypes)
|
||||||
writeStringSeq(&sb, "photoscli:areasOfInterest", func() []string {
|
writeStringSeq(&sb, "photoscli:areasOfInterest", func() []string {
|
||||||
@@ -931,6 +949,24 @@ func renderXMP(d xmpSidecarData) []byte {
|
|||||||
return []byte(sb.String())
|
return []byte(sb.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func keywordsFromAlbumPath(album, albumPath string) []string {
|
||||||
|
seen := map[string]bool{}
|
||||||
|
var out []string
|
||||||
|
add := func(v string) {
|
||||||
|
v = strings.TrimSpace(v)
|
||||||
|
if v == "" || v == "." || seen[v] {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
seen[v] = true
|
||||||
|
out = append(out, v)
|
||||||
|
}
|
||||||
|
add(album)
|
||||||
|
for _, part := range strings.Split(filepath.ToSlash(albumPath), "/") {
|
||||||
|
add(part)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
func writeStringSeq(sb *strings.Builder, name string, vals []string) {
|
func writeStringSeq(sb *strings.Builder, name string, vals []string) {
|
||||||
if len(vals) == 0 {
|
if len(vals) == 0 {
|
||||||
return
|
return
|
||||||
@@ -999,6 +1035,10 @@ func writeSidecarIfNeeded(pa pendingAsset, result photos.ExportResult, originals
|
|||||||
if err != nil || strings.HasPrefix(relPath, "..") {
|
if err != nil || strings.HasPrefix(relPath, "..") {
|
||||||
relPath = result.Filename
|
relPath = result.Filename
|
||||||
}
|
}
|
||||||
|
relDir, err := filepath.Rel(root, pa.path)
|
||||||
|
if err != nil || strings.HasPrefix(relDir, "..") || relDir == "." {
|
||||||
|
relDir = ""
|
||||||
|
}
|
||||||
createDate := ""
|
createDate := ""
|
||||||
if pa.asset.CreationDate != nil {
|
if pa.asset.CreationDate != nil {
|
||||||
createDate = *pa.asset.CreationDate
|
createDate = *pa.asset.CreationDate
|
||||||
@@ -1017,6 +1057,7 @@ func writeSidecarIfNeeded(pa pendingAsset, result photos.ExportResult, originals
|
|||||||
ExportedFilename: result.Filename,
|
ExportedFilename: result.Filename,
|
||||||
Album: pa.album,
|
Album: pa.album,
|
||||||
AlbumPath: pa.path,
|
AlbumPath: pa.path,
|
||||||
|
Keywords: keywordsFromAlbumPath(pa.album, relDir),
|
||||||
ManifestPath: relPath,
|
ManifestPath: relPath,
|
||||||
MediaType: pa.asset.MediaType,
|
MediaType: pa.asset.MediaType,
|
||||||
MediaSubtypes: pa.asset.MediaSubtypes,
|
MediaSubtypes: pa.asset.MediaSubtypes,
|
||||||
@@ -1963,6 +2004,7 @@ func cmdDiff(args []string, stdout, stderr io.Writer, bridge photos.Bridge) int
|
|||||||
|
|
||||||
func cmdVerify(args []string, stdout, stderr io.Writer) int {
|
func cmdVerify(args []string, stdout, stderr io.Writer) int {
|
||||||
outDir := flagVal(args, "--out")
|
outDir := flagVal(args, "--out")
|
||||||
|
checkSidecar := hasFlag(args, "--sidecar")
|
||||||
if outDir == "" {
|
if outDir == "" {
|
||||||
fmt.Fprintln(stderr, "error: --out is required")
|
fmt.Fprintln(stderr, "error: --out is required")
|
||||||
return exitErr
|
return exitErr
|
||||||
@@ -2001,6 +2043,9 @@ func cmdVerify(args []string, stdout, stderr io.Writer) int {
|
|||||||
bad++
|
bad++
|
||||||
fmt.Fprintf(stdout, "%s\t%s\tsize-mismatch\tmanifest=%d\tdisk=%d\n", id, checkPath, e.Size, info.Size())
|
fmt.Fprintf(stdout, "%s\t%s\tsize-mismatch\tmanifest=%d\tdisk=%d\n", id, checkPath, e.Size, info.Size())
|
||||||
}
|
}
|
||||||
|
if checkSidecar {
|
||||||
|
bad += verifySidecar(stdout, outDir, id, checkPath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if bad > 0 {
|
if bad > 0 {
|
||||||
return exitPartial
|
return exitPartial
|
||||||
@@ -2009,6 +2054,34 @@ func cmdVerify(args []string, stdout, stderr io.Writer) int {
|
|||||||
return exitOK
|
return exitOK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func verifySidecar(stdout io.Writer, outDir, id, checkPath string) int {
|
||||||
|
xmpPath := sidecarPath(filepath.Join(outDir, checkPath))
|
||||||
|
rel, err := filepath.Rel(outDir, xmpPath)
|
||||||
|
if err != nil || strings.HasPrefix(rel, "..") {
|
||||||
|
rel = xmpPath
|
||||||
|
}
|
||||||
|
info, err := statFunc(xmpPath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(stdout, "%s\t%s\tsidecar-missing\n", id, rel)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if info.Size() == 0 {
|
||||||
|
fmt.Fprintf(stdout, "%s\t%s\tsidecar-zero-byte\n", id, rel)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
data, err := readFileFunc(xmpPath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(stdout, "%s\t%s\tsidecar-unreadable\n", id, rel)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
needle := `photoscli:assetID="` + id + `"`
|
||||||
|
if !strings.Contains(string(data), needle) {
|
||||||
|
fmt.Fprintf(stdout, "%s\t%s\tsidecar-asset-mismatch\n", id, rel)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
func cmdRetryFailed(args []string, stdout, stderr io.Writer, bridge photos.Bridge) int {
|
func cmdRetryFailed(args []string, stdout, stderr io.Writer, bridge photos.Bridge) int {
|
||||||
outDir := flagVal(args, "--out")
|
outDir := flagVal(args, "--out")
|
||||||
clearOnSuccess := hasFlag(args, "--clear-on-success")
|
clearOnSuccess := hasFlag(args, "--clear-on-success")
|
||||||
|
|||||||
@@ -3835,6 +3835,13 @@ func TestReportDiffVerifyRetryFailedAndConfig(t *testing.T) {
|
|||||||
if rc != exitOK || !strings.Contains(out, "verified") || stderr != "" {
|
if rc != exitOK || !strings.Contains(out, "verified") || stderr != "" {
|
||||||
t.Fatalf("verify rc=%d out=%q stderr=%q", rc, out, stderr)
|
t.Fatalf("verify rc=%d out=%q stderr=%q", rc, out, stderr)
|
||||||
}
|
}
|
||||||
|
if err := os.WriteFile(filepath.Join(dir, "file.xmp"), renderXMP(xmpSidecarData{AssetID: "x1", ExportedFilename: "file.jpg"}), 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
out, stderr, rc = runWith([]string{"verify", "--out", dir, "--sidecar"}, &mockBridge{})
|
||||||
|
if rc != exitOK || !strings.Contains(out, "verified") || stderr != "" {
|
||||||
|
t.Fatalf("verify sidecar rc=%d out=%q stderr=%q", rc, out, stderr)
|
||||||
|
}
|
||||||
|
|
||||||
b := &mockBridge{albums: []photos.Album{{ID: "a1", Title: "Album"}}, assets: []photos.Asset{{ID: "x1", Filename: "file.jpg"}, {ID: "x2", Filename: "missing.jpg"}}}
|
b := &mockBridge{albums: []photos.Album{{ID: "a1", Title: "Album"}}, assets: []photos.Asset{{ID: "x1", Filename: "file.jpg"}, {ID: "x2", Filename: "missing.jpg"}}}
|
||||||
out, _, rc = runWith([]string{"diff", "--album-id", "Album", "--out", dir}, b)
|
out, _, rc = runWith([]string{"diff", "--album-id", "Album", "--out", dir}, b)
|
||||||
@@ -4133,6 +4140,8 @@ func TestMoreIntegrityBranches(t *testing.T) {
|
|||||||
}
|
}
|
||||||
m.AddEntry(manifest.Entry{ID: "zero", Filename: "zero.jpg", Path: "zero.jpg", Size: 1, Cloud: "local", Exported: time.Now().Unix()})
|
m.AddEntry(manifest.Entry{ID: "zero", Filename: "zero.jpg", Path: "zero.jpg", Size: 1, Cloud: "local", Exported: time.Now().Unix()})
|
||||||
m.AddEntry(manifest.Entry{ID: "mismatch", Filename: "mismatch.jpg", Path: "mismatch.jpg", Size: 10, Cloud: "local", Exported: time.Now().Unix()})
|
m.AddEntry(manifest.Entry{ID: "mismatch", Filename: "mismatch.jpg", Path: "mismatch.jpg", Size: 10, Cloud: "local", Exported: time.Now().Unix()})
|
||||||
|
m.AddEntry(manifest.Entry{ID: "nosidecar", Filename: "nosidecar.jpg", Path: "nosidecar.jpg", Size: 4, Cloud: "local", Exported: time.Now().Unix()})
|
||||||
|
m.AddEntry(manifest.Entry{ID: "zerosidecar", Filename: "zerosidecar.jpg", Path: "zerosidecar.jpg", Size: 4, Cloud: "local", Exported: time.Now().Unix()})
|
||||||
m.Close()
|
m.Close()
|
||||||
if err := os.WriteFile(filepath.Join(dir, "zero.jpg"), nil, 0644); err != nil {
|
if err := os.WriteFile(filepath.Join(dir, "zero.jpg"), nil, 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -4140,10 +4149,30 @@ func TestMoreIntegrityBranches(t *testing.T) {
|
|||||||
if err := os.WriteFile(filepath.Join(dir, "mismatch.jpg"), []byte("bad"), 0644); err != nil {
|
if err := os.WriteFile(filepath.Join(dir, "mismatch.jpg"), []byte("bad"), 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if err := os.WriteFile(filepath.Join(dir, "nosidecar.jpg"), []byte("data"), 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(filepath.Join(dir, "zerosidecar.jpg"), []byte("data"), 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
out, _, rc := runWith([]string{"verify", "--out", dir}, &mockBridge{})
|
out, _, rc := runWith([]string{"verify", "--out", dir}, &mockBridge{})
|
||||||
if rc != exitPartial || !strings.Contains(out, "zero-byte") || !strings.Contains(out, "size-mismatch") {
|
if rc != exitPartial || !strings.Contains(out, "zero-byte") || !strings.Contains(out, "size-mismatch") {
|
||||||
t.Fatalf("verify rc=%d out=%q", rc, out)
|
t.Fatalf("verify rc=%d out=%q", rc, out)
|
||||||
}
|
}
|
||||||
|
if err := os.WriteFile(filepath.Join(dir, "mismatch.xmp"), []byte("wrong asset"), 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
out, _, rc = runWith([]string{"verify", "--out", dir, "--sidecar"}, &mockBridge{})
|
||||||
|
if rc != exitPartial || !strings.Contains(out, "sidecar-missing") || !strings.Contains(out, "sidecar-asset-mismatch") {
|
||||||
|
t.Fatalf("verify sidecar failures rc=%d out=%q", rc, out)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(filepath.Join(dir, "zerosidecar.xmp"), nil, 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
out, _, rc = runWith([]string{"verify", "--out", dir, "--sidecar"}, &mockBridge{})
|
||||||
|
if rc != exitPartial || !strings.Contains(out, "sidecar-zero-byte") {
|
||||||
|
t.Fatalf("verify zero sidecar rc=%d out=%q", rc, out)
|
||||||
|
}
|
||||||
_, stderr, rc := runWith([]string{"status"}, &mockBridge{})
|
_, stderr, rc := runWith([]string{"status"}, &mockBridge{})
|
||||||
if rc != exitErr || !strings.Contains(stderr, "--out") {
|
if rc != exitErr || !strings.Contains(stderr, "--out") {
|
||||||
t.Fatalf("status missing out rc=%d stderr=%q", rc, stderr)
|
t.Fatalf("status missing out rc=%d stderr=%q", rc, stderr)
|
||||||
@@ -4162,6 +4191,25 @@ func TestMoreIntegrityBranches(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVerifySidecarBranches(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
subdir := filepath.Join(dir, "sub")
|
||||||
|
if err := os.Mkdir(subdir, 0755); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
xmp := filepath.Join(dir, "asset.xmp")
|
||||||
|
if err := os.WriteFile(xmp, []byte(`photoscli:assetID="x1"`), 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
oldRead := readFileFunc
|
||||||
|
readFileFunc = func(string) ([]byte, error) { return nil, fmt.Errorf("read") }
|
||||||
|
var out bytes.Buffer
|
||||||
|
if got := verifySidecar(&out, subdir, "x1", "../asset.jpg"); got != 1 || !strings.Contains(out.String(), "sidecar-unreadable") {
|
||||||
|
t.Fatalf("expected unreadable with rel fallback, got=%d out=%q", got, out.String())
|
||||||
|
}
|
||||||
|
readFileFunc = oldRead
|
||||||
|
}
|
||||||
|
|
||||||
func TestXMPSidecarHelpers(t *testing.T) {
|
func TestXMPSidecarHelpers(t *testing.T) {
|
||||||
if got := sidecarPath("/tmp/IMG_0001.HEIC"); got != "/tmp/IMG_0001.xmp" {
|
if got := sidecarPath("/tmp/IMG_0001.HEIC"); got != "/tmp/IMG_0001.xmp" {
|
||||||
t.Fatalf("sidecar path = %q", got)
|
t.Fatalf("sidecar path = %q", got)
|
||||||
@@ -4172,6 +4220,7 @@ func TestXMPSidecarHelpers(t *testing.T) {
|
|||||||
ExportedFilename: "IMG_0001.jpg",
|
ExportedFilename: "IMG_0001.jpg",
|
||||||
Album: "A&B",
|
Album: "A&B",
|
||||||
AlbumPath: "/tmp/A&B",
|
AlbumPath: "/tmp/A&B",
|
||||||
|
Keywords: []string{"A&B", "Trips"},
|
||||||
ManifestPath: "A&B/IMG_0001.jpg",
|
ManifestPath: "A&B/IMG_0001.jpg",
|
||||||
MediaType: "image",
|
MediaType: "image",
|
||||||
MediaSubtypes: []string{"photoLive", `hdr&<>"`},
|
MediaSubtypes: []string{"photoLive", `hdr&<>"`},
|
||||||
@@ -4198,13 +4247,29 @@ func TestXMPSidecarHelpers(t *testing.T) {
|
|||||||
AdjustmentInfo: &photos.AdjustmentInfo{FormatIdentifier: "com.apple", FormatVersion: "1.0", BaseFilename: "base.heic"},
|
AdjustmentInfo: &photos.AdjustmentInfo{FormatIdentifier: "com.apple", FormatVersion: "1.0", BaseFilename: "base.heic"},
|
||||||
Resources: []photos.AssetResource{{Type: "photo", Filename: `res&.heic`, UTI: "public.heic", Local: true, Size: 99}},
|
Resources: []photos.AssetResource{{Type: "photo", Filename: `res&.heic`, UTI: "public.heic", Local: true, Size: 99}},
|
||||||
}))
|
}))
|
||||||
for _, want := range []string{"photoscli:assetID=\"id&<>"\"", "photoscli:isFavorite=\"true\"", "photoscli:hasAdjustments=\"true\"", "xmp:ModifyDate=\"2024-02-01T00:00:00Z\"", "photoscli:latitude=\"59.32930000\"", "photoscli:addressCountry=\"Sweden\"", "photoscli:adjustmentFormatIdentifier=\"com.apple\"", "<photoscli:resources><rdf:Seq>", "photoscli:resourceFilename=\"res&.heic\"", "<photoscli:mediaSubtypes><rdf:Seq>"} {
|
for _, want := range []string{"photoscli:xmpSchemaVersion=\"2\"", "photoscli:assetID=\"id&<>"\"", "photoscli:isFavorite=\"true\"", "xmp:Rating=\"5\"", "photoscli:hasAdjustments=\"true\"", "xmp:ModifyDate=\"2024-02-01T00:00:00Z\"", "photoshop:DateCreated=\"2024-01-01T00:00:00Z\"", "exif:GPSLatitude=\"59.32930000\"", "photoscli:latitude=\"59.32930000\"", "photoscli:addressCountry=\"Sweden\"", "photoscli:adjustmentFormatIdentifier=\"com.apple\"", "<dc:subject><rdf:Seq>", "<rdf:li>A&B</rdf:li>", "<photoscli:resources><rdf:Seq>", "photoscli:resourceFilename=\"res&.heic\"", "<photoscli:mediaSubtypes><rdf:Seq>"} {
|
||||||
if !strings.Contains(xmp, want) {
|
if !strings.Contains(xmp, want) {
|
||||||
t.Fatalf("XMP missing %q in %s", want, xmp)
|
t.Fatalf("XMP missing %q in %s", want, xmp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestKeywordsFromAlbumPath(t *testing.T) {
|
||||||
|
got := keywordsFromAlbumPath("Album", "Trips/Album/2024")
|
||||||
|
want := []string{"Album", "Trips", "2024"}
|
||||||
|
if len(got) != len(want) {
|
||||||
|
t.Fatalf("keywords len=%d want=%d: %#v", len(got), len(want), got)
|
||||||
|
}
|
||||||
|
for i := range want {
|
||||||
|
if got[i] != want[i] {
|
||||||
|
t.Fatalf("keywords[%d]=%q want %q in %#v", i, got[i], want[i], got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if got := keywordsFromAlbumPath("", "."); len(got) != 0 {
|
||||||
|
t.Fatalf("expected no dot keyword, got %#v", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestWriteXMPSidecar(t *testing.T) {
|
func TestWriteXMPSidecar(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
path := filepath.Join(dir, "photo.xmp")
|
path := filepath.Join(dir, "photo.xmp")
|
||||||
|
|||||||
Reference in New Issue
Block a user