v0.8.6: add XMP keyword and rating controls
This commit is contained in:
+39
-2
@@ -43,6 +43,8 @@ type exportOptions struct {
|
||||
format string
|
||||
sidecar string
|
||||
xmpPrivacy string
|
||||
xmpKeywords string
|
||||
xmpRating string
|
||||
metadataOnly bool
|
||||
reverseGeocode bool
|
||||
minSize int64
|
||||
@@ -233,6 +235,12 @@ COMMON EXPORT FLAGS
|
||||
--xmp-privacy keep|strip-location|strip-address
|
||||
Control location/address metadata in generated XMP sidecars. Default: keep.
|
||||
|
||||
--xmp-keywords album-path|album|none
|
||||
Control dc:subject keywords in generated XMP sidecars. Default: album-path.
|
||||
|
||||
--xmp-rating favorite|none
|
||||
Control favorite-to-rating mapping in generated XMP sidecars. Default: favorite.
|
||||
|
||||
--metadata-only
|
||||
With --sidecar xmp, write or refresh XMP sidecars for files already in
|
||||
the manifest without exporting media files. Requires a manifest.
|
||||
@@ -1100,6 +1108,14 @@ func writeSidecarIfNeeded(pa pendingAsset, result photos.ExportResult, originals
|
||||
if xmpPrivacy == "" {
|
||||
xmpPrivacy = "keep"
|
||||
}
|
||||
xmpKeywords := opts.xmpKeywords
|
||||
if xmpKeywords == "" {
|
||||
xmpKeywords = "album-path"
|
||||
}
|
||||
xmpRating := opts.xmpRating
|
||||
if xmpRating == "" {
|
||||
xmpRating = "favorite"
|
||||
}
|
||||
var placemark *photos.Placemark
|
||||
if opts.reverseGeocode && location != nil && cache != nil && xmpPrivacy == "keep" {
|
||||
placemark = cache.lookup(pa.asset.Location.Latitude, pa.asset.Location.Longitude, bridge)
|
||||
@@ -1111,13 +1127,24 @@ func writeSidecarIfNeeded(pa pendingAsset, result photos.ExportResult, originals
|
||||
if xmpPrivacy == "strip-address" {
|
||||
placemark = nil
|
||||
}
|
||||
keywords := keywordsFromAlbumPath(pa.album, relDir)
|
||||
if xmpKeywords == "album" {
|
||||
keywords = keywordsFromAlbumPath(pa.album, "")
|
||||
}
|
||||
if xmpKeywords == "none" {
|
||||
keywords = nil
|
||||
}
|
||||
isFavorite := pa.asset.IsFavorite
|
||||
if xmpRating == "none" {
|
||||
isFavorite = false
|
||||
}
|
||||
return writeXMPSidecar(sidecarPath(fullPath), xmpSidecarData{
|
||||
AssetID: pa.asset.ID,
|
||||
OriginalFilename: pa.asset.Filename,
|
||||
ExportedFilename: result.Filename,
|
||||
Album: pa.album,
|
||||
AlbumPath: pa.path,
|
||||
Keywords: keywordsFromAlbumPath(pa.album, relDir),
|
||||
Keywords: keywords,
|
||||
ManifestPath: relPath,
|
||||
MediaType: pa.asset.MediaType,
|
||||
MediaSubtypes: pa.asset.MediaSubtypes,
|
||||
@@ -1126,7 +1153,7 @@ func writeSidecarIfNeeded(pa pendingAsset, result photos.ExportResult, originals
|
||||
PixelWidth: pa.asset.PixelWidth,
|
||||
PixelHeight: pa.asset.PixelHeight,
|
||||
Duration: pa.asset.Duration,
|
||||
IsFavorite: pa.asset.IsFavorite,
|
||||
IsFavorite: isFavorite,
|
||||
IsHidden: pa.asset.IsHidden,
|
||||
HasAdjustments: pa.asset.HasAdjustments,
|
||||
Cloud: result.Cloud,
|
||||
@@ -1892,6 +1919,8 @@ func parseExportOptions(args []string, stderr io.Writer) (exportOptions, bool) {
|
||||
format: flagValWithDefault(args, "--format", "jpeg"),
|
||||
sidecar: flagValWithDefault(args, "--sidecar", "none"),
|
||||
xmpPrivacy: flagValWithDefault(args, "--xmp-privacy", "keep"),
|
||||
xmpKeywords: flagValWithDefault(args, "--xmp-keywords", "album-path"),
|
||||
xmpRating: flagValWithDefault(args, "--xmp-rating", "favorite"),
|
||||
metadataOnly: hasFlag(args, "--metadata-only"),
|
||||
reverseGeocode: hasFlag(args, "--reverse-geocode"),
|
||||
dateTemplate: flagVal(args, "--date-template"),
|
||||
@@ -1912,6 +1941,14 @@ func parseExportOptions(args []string, stderr io.Writer) (exportOptions, bool) {
|
||||
fmt.Fprintf(stderr, "error: --xmp-privacy must be keep, strip-location, or strip-address, got %q\n", opts.xmpPrivacy)
|
||||
return opts, false
|
||||
}
|
||||
if opts.xmpKeywords != "album-path" && opts.xmpKeywords != "album" && opts.xmpKeywords != "none" {
|
||||
fmt.Fprintf(stderr, "error: --xmp-keywords must be album-path, album, or none, got %q\n", opts.xmpKeywords)
|
||||
return opts, false
|
||||
}
|
||||
if opts.xmpRating != "favorite" && opts.xmpRating != "none" {
|
||||
fmt.Fprintf(stderr, "error: --xmp-rating must be favorite or none, got %q\n", opts.xmpRating)
|
||||
return opts, false
|
||||
}
|
||||
if opts.metadataOnly && opts.sidecar != "xmp" {
|
||||
fmt.Fprintln(stderr, "error: --metadata-only requires --sidecar xmp")
|
||||
return opts, false
|
||||
|
||||
Reference in New Issue
Block a user