Updated CLI options with more descriptive metavar names

This commit is contained in:
Rhet Turnbull
2020-01-26 20:16:51 -08:00
parent f7c8b457a5
commit e79cb92693
2 changed files with 63 additions and 35 deletions

View File

@@ -93,16 +93,16 @@ Options:
order: 1. last opened library, 2. system order: 1. last opened library, 2. system
library, 3. ~/Pictures/Photos library, 3. ~/Pictures/Photos
Library.photoslibrary Library.photoslibrary
--keyword TEXT Search for keyword(s). --keyword KEYWORD Search for keyword(s).
--person TEXT Search for person(s). --person PERSON Search for person(s).
--album TEXT Search for album(s). --album ALBUM Search for album(s).
--uuid TEXT Search for UUID(s). --uuid UUID Search for UUID(s).
--title TEXT Search for TEXT in title of photo. --title TITLE Search for TITLE in title of photo.
--no-title Search for photos with no title. --no-title Search for photos with no title.
--description TEXT Search for TEXT in description of photo. --description DESC Search for DESC in description of photo.
--no-description Search for photos with no description. --no-description Search for photos with no description.
--uti TEXT Search for photos whose uniform type --uti UTI Search for photos whose uniform type
identifier (UTI) matches TEXT identifier (UTI) matches UTI
-i, --ignore-case Case insensitive search for title or -i, --ignore-case Case insensitive search for title or
description. Does not apply to keyword, description. Does not apply to keyword,
person, or album. person, or album.
@@ -155,17 +155,17 @@ Options:
extension. extension.
--original-name Use photo's original filename instead of --original-name Use photo's original filename instead of
current filename for export. current filename for export.
--sidecar Create JSON sidecar for each photo exported --sidecar FORMAT Create sidecar for each photo exported;
in format useable by exiftool valid FORMAT values: xmp, json; --sidecar
(https://exiftool.org/) The sidecar file can json: create JSON sidecar useable by
be used to apply metadata to the file with exiftool (https://exiftool.org/) The sidecar
exiftool, for example: "exiftool file can be used to apply metadata to the
-j=photoname.jpg.json photoname.jpg" The file with exiftool, for example: "exiftool
sidecar file is named in format -j=photoname.json photoname.jpg" The sidecar
photoname.ext.json where ext is extension of file is named in format photoname.json
the photo (e.g. jpg). Note: this does not --sidecar xmp: create XMP sidecar used by
create an XMP sidecar as used by Lightroom, Adobe Lightroom, etc. The sidecar file is
etc. named in format photoname.xmp
--download-missing Attempt to download missing photos from --download-missing Attempt to download missing photos from
iCloud. The current implementation uses iCloud. The current implementation uses
Applescript to interact with Photos to Applescript to interact with Photos to
@@ -650,15 +650,16 @@ Returns the path to the live video component of a [live photo](#live_photo). If
#### `json()` #### `json()`
Returns a JSON representation of all photo info Returns a JSON representation of all photo info
#### `export(dest, *filename, edited=False, overwrite=False, increment=True, sidecar=False, use_photos_export=False, timeout=120)` #### `export(dest, *filename, edited=False, overwrite=False, increment=True, sidecar_json=False, sidecar_xmp=False, use_photos_export=False, timeout=120,)`
Export photo from the Photos library to another destination on disk. Export photo from the Photos library to another destination on disk.
- dest: must be valid destination path as str (or exception raised). - dest: must be valid destination path as str (or exception raised).
- *filename (optional): name of picture as str; if not provided, will use current filename - *filename (optional): name of picture as str; if not provided, will use current filename
- edited: boolean; if True (default=False), will export the edited version of the photo (or raise exception if no edited version) - edited: boolean; if True (default=False), will export the edited version of the photo (or raise exception if no edited version)
- overwrite: boolean; if True (default=False), will overwrite files if they alreay exist - overwrite: boolean; if True (default=False), will overwrite files if they alreay exist
- increment: boolean; if True (default=True), will increment file name until a non-existant name is found - increment: boolean; if True (default=True), will increment file name until a non-existent name is found
- sidecar: boolean; if True (default=False) will also write a json sidecar file with EXIF data in format readable by [exiftool](https://exiftool.org/); filename will be dest/filename.ext.json where ext is suffix of the image file (e.g. jpeg or jpg). Note: this is not an XMP sidecar. - sidecar_json: (boolean, default = False); if True will also write a json sidecar with IPTC data in format readable by exiftool; sidecar filename will be dest/filename.ext.json where ext is suffix of the image file (e.g. jpeg or jpg)
- sidecar_xmp: (boolean, default = False); if True will also write a XMP sidecar with IPTC data; sidecar filename will be dest/filename.ext.xmp where ext is suffix of the image file (e.g. jpeg or jpg)
- use_photos_export: boolean; (default=False), if True will attempt to export photo via applescript interaction with Photos; useful for forcing download of missing photos. This only works if the Photos library being used is the default library (last opened by Photos) as applescript will directly interact with whichever library Photos is currently using. - use_photos_export: boolean; (default=False), if True will attempt to export photo via applescript interaction with Photos; useful for forcing download of missing photos. This only works if the Photos library being used is the default library (last opened by Photos) as applescript will directly interact with whichever library Photos is currently using.
- timeout: (int, default=120) timeout in seconds used with use_photos_export - timeout: (int, default=120) timeout in seconds used with use_photos_export
@@ -669,12 +670,12 @@ import osxphotos
photosdb = osxphotos.PhotosDB("/Users/smith/Pictures/Photos Library.photoslibrary") photosdb = osxphotos.PhotosDB("/Users/smith/Pictures/Photos Library.photoslibrary")
photos = photosdb.photos() photos = photosdb.photos()
photos[0].export("/tmp","photo_name.jpg",sidecar=True) photos[0].export("/tmp","photo_name.jpg",sidecar_json=True)
``` ```
Then Then
`exiftool -j=photo_name.jpg.json photo_name.jpg` `exiftool -j=photo_name.json photo_name.jpg`
If overwrite=False and increment=False, export will fail if destination file already exists If overwrite=False and increment=False, export will fail if destination file already exists

View File

@@ -89,22 +89,48 @@ JSON_OPTION = click.option(
def query_options(f): def query_options(f):
o = click.option o = click.option
options = [ options = [
o("--keyword", default=None, multiple=True, help="Search for keyword(s)."),
o("--person", default=None, multiple=True, help="Search for person(s)."),
o("--album", default=None, multiple=True, help="Search for album(s)."),
o("--uuid", default=None, multiple=True, help="Search for UUID(s)."),
o( o(
"--title", "--keyword",
metavar="KEYWORD",
default=None, default=None,
multiple=True, multiple=True,
help="Search for TEXT in title of photo.", help="Search for keyword(s).",
),
o(
"--person",
metavar="PERSON",
default=None,
multiple=True,
help="Search for person(s).",
),
o(
"--album",
metavar="ALBUM",
default=None,
multiple=True,
help="Search for album(s).",
),
o(
"--uuid",
metavar="UUID",
default=None,
multiple=True,
help="Search for UUID(s).",
),
o(
"--title",
metavar="TITLE",
default=None,
multiple=True,
help="Search for TITLE in title of photo.",
), ),
o("--no-title", is_flag=True, help="Search for photos with no title."), o("--no-title", is_flag=True, help="Search for photos with no title."),
o( o(
"--description", "--description",
metavar="DESC",
default=None, default=None,
multiple=True, multiple=True,
help="Search for TEXT in description of photo.", help="Search for DESC in description of photo.",
), ),
o( o(
"--no-description", "--no-description",
@@ -113,9 +139,10 @@ def query_options(f):
), ),
o( o(
"--uti", "--uti",
metavar="UTI",
default=None, default=None,
multiple=False, multiple=False,
help="Search for photos whose uniform type identifier (UTI) matches TEXT", help="Search for photos whose uniform type identifier (UTI) matches UTI",
), ),
o( o(
"-i", "-i",
@@ -625,14 +652,14 @@ def query(
default=None, default=None,
multiple=True, multiple=True,
metavar="FORMAT", metavar="FORMAT",
type=click.Choice(['xmp', 'json'], case_sensitive=False), type=click.Choice(["xmp", "json"], case_sensitive=False),
help="Create sidecar for each photo exported; valid FORMAT values: xmp, json; " help="Create sidecar for each photo exported; valid FORMAT values: xmp, json; "
f"--sidecar json: create JSON sidecar useable by exiftool ({_EXIF_TOOL_URL}) " f"--sidecar json: create JSON sidecar useable by exiftool ({_EXIF_TOOL_URL}) "
"The sidecar file can be used to apply metadata to the file with exiftool, for example: " "The sidecar file can be used to apply metadata to the file with exiftool, for example: "
'"exiftool -j=photoname.json photoname.jpg" ' '"exiftool -j=photoname.json photoname.jpg" '
"The sidecar file is named in format photoname.json " "The sidecar file is named in format photoname.json "
"--sidecar xmp: create XMP sidecar used by Adobe Lightroom, etc." "--sidecar xmp: create XMP sidecar used by Adobe Lightroom, etc."
"The sidecar file is named in format photoname.xmp" "The sidecar file is named in format photoname.xmp",
) )
@click.option( @click.option(
"--download-missing", "--download-missing",