Compare commits
45 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5195f9d2b | ||
|
|
fa332186ab | ||
|
|
aa2ebf55bb | ||
|
|
d1fbb9fe86 | ||
|
|
116cb662fb | ||
|
|
db68defc44 | ||
|
|
7460bc88fc | ||
|
|
dbbbbf10a8 | ||
|
|
0633814ab2 | ||
|
|
df7d45659a | ||
|
|
cec266bba4 | ||
|
|
d0d2e80800 | ||
|
|
aafdbea564 | ||
|
|
c42050a10c | ||
|
|
c27cfb1223 | ||
|
|
ad144da8a0 | ||
|
|
5352aec3b9 | ||
|
|
e951e5361e | ||
|
|
f7bd1376e1 | ||
|
|
26f96d582c | ||
|
|
8cb15d1555 | ||
|
|
2d9429c8ee | ||
|
|
3b6dd08d2b | ||
|
|
3c85f26f90 | ||
|
|
52c054f81f | ||
|
|
8dc59cbc35 | ||
|
|
802e2f069a | ||
|
|
5d4d7d7db7 | ||
|
|
ea9b41bae4 | ||
|
|
38397b507b | ||
|
|
3636fcbc76 | ||
|
|
a6231e29ff | ||
|
|
8c36c6712a | ||
|
|
7fa3704840 | ||
|
|
e829212987 | ||
|
|
df37a017a8 | ||
|
|
101525c95f | ||
|
|
ae2fd2e3db | ||
|
|
9588853ea2 | ||
|
|
9d38885416 | ||
|
|
653b7e6600 | ||
|
|
9429ea8ace | ||
|
|
2202f1b1e9 | ||
|
|
a509ef18d3 | ||
|
|
0492f94060 |
@@ -100,6 +100,15 @@
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "jstrine",
|
||||
"name": "Jonathan Strine",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/33943447?v=4",
|
||||
"profile": "https://github.com/jstrine",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 7
|
||||
|
||||
106
CHANGELOG.md
106
CHANGELOG.md
@@ -4,6 +4,112 @@ All notable changes to this project will be documented in this file. Dates are d
|
||||
|
||||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
||||
|
||||
#### [v0.36.22](https://github.com/RhetTbull/osxphotos/compare/v0.36.21...v0.36.22)
|
||||
|
||||
> 26 November 2020
|
||||
|
||||
- Add XML escaping to XMP sidecar export, thanks to @jstrine for the fix! [`#272`](https://github.com/RhetTbull/osxphotos/pull/272)
|
||||
- Fix EXIF GPS format for XMP sidecar, thanks to @jstrine for the fix! [`#270`](https://github.com/RhetTbull/osxphotos/pull/270)
|
||||
- Continue even if the original filename is None, thanks to @jstrine for the fix! [`#268`](https://github.com/RhetTbull/osxphotos/pull/268)
|
||||
- Added test for missing original_filename [`116cb66`](https://github.com/RhetTbull/osxphotos/commit/116cb662fbddf9153f6858c6ea97dc7f65c77705)
|
||||
- Add @jstrine as a contributor [`7460bc8`](https://github.com/RhetTbull/osxphotos/commit/7460bc88fcc5e1e7435c9b9bcdf7ec9c7c5e39ea)
|
||||
- Escape characters which cause XML parsing issues [`c42050a`](https://github.com/RhetTbull/osxphotos/commit/c42050a10cac40b0b5ac70c587e07f257a9b50dd)
|
||||
- Fix tests for apostrophe [`d0d2e80`](https://github.com/RhetTbull/osxphotos/commit/d0d2e8080096bf66f93a830386800ce713680c51)
|
||||
- Fix test for XMP sidecar with GPS info [`c27cfb1`](https://github.com/RhetTbull/osxphotos/commit/c27cfb1223fa82b9e5549b93c283e9444693270a)
|
||||
|
||||
#### [v0.36.21](https://github.com/RhetTbull/osxphotos/compare/v0.36.20...v0.36.21)
|
||||
|
||||
> 25 November 2020
|
||||
|
||||
- Exposed --use-photos-export and --use-photokit [`e951e53`](https://github.com/RhetTbull/osxphotos/commit/e951e5361e59060229787bb1ea3fc4e088ffff99)
|
||||
|
||||
#### [v0.36.20](https://github.com/RhetTbull/osxphotos/compare/v0.36.19...v0.36.20)
|
||||
|
||||
> 23 November 2020
|
||||
|
||||
- Added photokit export as hidden --use-photokit option [`26f96d5`](https://github.com/RhetTbull/osxphotos/commit/26f96d582c01ce9816b1f54f0e74c8570f133f7c)
|
||||
|
||||
#### [v0.36.19](https://github.com/RhetTbull/osxphotos/compare/v0.36.18...v0.36.19)
|
||||
|
||||
> 19 November 2020
|
||||
|
||||
- Removed debug statement in _photoinfo_export [`8cb15d1`](https://github.com/RhetTbull/osxphotos/commit/8cb15d15551094dcaf1b0ef32d6ac0273be7fd37)
|
||||
|
||||
#### [v0.36.18](https://github.com/RhetTbull/osxphotos/compare/v0.36.17...v0.36.18)
|
||||
|
||||
> 14 November 2020
|
||||
|
||||
- Moved AppleScript to photoscript [`3c85f26`](https://github.com/RhetTbull/osxphotos/commit/3c85f26f901645ce297685ccd639792757fbc995)
|
||||
- Fixed missing data file for photoscript [`2d9429c`](https://github.com/RhetTbull/osxphotos/commit/2d9429c8eefabe6233fc580f65511c48ee6c01e5)
|
||||
- Version bump, updated requirements [`3b6dd08`](https://github.com/RhetTbull/osxphotos/commit/3b6dd08d2bb2b20a55064bf24fe7ce788e7268ef)
|
||||
|
||||
#### [v0.36.17](https://github.com/RhetTbull/osxphotos/compare/v0.36.15...v0.36.17)
|
||||
|
||||
> 12 November 2020
|
||||
|
||||
- Fixed path for photos actually missing off disk [`5d4d7d7`](https://github.com/RhetTbull/osxphotos/commit/5d4d7d7db7ca1109b6230803fe777d7a30882efe)
|
||||
- Fixed erroneous attempt to export edited with --download-missing [`8dc59cb`](https://github.com/RhetTbull/osxphotos/commit/8dc59cbc35c33e71d0d912f4139e855180ac4fbd)
|
||||
- version bump [`802e2f0`](https://github.com/RhetTbull/osxphotos/commit/802e2f069a5f8b37ddc6b3b8ba07519ce10f88a7)
|
||||
|
||||
#### [v0.36.15](https://github.com/RhetTbull/osxphotos/compare/v0.36.14...v0.36.15)
|
||||
|
||||
> 11 November 2020
|
||||
|
||||
- Avoid copying db files if not necessary [`ea9b41b`](https://github.com/RhetTbull/osxphotos/commit/ea9b41bae41a05aad53454f67871c5e6c9a49f79)
|
||||
|
||||
#### [v0.36.14](https://github.com/RhetTbull/osxphotos/compare/v0.36.13...v0.36.14)
|
||||
|
||||
> 9 November 2020
|
||||
|
||||
- Fix for issue #247 [`38397b5`](https://github.com/RhetTbull/osxphotos/commit/38397b507b456169cf3be2d2dc6743ec8653feb3)
|
||||
|
||||
#### [v0.36.13](https://github.com/RhetTbull/osxphotos/compare/v0.36.11...v0.36.13)
|
||||
|
||||
> 9 November 2020
|
||||
|
||||
- Refactored phototemplate.py to add PATH_SEP option [`3636fcb`](https://github.com/RhetTbull/osxphotos/commit/3636fcbc76100d9898a59f24ed6e9b1965cc6022)
|
||||
- More work on phototemplate.py to add inline expansion [`a6231e2`](https://github.com/RhetTbull/osxphotos/commit/a6231e29ff28b2c7dc3239445f41afcb35926a7a)
|
||||
|
||||
#### [v0.36.11](https://github.com/RhetTbull/osxphotos/compare/v0.36.10...v0.36.11)
|
||||
|
||||
> 8 November 2020
|
||||
|
||||
- Implemented boolean type template fields [`7fa3704`](https://github.com/RhetTbull/osxphotos/commit/7fa3704840f7800689b4ac5f8edee8210eb3e8db)
|
||||
- Bug fix in handling missing edited photos [`e829212`](https://github.com/RhetTbull/osxphotos/commit/e829212987bbc1a88f845922abcffef70c159883)
|
||||
- Fixed message in CLI [`df37a01`](https://github.com/RhetTbull/osxphotos/commit/df37a017a8efdc8d0b9bc8d00a4452dc4cb892b3)
|
||||
|
||||
#### [v0.36.10](https://github.com/RhetTbull/osxphotos/compare/v0.36.9...v0.36.10)
|
||||
|
||||
> 8 November 2020
|
||||
|
||||
- Implemented issue #255 [`ae2fd2e`](https://github.com/RhetTbull/osxphotos/commit/ae2fd2e3db984756e6cc3f7b3338b8ba819ce28c)
|
||||
|
||||
#### [v0.36.9](https://github.com/RhetTbull/osxphotos/compare/v0.36.8...v0.36.9)
|
||||
|
||||
> 7 November 2020
|
||||
|
||||
- Refactored regex in phototemplate [`653b7e6`](https://github.com/RhetTbull/osxphotos/commit/653b7e6600e0738ecd00f74d510a893e0d447ca4)
|
||||
- Fix for exporting slow mo videos, issue #252 [`9d38885`](https://github.com/RhetTbull/osxphotos/commit/9d38885416b528bd8c91bb09120be85a8b109f29)
|
||||
|
||||
#### [v0.36.8](https://github.com/RhetTbull/osxphotos/compare/v0.36.7...v0.36.8)
|
||||
|
||||
> 5 November 2020
|
||||
|
||||
- Refactored exiftool.py [`2202f1b`](https://github.com/RhetTbull/osxphotos/commit/2202f1b1e9c4f83558ef48e58cb94af6b3a38cdd)
|
||||
- README.md update [`a509ef1`](https://github.com/RhetTbull/osxphotos/commit/a509ef18d3db2ac15a661e763a7254974cf8d84a)
|
||||
|
||||
#### [v0.36.7](https://github.com/RhetTbull/osxphotos/compare/v0.36.6...v0.36.7)
|
||||
|
||||
> 4 November 2020
|
||||
|
||||
- Implemented context manager for ExifTool, closes #250 [`#250`](https://github.com/RhetTbull/osxphotos/issues/250)
|
||||
|
||||
#### [v0.36.6](https://github.com/RhetTbull/osxphotos/compare/v0.36.5...v0.36.6)
|
||||
|
||||
> 2 November 2020
|
||||
|
||||
- Fix for issue #39 [`c7c5320`](https://github.com/RhetTbull/osxphotos/commit/c7c5320587e31070b55cc8c7e74f30b0f9e61379)
|
||||
|
||||
#### [v0.36.5](https://github.com/RhetTbull/osxphotos/compare/v0.36.4...v0.36.5)
|
||||
|
||||
> 1 November 2020
|
||||
|
||||
207
README.md
207
README.md
@@ -3,7 +3,7 @@
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
[](https://github.com/RhetTbull/osxphotos/workflows/Python%20package/badge.svg)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
[](#contributors-)
|
||||
[](#contributors-)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||
|
||||
- [OSXPhotos](#osxphotos)
|
||||
@@ -356,6 +356,16 @@ Options:
|
||||
to a filesystem that doesn't support Mac OS
|
||||
extended attributes. Only use this if you
|
||||
get an error while exporting.
|
||||
--use-photos-export Force the use of AppleScript or PhotoKit to
|
||||
export even if not missing (see also '--
|
||||
download-missing' and '--use-photokit').
|
||||
--use-photokit Use with '--download-missing' or '--use-
|
||||
photos-export' to use direct Photos
|
||||
interface instead of AppleScript to export.
|
||||
Highly experimental alpha feature; does not
|
||||
work with iTerm2 (use with Terminal.app).
|
||||
This is faster and more reliable than the
|
||||
default AppleScript interface.
|
||||
-h, --help Show this message and exit.
|
||||
|
||||
** Export **
|
||||
@@ -388,16 +398,72 @@ option to re-export the entire library thus rebuilding the
|
||||
|
||||
** Templating System **
|
||||
|
||||
Several options, such as --directory, allow you to specify a template which
|
||||
will be rendered to substitute template fields with values from the photo.
|
||||
For example, '{created.month}' would be replaced with the month name of the
|
||||
photo creation date. e.g. 'November'.
|
||||
|
||||
The general format for a template is '{TEMPLATE_FIELD[,[DEFAULT]]}'. Some
|
||||
templates have optional modifiers in form
|
||||
'{[[DELIM]+]TEMPLATE_FIELD[(PATH_SEP)][?VALUE_IF_TRUE][,[DEFAULT]]}'
|
||||
|
||||
The ',' and DEFAULT value are optional. If TEMPLATE_FIELD results in a null
|
||||
(empty) value, the default is '_'. You may specify an alternate default
|
||||
value by appending ',DEFAULT' after template_field. e.g. '{title,no_title}'
|
||||
would result in 'no_title' if the photo had no title. You may include other
|
||||
text in the template string outside the {} and use more than one template
|
||||
field, e.g. '{created.year} - {created.month}' (e.g. '2020 - November').
|
||||
|
||||
Some template fields such as 'hdr' are boolean and resolve to True or False.
|
||||
These take the form: '{TEMPLATE_FIELD?VALUE_IF_TRUE,VALUE_IF_FALSE}', e.g.
|
||||
{hdr?is_hdr,not_hdr} which would result in 'is_hdr' if photo is an HDR image
|
||||
and 'not_hdr' otherwise.
|
||||
|
||||
Some template fields such as 'folder_template' are "path-like" in that they
|
||||
join multiple elements into a single path-like string. For example, if photo
|
||||
is in album Album1 in folder Folder1, '{folder_album}` results in
|
||||
'Folder1/Album1'. This is so these template fields may be used as paths in
|
||||
--directory. If you intend to use such a field as a string, e.g. in the
|
||||
filename, you may specify a different path separator using the form:
|
||||
'{TEMPLATE_FIELD(PATH_SEP)}'. For example, using the example above,
|
||||
'{folder_album(-)}' would result in 'Folder1-Album1' and '{folder_album()}'
|
||||
would result in 'Folder1Album1'.
|
||||
|
||||
Some templates may resolve to more than one value. For example, a photo can
|
||||
have multiple keywords so '{keyword}' can result in multiple values. If used
|
||||
in a filename or directory, these templates may result in more than one copy
|
||||
of the photo being exported. For example, if photo has keywords "foo" and
|
||||
"bar", --directory '{keyword}' will result in copies of the photo being
|
||||
exported to 'foo/image_name.jpeg' and 'bar/image_name.jpeg'.
|
||||
|
||||
Multi-value template fields such as '{keyword}' may be expanded 'in place'
|
||||
with an optional delimiter using the template form '{DELIM+TEMPLATE_FIELD}'.
|
||||
For example, a photo with keywords 'foo' and 'bar':
|
||||
|
||||
'{keyword}' renders to 'foo' and 'bar'
|
||||
|
||||
'{,+keyword}' renders to: 'foo,bar'
|
||||
|
||||
'{; +keyword}' renders to: 'foo; bar'
|
||||
|
||||
'{+keyword}' renders to 'foobar'
|
||||
|
||||
Some template fields such as '{media_type}' use the 'DEFAULT' value to allow
|
||||
customization of the output. For example, '{media_type}' resolves to the
|
||||
special media type of the photo such as 'panorama' or 'selfie'. You may use
|
||||
the 'DEFAULT' value to override these in form:
|
||||
'{media_type,video=vidéo;time_lapse=vidéo_accélérée}'. In this example, if
|
||||
photo is a time_lapse photo, 'media_type' would resolve to 'vidéo_accélérée'
|
||||
instead of 'time_lapse' and video would resolve to 'vidéo' if photo is an
|
||||
ordinary video.
|
||||
|
||||
With the --directory and --filename options you may specify a template for the
|
||||
export directory or filename, respectively. The directory will be appended to
|
||||
the export path specified in the export DEST argument to export. For example,
|
||||
if template is '{created.year}/{created.month}', and export desitnation DEST
|
||||
if template is '{created.year}/{created.month}', and export destination DEST
|
||||
is '/Users/maria/Pictures/export', the actual export directory for a photo
|
||||
would be '/Users/maria/Pictures/export/2020/March' if the photo was created in
|
||||
March 2020. Some template substitutions may result in more than one value, for
|
||||
example '{album}' if photo is in more than one album or '{keyword}' if photo
|
||||
has more than one keyword. In this case, more than one copy of the photo will
|
||||
be exported, each in a separate directory or with a different filename.
|
||||
March 2020.
|
||||
|
||||
The templating system may also be used with the --keyword-template option to
|
||||
set keywords on export (with --exiftool or --sidecar), for example, to set a
|
||||
@@ -426,12 +492,28 @@ value, '_' (underscore) will be used as the default value. For example, in the
|
||||
above example, this would result in '2020/_/photoname.jpg' if address was
|
||||
null.
|
||||
|
||||
You may specify a null default (e.g. "" or empty string) by omitting the value
|
||||
after the comma, e.g. {title,} which would render to "" if title had no value.
|
||||
|
||||
Substitution Description
|
||||
{name} Current filename of the photo
|
||||
{original_name} Photo's original filename when imported to
|
||||
Photos
|
||||
{title} Title of the photo
|
||||
{descr} Description of the photo
|
||||
{media_type} Special media type resolved in this
|
||||
precedence: selfie, time_lapse, panorama,
|
||||
slow_mo, screenshot, portrait, live_photo,
|
||||
burst, photo, video. Defaults to 'photo' or
|
||||
'video' if no special type. Customize one or
|
||||
more media types using format: '{media_type,
|
||||
video=vidéo;time_lapse=vidéo_accélérée}'
|
||||
{photo_or_video} 'photo' or 'video' depending on what type
|
||||
the image is. To customize, use default
|
||||
value as in
|
||||
'{photo_or_video,photo=fotos;video=videos}'
|
||||
{hdr} Photo is HDR?; True/False value, use in
|
||||
format '{hdr?VALUE_IF_TRUE,VALUE_IF_FALSE}'
|
||||
{created.date} Photo's creation date in ISO format, e.g.
|
||||
'2020-03-22'
|
||||
{created.year} 4-digit year of photo creation time
|
||||
@@ -1269,6 +1351,9 @@ Returns True if photo is a panorama, otherwise False.
|
||||
|
||||
**Note**: The result of `PhotoInfo.panorama` will differ from the "Panoramas" Media Types smart album in that it will also identify panorama photos from older phones that Photos does not recognize as panoramas.
|
||||
|
||||
#### `slow_mo`
|
||||
Returns True if photo is a slow motion video, otherwise False
|
||||
|
||||
#### `labels`
|
||||
Returns image categorization labels associated with the photo as list of str.
|
||||
|
||||
@@ -1391,11 +1476,13 @@ If overwrite=False and increment=False, export will fail if destination file alr
|
||||
|
||||
#### <a name="rendertemplate">`render_template()`</a>
|
||||
|
||||
`render_template(template_str, none_str = "_", path_sep = None, expand_inplace = False, inplace_sep = None, filename=False, dirname=False, replacement=":",)`
|
||||
Render template string for photo. none_str is used if template substitution results in None value and no default specified.
|
||||
- `template_str`: str in form "{name,DEFAULT}" where name is one of the values in table below. The "," and default value that follows are optional. If specified, "DEFAULT" will be used if "name" is None. This is useful for values which are not always present, for example reverse geolocation data.
|
||||
`render_template(template_str, none_str = "_", path_sep = None, expand_inplace = False, inplace_sep = None, filename=False, dirname=False, replacement=":",)`
|
||||
|
||||
Render template string for photo. none_str is used if template substitution results in None value and no default specified.
|
||||
|
||||
- `template_str`: str in format "{[[DELIM]+]name[(PATH_SEP)][?TRUE_VALUE][,[DEFAULT]]}" where name is one of the values in the [Template Substitutions](#template-substitutions) table. See notes below regarding specific details of the syntax.
|
||||
- `none_str`: optional str to use as substitution when template value is None and no default specified in the template string. default is "_".
|
||||
- `path_sep`: optional character to use as path separator, default is os.path.sep
|
||||
- `path_sep`: optional character to use as path separator, default is `os.path.sep`
|
||||
- `expand_inplace`: expand multi-valued substitutions in-place as a single string instead of returning individual strings
|
||||
- `inplace_sep`: optional string to use as separator between multi-valued keywords with expand_inplace; default is ','
|
||||
- `filename`: if True, template output will be sanitized to produce valid file name
|
||||
@@ -1412,6 +1499,56 @@ e.g. `render_template("{created.year}/{{foo}}", photo)` would return `(["2020/{f
|
||||
|
||||
Some substitutions, notably `album`, `keyword`, and `person` could return multiple values, hence a new string will be return for each possible substitution (hence why a list of rendered strings is returned). For example, a photo in 2 albums: 'Vacation' and 'Family' would result in the following rendered values if template was "{created.year}/{album}" and created.year == 2020: `["2020/Vacation","2020/Family"]`
|
||||
|
||||
The template field format contains optional modifiers:
|
||||
|
||||
`"{[[DELIM]+]name[(PATH_SEP)][?TRUE_VALUE][,[DEFAULT]]}"`
|
||||
|
||||
`DELIM`: optional delimiter string to use when expanding multi-valued template values in-place
|
||||
|
||||
`+`: If present before template `name`, expands the template in place. If `DELIM` not provided, values are joined with no delimiter.
|
||||
|
||||
e.g. if Photo keywords are `["foo","bar"]`:
|
||||
|
||||
- `"{keyword}"` renders to `["foo", "bar"]`
|
||||
- `"{,+keyword}"` renders to: `["foo,bar"]`
|
||||
- `"{; +keyword}"` renders to: `["foo; bar"]`
|
||||
- `"{+keyword}"` renders to `["foobar"]`
|
||||
|
||||
`PATH_SEP`: optional path separator to use when joining path like fields, for example `{folder_album}`. May also be provided as `path_sep` argument in `render_template()`. If provided both in the call to `render_template()` and in the template itself, the value in the template string takes precedence. If not provided in either the template string or in `path_sep` argument, defaults to `os.path.sep`.
|
||||
|
||||
e.g. If Photo is in `Album1` in `Folder1`:
|
||||
|
||||
- `"{folder_album}"` renders to `["Folder1/Album1"]`
|
||||
- `"{folder_album(:)}"` renders to `["Folder1:Album1"]`
|
||||
- `"{folder_album()}"` renders to `["Folder1Album1"]`
|
||||
|
||||
`?TRUE_VALUE`: optional value to use if name is boolean-type field which evaluates to true. For example `"{hdr}"` evaluates to True if photo is an high dynamic range (HDR) image and False otherwise. In these types of fields, use `?TRUE_VALUE` to provide the value if True and `,DEFAULT` to provide the value of False.
|
||||
|
||||
e.g. if photo is an HDR image,
|
||||
|
||||
- `"{hdr?ISHDR,NOTHDR}"` renders to `["ISHDR"]`
|
||||
|
||||
and if it is not an HDR image,
|
||||
|
||||
- `"{hdr?ISHDR,NOTHDR}"` renders to `["NOTHDR"]`
|
||||
|
||||
Either or both `TRUE_VALUE` or `DEFAULT` (False value) may be empty which would result in empty string `[""]` when rendered.
|
||||
|
||||
`,DEFAULT`: optional default value to use if the template name has no value. This modifier is also used for the value if False for boolean-type fields (see above) as well as to hold a sub-template for values like `{created.strftime}`. If no default value provided, "_" is used. May also be provided in the `none_str` argument to `render_template()`. If provided both in the template string and in `none_str`, the value in the template string takes precedence.
|
||||
|
||||
e.g., if photo has no title set,
|
||||
|
||||
- `"{title}"` renders to ["_"]
|
||||
- `"{title,I have no title}"` renders to `["I have no title"]`
|
||||
|
||||
Template fields such as `created.strftime` use the DEFAULT value to pass the template to use for `strftime`.
|
||||
|
||||
e.g., if photo date is 4 February 2020, 19:07:38,
|
||||
|
||||
- `"{created.strftime,%Y-%m-%d-%H%M%S}"` renders to `["2020-02-04-190738"]`
|
||||
|
||||
Some template fields such as `"{media_type}"` use the `DEFAULT` value to allow customization of the output. For example, `"{media_type}"` resolves to the special media type of the photo such as `panorama` or `selfie`. You may use the `DEFAULT` value to override these in form: `"{media_type,video=vidéo;time_lapse=vidéo_accélérée}"`. In this example, if photo was a time_lapse photo, `media_type` would resolve to `vidéo_accélérée` instead of `time_lapse`.
|
||||
|
||||
See [Template Substitutions](#template-substitutions) for additional details.
|
||||
|
||||
### ExifInfo
|
||||
@@ -1832,37 +1969,42 @@ To get the path of every raw photo, whether it's a single raw photo or a raw+JPE
|
||||
|
||||
### Template Substitutions
|
||||
|
||||
The following substitutions are availabe for use with `PhotoInfo.render_template()`
|
||||
The following template field substitutions are availabe for use with `PhotoInfo.render_template()`
|
||||
|
||||
| Substitution | Description |
|
||||
|--------------|-------------|
|
||||
|{name}|Current filename of the photo|
|
||||
|{original_name}|Photo's original filename when imported to Photos|
|
||||
|{title}|Title of the photo|
|
||||
|{descr}|Description of the photo|
|
||||
|{media_type}|Special media type resolved in this precedence: selfie, time_lapse, panorama, slow_mo, screenshot, portrait, live_photo, burst, photo, video. Defaults to 'photo' or 'video' if no special type. Customize one or more media types using format: '{media_type,video=vidéo;time_lapse=vidéo_accélérée}'|
|
||||
|{photo_or_video}|'photo' or 'video' depending on what type the image is. To customize, use default value as in '{photo_or_video,photo=fotos;video=videos}'|
|
||||
|{hdr}|Photo is HDR?; True/False value, use in format '{hdr?VALUE_IF_TRUE,VALUE_IF_FALSE}'|
|
||||
|{created.date}|Photo's creation date in ISO format, e.g. '2020-03-22'|
|
||||
|{created.year}|4-digit year of file creation time|
|
||||
|{created.yy}|2-digit year of file creation time|
|
||||
|{created.mm}|2-digit month of the file creation time (zero padded)|
|
||||
|{created.month}|Month name in user's locale of the file creation time|
|
||||
|{created.mon}|Month abbreviation in the user's locale of the file creation time|
|
||||
|{created.dd}|2-digit day of the month (zero padded) of file creation time|
|
||||
|{created.dow}|Day of week in user's locale of the file creation time|
|
||||
|{created.doy}|3-digit day of year (e.g Julian day) of file creation time, starting from 1 (zero padded)|
|
||||
|{created.hour}|2-digit hour of the file creation time|
|
||||
|{created.min}|2-digit minute of the file creation time|
|
||||
|{created.sec}|2-digit second of the file creation time|
|
||||
|{created.year}|4-digit year of photo creation time|
|
||||
|{created.yy}|2-digit year of photo creation time|
|
||||
|{created.mm}|2-digit month of the photo creation time (zero padded)|
|
||||
|{created.month}|Month name in user's locale of the photo creation time|
|
||||
|{created.mon}|Month abbreviation in the user's locale of the photo creation time|
|
||||
|{created.dd}|2-digit day of the month (zero padded) of photo creation time|
|
||||
|{created.dow}|Day of week in user's locale of the photo creation time|
|
||||
|{created.doy}|3-digit day of year (e.g Julian day) of photo creation time, starting from 1 (zero padded)|
|
||||
|{created.hour}|2-digit hour of the photo creation time|
|
||||
|{created.min}|2-digit minute of the photo creation time|
|
||||
|{created.sec}|2-digit second of the photo creation time|
|
||||
|{created.strftime}|Apply strftime template to file creation date/time. Should be used in form {created.strftime,TEMPLATE} where TEMPLATE is a valid strftime template, e.g. {created.strftime,%Y-%U} would result in year-week number of year: '2020-23'. If used with no template will return null value. See https://strftime.org/ for help on strftime templates.|
|
||||
|{modified.date}|Photo's modification date in ISO format, e.g. '2020-03-22'|
|
||||
|{modified.year}|4-digit year of file modification time|
|
||||
|{modified.yy}|2-digit year of file modification time|
|
||||
|{modified.mm}|2-digit month of the file modification time (zero padded)|
|
||||
|{modified.month}|Month name in user's locale of the file modification time|
|
||||
|{modified.mon}|Month abbreviation in the user's locale of the file modification time|
|
||||
|{modified.dd}|2-digit day of the month (zero padded) of the file modification time|
|
||||
|{modified.doy}|3-digit day of year (e.g Julian day) of file modification time, starting from 1 (zero padded)|
|
||||
|{modified.hour}|2-digit hour of the file modification time|
|
||||
|{modified.min}|2-digit minute of the file modification time|
|
||||
|{modified.sec}|2-digit second of the file modification time|
|
||||
|{modified.year}|4-digit year of photo modification time|
|
||||
|{modified.yy}|2-digit year of photo modification time|
|
||||
|{modified.mm}|2-digit month of the photo modification time (zero padded)|
|
||||
|{modified.month}|Month name in user's locale of the photo modification time|
|
||||
|{modified.mon}|Month abbreviation in the user's locale of the photo modification time|
|
||||
|{modified.dd}|2-digit day of the month (zero padded) of the photo modification time|
|
||||
|{modified.dow}|Day of week in user's locale of the photo modification time|
|
||||
|{modified.doy}|3-digit day of year (e.g Julian day) of photo modification time, starting from 1 (zero padded)|
|
||||
|{modified.hour}|2-digit hour of the photo modification time|
|
||||
|{modified.min}|2-digit minute of the photo modification time|
|
||||
|{modified.sec}|2-digit second of the photo modification time|
|
||||
|{today.date}|Current date in iso format, e.g. '2020-03-22'|
|
||||
|{today.year}|4-digit year of current date|
|
||||
|{today.yy}|2-digit year of current date|
|
||||
@@ -2017,6 +2159,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
||||
<td align="center"><a href="https://github.com/grundsch"><img src="https://avatars0.githubusercontent.com/u/3874928?v=4?s=100" width="100px;" alt=""/><br /><sub><b>grundsch</b></sub></a><br /><a href="https://github.com/RhetTbull/osxphotos/commits?author=grundsch" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/agprimatic"><img src="https://avatars1.githubusercontent.com/u/4685054?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ag Primatic</b></sub></a><br /><a href="https://github.com/RhetTbull/osxphotos/commits?author=agprimatic" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/hhoeck"><img src="https://avatars1.githubusercontent.com/u/6313998?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Horst Höck</b></sub></a><br /><a href="https://github.com/RhetTbull/osxphotos/commits?author=hhoeck" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/jstrine"><img src="https://avatars1.githubusercontent.com/u/33943447?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan Strine</b></sub></a><br /><a href="https://github.com/RhetTbull/osxphotos/commits?author=jstrine" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
# If you need to install pyinstaller:
|
||||
# python3 -m pip install --upgrade pyinstaller
|
||||
|
||||
pyinstaller --onefile --hidden-import="pkg_resources.py2_warn" --name osxphotos --add-data osxphotos/templates/xmp_sidecar.mako:osxphotos/templates cli.py
|
||||
pyinstaller osxphotos.spec
|
||||
48
osxphotos.spec
Normal file
48
osxphotos.spec
Normal file
@@ -0,0 +1,48 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
# spec file for pyinstaller
|
||||
# run `pyinstaller osxphotos.spec`
|
||||
|
||||
import os
|
||||
import importlib
|
||||
|
||||
pathex = os.getcwd()
|
||||
|
||||
# include necessary data files
|
||||
datas=[('osxphotos/templates/xmp_sidecar.mako', 'osxphotos/templates')]
|
||||
package_imports = [['photoscript', ['photoscript.applescript']]]
|
||||
for package, files in package_imports:
|
||||
proot = os.path.dirname(importlib.import_module(package).__file__)
|
||||
datas.extend((os.path.join(proot, f), package) for f in files)
|
||||
|
||||
block_cipher = None
|
||||
|
||||
a = Analysis(['cli.py'],
|
||||
pathex=[pathex],
|
||||
binaries=[],
|
||||
datas=datas,
|
||||
hiddenimports=['pkg_resources.py2_warn'],
|
||||
hookspath=[],
|
||||
runtime_hooks=[],
|
||||
excludes=[],
|
||||
win_no_prefer_redirects=False,
|
||||
win_private_assemblies=False,
|
||||
cipher=block_cipher,
|
||||
noarchive=False)
|
||||
|
||||
pyz = PYZ(a.pure, a.zipped_data,
|
||||
cipher=block_cipher)
|
||||
|
||||
exe = EXE(pyz,
|
||||
a.scripts,
|
||||
a.binaries,
|
||||
a.zipfiles,
|
||||
a.datas,
|
||||
[],
|
||||
name='osxphotos',
|
||||
debug=False,
|
||||
bootloader_ignore_signals=False,
|
||||
strip=False,
|
||||
upx=True,
|
||||
upx_exclude=[],
|
||||
runtime_tmpdir=None,
|
||||
console=True )
|
||||
@@ -28,6 +28,7 @@ from .export_db import ExportDB, ExportDBInMemory
|
||||
from .fileutil import FileUtil, FileUtilNoOp
|
||||
from .path_utils import is_valid_filepath, sanitize_filename, sanitize_filepath
|
||||
from .photoinfo import ExportResults
|
||||
from .photokit import check_photokit_authorization, request_photokit_authorization
|
||||
from .phototemplate import TEMPLATE_SUBSTITUTIONS, TEMPLATE_SUBSTITUTIONS_MULTI_VALUED
|
||||
|
||||
# global variable to control verbose output
|
||||
@@ -158,19 +159,76 @@ class ExportCommand(click.Command):
|
||||
formatter.write("\n\n")
|
||||
formatter.write_text("** Templating System **")
|
||||
formatter.write("\n")
|
||||
formatter.write_text(
|
||||
"""
|
||||
Several options, such as --directory, allow you to specify a template
|
||||
which will be rendered to substitute template fields with values from the photo.
|
||||
For example, '{created.month}' would be replaced with the month name of the photo creation date.
|
||||
e.g. 'November'.
|
||||
\n
|
||||
The general format for a template is '{TEMPLATE_FIELD[,[DEFAULT]]}'.
|
||||
Some templates have optional modifiers in form
|
||||
'{[[DELIM]+]TEMPLATE_FIELD[(PATH_SEP)][?VALUE_IF_TRUE][,[DEFAULT]]}'
|
||||
\n
|
||||
The ',' and DEFAULT value are optional.
|
||||
If TEMPLATE_FIELD results in a null (empty) value, the default is '_'.
|
||||
You may specify an alternate default value by appending ',DEFAULT' after template_field.
|
||||
e.g. '{title,no_title}' would result in 'no_title' if the photo had no title.
|
||||
You may include other text in the template string outside the {} and use more than
|
||||
one template field, e.g. '{created.year} - {created.month}' (e.g. '2020 - November').
|
||||
\n
|
||||
Some template fields such as 'hdr' are boolean and resolve to True or False.
|
||||
These take the form: '{TEMPLATE_FIELD?VALUE_IF_TRUE,VALUE_IF_FALSE}', e.g.
|
||||
{hdr?is_hdr,not_hdr} which would result in 'is_hdr' if photo is an HDR
|
||||
image and 'not_hdr' otherwise.
|
||||
\n
|
||||
Some template fields such as 'folder_template' are "path-like" in that they join
|
||||
multiple elements into a single path-like string. For example, if photo is in
|
||||
album Album1 in folder Folder1, '{folder_album}` results in 'Folder1/Album1'.
|
||||
This is so these template fields may be used as paths in --directory.
|
||||
If you intend to use such a field as a string, e.g. in the filename, you may specify
|
||||
a different path separator using the form: '{TEMPLATE_FIELD(PATH_SEP)}'.
|
||||
For example, using the example above, '{folder_album(-)}' would result in
|
||||
'Folder1-Album1' and '{folder_album()}' would result in
|
||||
'Folder1Album1'.
|
||||
\n
|
||||
Some templates may resolve to more than one value. For example, a photo can have
|
||||
multiple keywords so '{keyword}' can result in multiple values. If used in a filename
|
||||
or directory, these templates may result in more than one copy of the photo being exported.
|
||||
For example, if photo has keywords "foo" and "bar", --directory '{keyword}' will result in
|
||||
copies of the photo being exported to 'foo/image_name.jpeg' and 'bar/image_name.jpeg'.
|
||||
\n
|
||||
Multi-value template fields such as '{keyword}' may be expanded 'in place' with an optional
|
||||
delimiter using the template form '{DELIM+TEMPLATE_FIELD}'. For example, a photo with
|
||||
keywords 'foo' and 'bar':
|
||||
\n
|
||||
'{keyword}' renders to 'foo' and 'bar'
|
||||
\n
|
||||
'{,+keyword}' renders to: 'foo,bar'
|
||||
\n
|
||||
'{; +keyword}' renders to: 'foo; bar'
|
||||
\n
|
||||
'{+keyword}' renders to 'foobar'
|
||||
\n
|
||||
Some template fields such as '{media_type}' use the 'DEFAULT' value to allow customization
|
||||
of the output. For example, '{media_type}' resolves to the special media type of the
|
||||
photo such as 'panorama' or 'selfie'. You may use the 'DEFAULT' value to override
|
||||
these in form: '{media_type,video=vidéo;time_lapse=vidéo_accélérée}'.
|
||||
In this example, if photo is a time_lapse photo, 'media_type' would resolve to
|
||||
'vidéo_accélérée' instead of 'time_lapse' and video would resolve to 'vidéo' if photo
|
||||
is an ordinary video.
|
||||
"""
|
||||
)
|
||||
formatter.write("\n")
|
||||
formatter.write_text(
|
||||
"With the --directory and --filename options you may specify a template for the "
|
||||
+ "export directory or filename, respectively. "
|
||||
+ "The directory will be appended to the export path specified "
|
||||
+ "in the export DEST argument to export. For example, if template is "
|
||||
+ "'{created.year}/{created.month}', and export desitnation DEST is "
|
||||
+ "'{created.year}/{created.month}', and export destination DEST is "
|
||||
+ "'/Users/maria/Pictures/export', "
|
||||
+ "the actual export directory for a photo would be '/Users/maria/Pictures/export/2020/March' "
|
||||
+ "if the photo was created in March 2020. "
|
||||
+ "Some template substitutions may result in more than one value, for example '{album}' if "
|
||||
+ "photo is in more than one album or '{keyword}' if photo has more than one keyword. "
|
||||
+ "In this case, more than one copy of the photo will be exported, each in a separate directory "
|
||||
+ "or with a different filename."
|
||||
)
|
||||
formatter.write("\n")
|
||||
formatter.write_text(
|
||||
@@ -208,7 +266,11 @@ class ExportCommand(click.Command):
|
||||
+ "has no value, '_' (underscore) will be used as the default value. For example, in the "
|
||||
+ "above example, this would result in '2020/_/photoname.jpg' if address was null."
|
||||
)
|
||||
|
||||
formatter.write("\n")
|
||||
formatter.write_text(
|
||||
'You may specify a null default (e.g. "" or empty string) by omitting the value after '
|
||||
+ 'the comma, e.g. {title,} which would render to "" if title had no value.'
|
||||
)
|
||||
formatter.write("\n")
|
||||
templ_tuples = [("Substitution", "Description")]
|
||||
templ_tuples.extend((k, v) for k, v in TEMPLATE_SUBSTITUTIONS.items())
|
||||
@@ -1333,8 +1395,15 @@ def query(
|
||||
"--use-photos-export",
|
||||
is_flag=True,
|
||||
default=False,
|
||||
hidden=True,
|
||||
help="Force the use of AppleScript to export even if not missing (see also --download-missing).",
|
||||
help="Force the use of AppleScript or PhotoKit to export even if not missing (see also '--download-missing' and '--use-photokit').",
|
||||
)
|
||||
@click.option(
|
||||
"--use-photokit",
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Use with '--download-missing' or '--use-photos-export' to use direct Photos interface instead of AppleScript to export. "
|
||||
"Highly experimental alpha feature; does not work with iTerm2 (use with Terminal.app). "
|
||||
"This is faster and more reliable than the default AppleScript interface.",
|
||||
)
|
||||
@DB_ARGUMENT
|
||||
@click.argument("dest", nargs=1, type=click.Path(exists=True))
|
||||
@@ -1426,6 +1495,7 @@ def export(
|
||||
deleted,
|
||||
deleted_only,
|
||||
use_photos_export,
|
||||
use_photokit,
|
||||
):
|
||||
""" Export photos from the Photos database.
|
||||
Export path DEST is required.
|
||||
@@ -1476,6 +1546,18 @@ def export(
|
||||
click.echo(cli.commands["export"].get_help(ctx), err=True)
|
||||
return
|
||||
|
||||
if use_photokit and not check_photokit_authorization():
|
||||
click.echo(
|
||||
"Requesting access to use your Photos library. Click 'OK' on the dialog box to grant access."
|
||||
)
|
||||
request_photokit_authorization()
|
||||
click.confirm("Have you granted access?")
|
||||
if not check_photokit_authorization():
|
||||
click.echo(
|
||||
"Failed to get access to the Photos library which is needed with `--use-photokit`."
|
||||
)
|
||||
return
|
||||
|
||||
# initialize export flags
|
||||
# by default, will export all versions of photos unless skip flag is set
|
||||
(export_edited, export_bursts, export_live, export_raw) = [
|
||||
@@ -1672,6 +1754,7 @@ def export(
|
||||
convert_to_jpeg=convert_to_jpeg,
|
||||
jpeg_quality=jpeg_quality,
|
||||
ignore_date_modified=ignore_date_modified,
|
||||
use_photokit=use_photokit,
|
||||
)
|
||||
results_exported.extend(results.exported)
|
||||
results_new.extend(results.new)
|
||||
@@ -1722,6 +1805,7 @@ def export(
|
||||
convert_to_jpeg=convert_to_jpeg,
|
||||
jpeg_quality=jpeg_quality,
|
||||
ignore_date_modified=ignore_date_modified,
|
||||
use_photokit=use_photokit,
|
||||
)
|
||||
results_exported.extend(results.exported)
|
||||
results_new.extend(results.new)
|
||||
@@ -2229,6 +2313,7 @@ def export_photo(
|
||||
convert_to_jpeg=False,
|
||||
jpeg_quality=1.0,
|
||||
ignore_date_modified=False,
|
||||
use_photokit=False,
|
||||
):
|
||||
""" Helper function for export that does the actual export
|
||||
|
||||
@@ -2273,15 +2358,17 @@ def export_photo(
|
||||
global VERBOSE
|
||||
VERBOSE = bool(verbose_)
|
||||
|
||||
# TODO: if --skip-original-if-edited, it's possible edited version is on disk but
|
||||
# original is missing, in which case we should download the edited version
|
||||
if not download_missing:
|
||||
if photo.ismissing:
|
||||
space = " " if not verbose_ else ""
|
||||
verbose(f"{space}Skipping missing photo {photo.original_filename}")
|
||||
return ExportResults([], [], [], [], [], [])
|
||||
elif not os.path.exists(photo.path):
|
||||
elif photo.path is None:
|
||||
space = " " if not verbose_ else ""
|
||||
verbose(
|
||||
f"{space}WARNING: file {photo.path} is missing but ismissing=False, "
|
||||
f"{space}WARNING: photo {photo.original_filename} ({photo.uuid}) is missing but ismissing=False, "
|
||||
f"skipping {photo.original_filename}"
|
||||
)
|
||||
return ExportResults([], [], [], [], [], [])
|
||||
@@ -2300,6 +2387,22 @@ def export_photo(
|
||||
|
||||
export_original = not (skip_original_if_edited and photo.hasadjustments)
|
||||
|
||||
# can't export edited if photo doesn't have edited versions
|
||||
export_edited = export_edited if photo.hasadjustments else False
|
||||
|
||||
# slow_mo photos will always have hasadjustments=True even if not edited
|
||||
if photo.hasadjustments and photo.path_edited is None:
|
||||
if photo.slow_mo:
|
||||
export_original = True
|
||||
export_edited = False
|
||||
elif not download_missing:
|
||||
# requested edited version but it's missing, download original
|
||||
export_original = True
|
||||
export_edited = False
|
||||
verbose(
|
||||
f"Edited file for {photo.original_filename} is missing, exporting original"
|
||||
)
|
||||
|
||||
filenames = get_filenames_from_template(photo, filename_template, original_name)
|
||||
for filename in filenames:
|
||||
verbose(f"Exporting {photo.original_filename} ({photo.filename}) as {filename}")
|
||||
@@ -2321,7 +2424,7 @@ def export_photo(
|
||||
download_missing
|
||||
and (
|
||||
photo.ismissing
|
||||
or not os.path.exists(photo.path)
|
||||
or photo.path is None
|
||||
or (export_edited and photo.path_edited is None)
|
||||
)
|
||||
)
|
||||
@@ -2355,6 +2458,7 @@ def export_photo(
|
||||
convert_to_jpeg=convert_to_jpeg,
|
||||
jpeg_quality=jpeg_quality,
|
||||
ignore_date_modified=ignore_date_modified,
|
||||
use_photokit=use_photokit,
|
||||
)
|
||||
|
||||
results_exported.extend(export_results.exported)
|
||||
@@ -2417,6 +2521,7 @@ def export_photo(
|
||||
convert_to_jpeg=convert_to_jpeg,
|
||||
jpeg_quality=jpeg_quality,
|
||||
ignore_date_modified=ignore_date_modified,
|
||||
use_photokit=use_photokit,
|
||||
)
|
||||
|
||||
results_exported.extend(export_results_edited.exported)
|
||||
@@ -2474,7 +2579,7 @@ def get_filenames_from_template(photo, filename_template, original_name):
|
||||
)
|
||||
filenames = [f"{file_}{photo_ext}" for file_ in filenames]
|
||||
else:
|
||||
filenames = [photo.original_filename] if original_name else [photo.filename]
|
||||
filenames = [photo.original_filename] if (original_name and (photo.original_filename is not None)) else [photo.filename]
|
||||
|
||||
filenames = [sanitize_filename(filename) for filename in filenames]
|
||||
return filenames
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
""" version info """
|
||||
|
||||
__version__ = "0.36.7"
|
||||
__version__ = "0.36.23"
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ class _ExifToolProc:
|
||||
],
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.DEVNULL,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
self._process_running = True
|
||||
|
||||
@@ -133,13 +133,19 @@ class ExifTool:
|
||||
""" Basic exiftool interface for reading and writing EXIF tags """
|
||||
|
||||
def __init__(self, filepath, exiftool=None, overwrite=True):
|
||||
""" Return ExifTool object
|
||||
file: path to image file
|
||||
exiftool: path to exiftool, if not specified will look in path
|
||||
overwrite: if True, will overwrite image file without creating backup, default=False """
|
||||
""" Create ExifTool object
|
||||
|
||||
Args:
|
||||
file: path to image file
|
||||
exiftool: path to exiftool, if not specified will look in path
|
||||
overwrite: if True, will overwrite image file without creating backup, default=False
|
||||
Returns:
|
||||
ExifTool instance
|
||||
"""
|
||||
self.file = filepath
|
||||
self.overwrite = overwrite
|
||||
self.data = {}
|
||||
self.error = None
|
||||
# if running as a context manager, self._context_mgr will be True
|
||||
self._context_mgr = False
|
||||
self._exiftoolproc = _ExifToolProc(exiftool=exiftool)
|
||||
@@ -147,8 +153,18 @@ class ExifTool:
|
||||
self._read_exif()
|
||||
|
||||
def setvalue(self, tag, value):
|
||||
""" Set tag to value(s)
|
||||
if value is None, will delete tag """
|
||||
""" Set tag to value(s); if value is None, will delete tag
|
||||
|
||||
Args:
|
||||
tag: str; name of tag to set
|
||||
value: str; value to set tag to
|
||||
|
||||
Returns:
|
||||
True if success otherwise False
|
||||
|
||||
If error generated by exiftool, returns False and sets self.error to error string
|
||||
If called in context manager, returns True (execution is delayed until exiting context manager)
|
||||
"""
|
||||
|
||||
if value is None:
|
||||
value = ""
|
||||
@@ -157,19 +173,32 @@ class ExifTool:
|
||||
command.append("-overwrite_original")
|
||||
if self._context_mgr:
|
||||
self._commands.extend(command)
|
||||
return True
|
||||
else:
|
||||
self.run_commands(*command)
|
||||
_, self.error = self.run_commands(*command)
|
||||
return self.error is None
|
||||
|
||||
def addvalues(self, tag, *values):
|
||||
""" Add one or more value(s) to tag
|
||||
If more than one value is passed, each value will be added to the tag
|
||||
Notes: exiftool may add duplicate values for some tags so the caller must ensure
|
||||
the values being added are not already in the EXIF data
|
||||
For some tags, such as IPTC:Keywords, this will add a new value to the list of keywords,
|
||||
but for others, such as EXIF:ISO, this will literally add a value to the existing value.
|
||||
It's up to the caller to know what exiftool will do for each tag
|
||||
If setvalue called before addvalues, exiftool does not appear to add duplicates,
|
||||
but if addvalues called without first calling setvalue, exiftool will add duplicate values
|
||||
|
||||
Args:
|
||||
tag: str; tag to set
|
||||
*values: str; one or more values to set
|
||||
|
||||
Returns:
|
||||
True if success otherwise False
|
||||
|
||||
If error generated by exiftool, returns False and sets self.error to error string
|
||||
If called in context manager, returns True (execution is delayed until exiting context manager)
|
||||
|
||||
Notes: exiftool may add duplicate values for some tags so the caller must ensure
|
||||
the values being added are not already in the EXIF data
|
||||
For some tags, such as IPTC:Keywords, this will add a new value to the list of keywords,
|
||||
but for others, such as EXIF:ISO, this will literally add a value to the existing value.
|
||||
It's up to the caller to know what exiftool will do for each tag
|
||||
If setvalue called before addvalues, exiftool does not appear to add duplicates,
|
||||
but if addvalues called without first calling setvalue, exiftool will add duplicate values
|
||||
"""
|
||||
if not values:
|
||||
raise ValueError("Must pass at least one value")
|
||||
@@ -185,14 +214,26 @@ class ExifTool:
|
||||
|
||||
if self._context_mgr:
|
||||
self._commands.extend(command)
|
||||
return True
|
||||
else:
|
||||
self.run_commands(*command)
|
||||
_, self.error = self.run_commands(*command)
|
||||
return self.error is None
|
||||
|
||||
def run_commands(self, *commands, no_file=False):
|
||||
""" run commands in the exiftool process and return result
|
||||
no_file: (bool) do not pass the filename to exiftool (default=False)
|
||||
by default, all commands will be run against self.file
|
||||
use no_file=True to run a command without passing the filename """
|
||||
""" Run commands in the exiftool process and return result.
|
||||
|
||||
Args:
|
||||
*commands: exiftool commands to run
|
||||
no_file: (bool) do not pass the filename to exiftool (default=False)
|
||||
by default, all commands will be run against self.file
|
||||
use no_file=True to run a command without passing the filename
|
||||
Returns:
|
||||
(output, errror)
|
||||
output: bytes is containing output of exiftool commands
|
||||
error: if exiftool generated an error, bytes containing error string otherwise None
|
||||
|
||||
Note: Also sets self.error if error generated.
|
||||
"""
|
||||
if not (hasattr(self, "_process") and self._process):
|
||||
raise ValueError("exiftool process is not running")
|
||||
|
||||
@@ -218,9 +259,16 @@ class ExifTool:
|
||||
|
||||
# read the output
|
||||
output = b""
|
||||
error = b""
|
||||
while EXIFTOOL_STAYOPEN_EOF not in str(output):
|
||||
output += self._process.stdout.readline().strip()
|
||||
return output[:-EXIFTOOL_STAYOPEN_EOF_LEN]
|
||||
line = self._process.stdout.readline()
|
||||
if line.startswith(b"Warning"):
|
||||
error += line
|
||||
else:
|
||||
output += line.strip()
|
||||
error = None if error == b"" else error
|
||||
self.error = error
|
||||
return output[:-EXIFTOOL_STAYOPEN_EOF_LEN], error
|
||||
|
||||
@property
|
||||
def pid(self):
|
||||
@@ -230,14 +278,14 @@ class ExifTool:
|
||||
@property
|
||||
def version(self):
|
||||
""" returns exiftool version """
|
||||
ver = self.run_commands("-ver", no_file=True)
|
||||
ver, _ = self.run_commands("-ver", no_file=True)
|
||||
return ver.decode("utf-8")
|
||||
|
||||
def asdict(self):
|
||||
""" return dictionary of all EXIF tags and values from exiftool
|
||||
returns empty dict if no tags
|
||||
"""
|
||||
json_str = self.run_commands("-json")
|
||||
json_str, _ = self.run_commands("-json")
|
||||
if json_str:
|
||||
exifdict = json.loads(json_str)
|
||||
return exifdict[0]
|
||||
@@ -246,7 +294,8 @@ class ExifTool:
|
||||
|
||||
def json(self):
|
||||
""" returns JSON string containing all EXIF tags and values from exiftool """
|
||||
return self.run_commands("-json")
|
||||
json, _ = self.run_commands("-json")
|
||||
return json
|
||||
|
||||
def _read_exif(self):
|
||||
""" read exif data from file """
|
||||
@@ -265,4 +314,4 @@ class ExifTool:
|
||||
if exc_type:
|
||||
return False
|
||||
elif self._commands:
|
||||
self.run_commands(*self._commands)
|
||||
_, self.error = self.run_commands(*self._commands)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
""" FileUtil class with methods for copy, hardlink, unlink, etc. """
|
||||
|
||||
import logging
|
||||
import os
|
||||
import pathlib
|
||||
import stat
|
||||
@@ -74,7 +73,6 @@ class FileUtilMacOS(FileUtilABC):
|
||||
try:
|
||||
os.link(src, dest)
|
||||
except Exception as e:
|
||||
logging.critical(f"os.link returned error: {e}")
|
||||
raise e
|
||||
|
||||
@classmethod
|
||||
@@ -92,7 +90,7 @@ class FileUtilMacOS(FileUtilABC):
|
||||
if src is None or dest is None:
|
||||
raise ValueError("src and dest must not be None", src, dest)
|
||||
|
||||
if not os.path.isfile(src):
|
||||
if not os.path.exists(src):
|
||||
raise FileNotFoundError("src file does not appear to exist", src)
|
||||
|
||||
if norsrc:
|
||||
@@ -104,9 +102,6 @@ class FileUtilMacOS(FileUtilABC):
|
||||
try:
|
||||
result = subprocess.run(command, check=True, stderr=subprocess.PIPE)
|
||||
except subprocess.CalledProcessError as e:
|
||||
logging.critical(
|
||||
f"ditto returned error: {e.returncode} {e.stderr.decode(sys.getfilesystemencoding()).rstrip()}"
|
||||
)
|
||||
raise e
|
||||
|
||||
return result.returncode
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
""" utility functions for validating/sanitizing path components """
|
||||
|
||||
from ._constants import MAX_DIRNAME_LEN, MAX_FILENAME_LEN
|
||||
import pathvalidate
|
||||
|
||||
from ._constants import MAX_DIRNAME_LEN, MAX_FILENAME_LEN
|
||||
|
||||
|
||||
def sanitize_filepath(filepath):
|
||||
""" sanitize a filepath """
|
||||
|
||||
@@ -21,9 +21,10 @@ import re
|
||||
import tempfile
|
||||
from collections import namedtuple # pylint: disable=syntax-error
|
||||
|
||||
import photoscript
|
||||
from mako.template import Template
|
||||
|
||||
from .._applescript import AppleScript
|
||||
# from .._applescript import AppleScript
|
||||
from .._constants import (
|
||||
_MAX_IPTC_KEYWORD_LEN,
|
||||
_OSXPHOTOS_NONE_SENTINEL,
|
||||
@@ -31,9 +32,15 @@ from .._constants import (
|
||||
_UNKNOWN_PERSON,
|
||||
_XMP_TEMPLATE_NAME,
|
||||
)
|
||||
from ..export_db import ExportDBNoOp
|
||||
from ..exiftool import ExifTool
|
||||
from ..export_db import ExportDBNoOp
|
||||
from ..fileutil import FileUtil
|
||||
from ..photokit import (
|
||||
PHOTOS_VERSION_CURRENT,
|
||||
PHOTOS_VERSION_ORIGINAL,
|
||||
PhotoLibrary,
|
||||
PhotoKitFetchFailed,
|
||||
)
|
||||
from ..utils import dd_to_dms_str, findfiles
|
||||
|
||||
ExportResults = namedtuple(
|
||||
@@ -78,33 +85,33 @@ def _export_photo_uuid_applescript(
|
||||
"""
|
||||
|
||||
# setup the applescript to do the export
|
||||
export_scpt = AppleScript(
|
||||
"""
|
||||
on export_by_uuid(theUUID, thePath, original, edited, theTimeOut)
|
||||
tell application "Photos"
|
||||
set thePath to thePath
|
||||
set theItem to media item id theUUID
|
||||
set theFilename to filename of theItem
|
||||
set itemList to {theItem}
|
||||
|
||||
if original then
|
||||
with timeout of theTimeOut seconds
|
||||
export itemList to POSIX file thePath with using originals
|
||||
end timeout
|
||||
end if
|
||||
|
||||
if edited then
|
||||
with timeout of theTimeOut seconds
|
||||
export itemList to POSIX file thePath
|
||||
end timeout
|
||||
end if
|
||||
|
||||
return theFilename
|
||||
end tell
|
||||
# export_scpt = AppleScript(
|
||||
# """
|
||||
# on export_by_uuid(theUUID, thePath, original, edited, theTimeOut)
|
||||
# tell application "Photos"
|
||||
# set thePath to thePath
|
||||
# set theItem to media item id theUUID
|
||||
# set theFilename to filename of theItem
|
||||
# set itemList to {theItem}
|
||||
|
||||
end export_by_uuid
|
||||
"""
|
||||
)
|
||||
# if original then
|
||||
# with timeout of theTimeOut seconds
|
||||
# export itemList to POSIX file thePath with using originals
|
||||
# end timeout
|
||||
# end if
|
||||
|
||||
# if edited then
|
||||
# with timeout of theTimeOut seconds
|
||||
# export itemList to POSIX file thePath
|
||||
# end timeout
|
||||
# end if
|
||||
|
||||
# return theFilename
|
||||
# end tell
|
||||
|
||||
# end export_by_uuid
|
||||
# """
|
||||
# )
|
||||
|
||||
dest = pathlib.Path(dest)
|
||||
if not dest.is_dir():
|
||||
@@ -115,30 +122,36 @@ def _export_photo_uuid_applescript(
|
||||
|
||||
tmpdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
|
||||
|
||||
# export original
|
||||
exported_files = []
|
||||
filename = None
|
||||
try:
|
||||
filename = export_scpt.call(
|
||||
"export_by_uuid", uuid, tmpdir.name, original, edited, timeout
|
||||
)
|
||||
photo = photoscript.Photo(uuid)
|
||||
filename = photo.filename
|
||||
exported_files = photo.export(tmpdir.name, original=original, timeout=timeout)
|
||||
# filename = export_scpt.call(
|
||||
# "export_by_uuid", uuid, tmpdir.name, original, edited, timeout
|
||||
# )
|
||||
except Exception as e:
|
||||
logging.warning(f"Error exporting uuid {uuid}: {e}")
|
||||
return None
|
||||
|
||||
if filename is not None:
|
||||
if exported_files and filename:
|
||||
# need to find actual filename as sometimes Photos renames JPG to jpeg on export
|
||||
# may be more than one file exported (e.g. if Live Photo, Photos exports both .jpeg and .mov)
|
||||
# TemporaryDirectory will cleanup on return
|
||||
filename_stem = pathlib.Path(filename).stem
|
||||
files = glob.glob(os.path.join(tmpdir.name, "*"))
|
||||
exported_paths = []
|
||||
for fname in files:
|
||||
path = pathlib.Path(fname)
|
||||
if len(files) > 1 and not live_photo and path.suffix.lower() == ".mov":
|
||||
for fname in exported_files:
|
||||
path = pathlib.Path(tmpdir.name) / fname
|
||||
if (
|
||||
len(exported_files) > 1
|
||||
and not live_photo
|
||||
and path.suffix.lower() == ".mov"
|
||||
):
|
||||
# it's the .mov part of live photo but not requested, so don't export
|
||||
logging.debug(f"Skipping live photo file {path}")
|
||||
continue
|
||||
if len(files) > 1 and burst and path.stem != filename_stem:
|
||||
if len(exported_files) > 1 and burst and path.stem != filename_stem:
|
||||
# skip any burst photo that's not the one we asked for
|
||||
logging.debug(f"Skipping burst photo file {path}")
|
||||
continue
|
||||
@@ -310,6 +323,7 @@ def export2(
|
||||
convert_to_jpeg=False,
|
||||
jpeg_quality=1.0,
|
||||
ignore_date_modified=False,
|
||||
use_photokit=False,
|
||||
):
|
||||
""" export photo, like export but with update and dry_run options
|
||||
dest: must be valid destination path or exception raised
|
||||
@@ -651,32 +665,73 @@ def export2(
|
||||
# didn't get passed a filename, add _edited
|
||||
filestem = f"{dest.stem}{edited_identifier}"
|
||||
dest = dest.parent / f"{filestem}.jpeg"
|
||||
|
||||
exported = _export_photo_uuid_applescript(
|
||||
self.uuid,
|
||||
dest.parent,
|
||||
filestem=filestem,
|
||||
original=False,
|
||||
edited=True,
|
||||
live_photo=live_photo,
|
||||
timeout=timeout,
|
||||
burst=self.burst,
|
||||
dry_run=dry_run,
|
||||
)
|
||||
if use_photokit:
|
||||
photolib = PhotoLibrary()
|
||||
photo = None
|
||||
try:
|
||||
photo = photolib.fetch_uuid(self.uuid)
|
||||
except PhotoKitFetchFailed:
|
||||
# if failed to find UUID, might be a burst photo
|
||||
if self.burst and self._info["burstUUID"]:
|
||||
bursts = photolib.fetch_burst_uuid(
|
||||
self._info["burstUUID"], all=True
|
||||
)
|
||||
# PhotoKit UUIDs may contain "/L0/001" so only look at beginning
|
||||
photo = [p for p in bursts if p.uuid.startswith(self.uuid)]
|
||||
photo = photo[0] if photo else None
|
||||
if photo:
|
||||
exported = photo.export(
|
||||
dest.parent, dest.name, version=PHOTOS_VERSION_CURRENT
|
||||
)
|
||||
else:
|
||||
exported = []
|
||||
else:
|
||||
exported = _export_photo_uuid_applescript(
|
||||
self.uuid,
|
||||
dest.parent,
|
||||
filestem=filestem,
|
||||
original=False,
|
||||
edited=True,
|
||||
live_photo=live_photo,
|
||||
timeout=timeout,
|
||||
burst=self.burst,
|
||||
dry_run=dry_run,
|
||||
)
|
||||
else:
|
||||
# export original version and not edited
|
||||
filestem = dest.stem
|
||||
exported = _export_photo_uuid_applescript(
|
||||
self.uuid,
|
||||
dest.parent,
|
||||
filestem=filestem,
|
||||
original=True,
|
||||
edited=False,
|
||||
live_photo=live_photo,
|
||||
timeout=timeout,
|
||||
burst=self.burst,
|
||||
dry_run=dry_run,
|
||||
)
|
||||
if use_photokit:
|
||||
photolib = PhotoLibrary()
|
||||
photo = None
|
||||
try:
|
||||
photo = photolib.fetch_uuid(self.uuid)
|
||||
except PhotoKitFetchFailed:
|
||||
# if failed to find UUID, might be a burst photo
|
||||
if self.burst and self._info["burstUUID"]:
|
||||
bursts = photolib.fetch_burst_uuid(
|
||||
self._info["burstUUID"], all=True
|
||||
)
|
||||
# PhotoKit UUIDs may contain "/L0/001" so only look at beginning
|
||||
photo = [p for p in bursts if p.uuid.startswith(self.uuid)]
|
||||
photo = photo[0] if photo else None
|
||||
if photo:
|
||||
exported = photo.export(
|
||||
dest.parent, dest.name, version=PHOTOS_VERSION_ORIGINAL
|
||||
)
|
||||
else:
|
||||
exported = []
|
||||
else:
|
||||
exported = _export_photo_uuid_applescript(
|
||||
self.uuid,
|
||||
dest.parent,
|
||||
filestem=filestem,
|
||||
original=True,
|
||||
edited=False,
|
||||
live_photo=live_photo,
|
||||
timeout=timeout,
|
||||
burst=self.burst,
|
||||
dry_run=dry_run,
|
||||
)
|
||||
if exported:
|
||||
if touch_file:
|
||||
for exported_file in exported:
|
||||
@@ -1072,8 +1127,8 @@ def _exiftool_dict(
|
||||
EXIF:DateTimeOriginal
|
||||
EXIF:OffsetTimeOriginal
|
||||
EXIF:ModifyDate
|
||||
IPTC:DigitalCreationDate
|
||||
IPTC:DateCreated
|
||||
IPTC:TimeCreated
|
||||
"""
|
||||
|
||||
exif = {}
|
||||
@@ -1187,9 +1242,11 @@ def _exiftool_dict(
|
||||
exif["EXIF:OffsetTimeOriginal"] = offsettime
|
||||
|
||||
dateoriginal = date.strftime("%Y:%m:%d")
|
||||
exif["IPTC:DigitalCreationDate"] = dateoriginal
|
||||
exif["IPTC:DateCreated"] = dateoriginal
|
||||
|
||||
timeoriginal = date.strftime(f"%H:%M:%S{offsettime}")
|
||||
exif["IPTC:TimeCreated"] = timeoriginal
|
||||
|
||||
if self.date_modified is not None and not ignore_date_modified:
|
||||
exif["EXIF:ModifyDate"] = self.date_modified.strftime("%Y:%m:%d %H:%M:%S")
|
||||
else:
|
||||
|
||||
@@ -91,9 +91,10 @@ class PhotoInfo:
|
||||
and self.raw_original
|
||||
):
|
||||
# return the JPEG version as that's what Photos 5+ does
|
||||
return self._info["raw_pair_info"]["originalFilename"]
|
||||
original_name = self._info["raw_pair_info"]["originalFilename"]
|
||||
else:
|
||||
return self._info["originalFilename"]
|
||||
original_name = self._info["originalFilename"]
|
||||
return original_name or self.filename
|
||||
|
||||
@property
|
||||
def date(self):
|
||||
@@ -164,6 +165,8 @@ class PhotoInfo:
|
||||
photopath = os.path.join(
|
||||
self._db._masters_path, self._info["imagePath"]
|
||||
)
|
||||
if not os.path.isfile(photopath):
|
||||
photopath = None
|
||||
self._path = photopath
|
||||
return photopath
|
||||
|
||||
@@ -175,6 +178,8 @@ class PhotoInfo:
|
||||
self._info["directory"],
|
||||
self._info["filename"],
|
||||
)
|
||||
if not os.path.isfile(photopath):
|
||||
photopath = None
|
||||
self._path = photopath
|
||||
return photopath
|
||||
|
||||
@@ -188,6 +193,8 @@ class PhotoInfo:
|
||||
self._info["directory"],
|
||||
self._info["filename"],
|
||||
)
|
||||
if not os.path.isfile(photopath):
|
||||
photopath = None
|
||||
self._path = photopath
|
||||
return photopath
|
||||
|
||||
|
||||
1215
osxphotos/photokit.py
Normal file
1215
osxphotos/photokit.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -35,6 +35,7 @@ from .._constants import (
|
||||
from .._version import __version__
|
||||
from ..albuminfo import AlbumInfo, FolderInfo, ImportInfo
|
||||
from ..datetime_utils import datetime_has_tz, datetime_naive_to_local
|
||||
from ..fileutil import FileUtil
|
||||
from ..personinfo import PersonInfo
|
||||
from ..photoinfo import PhotoInfo
|
||||
from ..utils import (
|
||||
@@ -546,6 +547,33 @@ class PhotosDB:
|
||||
|
||||
return dest_path
|
||||
|
||||
# NOTE: This method seems to cause problems with applescript
|
||||
# Bummer...would'be been nice to avoid copying the DB
|
||||
# def _link_db_file(self, fname):
|
||||
# """ links the sqlite database file to a temp file """
|
||||
# """ returns the name of the temp file """
|
||||
# """ If sqlite shared memory and write-ahead log files exist, those are copied too """
|
||||
# # required because python's sqlite3 implementation can't read a locked file
|
||||
# # _, suffix = os.path.splitext(fname)
|
||||
# dest_name = dest_path = ""
|
||||
# try:
|
||||
# dest_name = pathlib.Path(fname).name
|
||||
# dest_path = os.path.join(self._tempdir_name, dest_name)
|
||||
# FileUtil.hardlink(fname, dest_path)
|
||||
# # link write-ahead log and shared memory files (-wal and -shm) files if they exist
|
||||
# if os.path.exists(f"{fname}-wal"):
|
||||
# FileUtil.hardlink(f"{fname}-wal", f"{dest_path}-wal")
|
||||
# if os.path.exists(f"{fname}-shm"):
|
||||
# FileUtil.hardlink(f"{fname}-shm", f"{dest_path}-shm")
|
||||
# except:
|
||||
# print("Error linking " + fname + " to " + dest_path, file=sys.stderr)
|
||||
# raise Exception
|
||||
|
||||
# if _debug():
|
||||
# logging.debug(dest_path)
|
||||
|
||||
# return dest_path
|
||||
|
||||
def _process_database4(self):
|
||||
""" process the Photos database to extract info
|
||||
works on Photos version <= 4.0 """
|
||||
|
||||
@@ -23,12 +23,34 @@ from .path_utils import sanitize_dirname, sanitize_filename, sanitize_pathpart
|
||||
# ensure locale set to user's locale
|
||||
locale.setlocale(locale.LC_ALL, "")
|
||||
|
||||
PHOTO_VIDEO_TYPE_DEFAULTS = {"photo": "photo", "video": "video"}
|
||||
|
||||
MEDIA_TYPE_DEFAULTS = {
|
||||
"selfie": "selfie",
|
||||
"time_lapse": "time_lapse",
|
||||
"panorama": "panorama",
|
||||
"slow_mo": "slow_mo",
|
||||
"screenshot": "screenshot",
|
||||
"portrait": "portrait",
|
||||
"live_photo": "live_photo",
|
||||
"burst": "burst",
|
||||
"photo": "photo",
|
||||
"video": "video",
|
||||
}
|
||||
|
||||
# Permitted substitutions (each of these returns a single value or None)
|
||||
TEMPLATE_SUBSTITUTIONS = {
|
||||
"{name}": "Current filename of the photo",
|
||||
"{original_name}": "Photo's original filename when imported to Photos",
|
||||
"{title}": "Title of the photo",
|
||||
"{descr}": "Description of the photo",
|
||||
"{media_type}": (
|
||||
f"Special media type resolved in this precedence: {', '.join(t for t in MEDIA_TYPE_DEFAULTS)}. "
|
||||
"Defaults to 'photo' or 'video' if no special type. "
|
||||
"Customize one or more media types using format: '{media_type,video=vidéo;time_lapse=vidéo_accélérée}'"
|
||||
),
|
||||
"{photo_or_video}": "'photo' or 'video' depending on what type the image is. To customize, use default value as in '{photo_or_video,photo=fotos;video=videos}'",
|
||||
"{hdr}": "Photo is HDR?; True/False value, use in format '{hdr?VALUE_IF_TRUE,VALUE_IF_FALSE}'",
|
||||
"{created.date}": "Photo's creation date in ISO format, e.g. '2020-03-22'",
|
||||
"{created.year}": "4-digit year of photo creation time",
|
||||
"{created.yy}": "2-digit year of photo creation time",
|
||||
@@ -144,7 +166,7 @@ class PhotoTemplate:
|
||||
Args:
|
||||
template: str template
|
||||
none_str: str to use default for None values, default is '_'
|
||||
path_sep: optional character to use as path separator, default is os.path.sep
|
||||
path_sep: optional string to use as path separator, default is os.path.sep
|
||||
expand_inplace: expand multi-valued substitutions in-place as a single string
|
||||
instead of returning individual strings
|
||||
inplace_sep: optional string to use as separator between multi-valued keywords
|
||||
@@ -159,8 +181,6 @@ class PhotoTemplate:
|
||||
|
||||
if path_sep is None:
|
||||
path_sep = os.path.sep
|
||||
elif path_sep is not None and len(path_sep) != 1:
|
||||
raise ValueError(f"path_sep must be single character: {path_sep}")
|
||||
|
||||
if inplace_sep is None:
|
||||
inplace_sep = ","
|
||||
@@ -174,9 +194,17 @@ class PhotoTemplate:
|
||||
# there would be 6 possible renderings (2 albums x 3 persons)
|
||||
|
||||
# regex to find {template_field,optional_default} in strings
|
||||
# for explanation of regex see https://regex101.com/r/4JJg42/1
|
||||
# pylint: disable=anomalous-backslash-in-string
|
||||
regex = r"(?<!\{)\{([^\\,}]+)(,{0,1}(([\w\-\%. ]+))?)(?=\}(?!\}))\}"
|
||||
regex = (
|
||||
r"(?<!\{)\{" # match { but not {{
|
||||
+ r"([^}]*\+)?" # group 1: optional DELIM+
|
||||
+ r"([^\\,}+\?]+)" # group 2: field name
|
||||
+ r"(\([^{}\)]*\))?" # group 3: optional (PATH_SEP)
|
||||
+ r"(\?[^\\,}]*)?" # group 4: optional ?TRUE_VALUE for boolean fields
|
||||
+ r"(,[\w\=\;\-\%. ]*)?" # group 5: optional ,DEFAULT
|
||||
+ r"(?=\}(?!\}))\}" # match } but not }}
|
||||
)
|
||||
|
||||
if type(template) is not str:
|
||||
raise TypeError(f"template must be type str, not {type(template)}")
|
||||
|
||||
@@ -197,18 +225,33 @@ class PhotoTemplate:
|
||||
# closure to capture photo, none_str, filename, dirname in subst
|
||||
def subst(matchobj):
|
||||
groups = len(matchobj.groups())
|
||||
if groups == 4:
|
||||
if groups == 5:
|
||||
delim = matchobj.group(1)
|
||||
field = matchobj.group(2)
|
||||
path_sep = matchobj.group(3)
|
||||
bool_val = matchobj.group(4)
|
||||
default = matchobj.group(5)
|
||||
|
||||
# drop the '+' on delim
|
||||
delim = delim[:-1] if delim is not None else None
|
||||
# drop () from path_sep
|
||||
path_sep = path_sep.strip("()") if path_sep is not None else None
|
||||
# drop the ? on bool_val
|
||||
bool_val = bool_val[1:] if bool_val is not None else None
|
||||
# drop the comma on default
|
||||
default_val = default[1:] if default is not None else None
|
||||
|
||||
try:
|
||||
val = get_func(matchobj.group(1), matchobj.group(3))
|
||||
val = get_func(field, default_val, bool_val, delim, path_sep)
|
||||
except ValueError:
|
||||
return matchobj.group(0)
|
||||
|
||||
if val is None:
|
||||
val = (
|
||||
matchobj.group(3)
|
||||
if matchobj.group(3) is not None
|
||||
else none_str
|
||||
)
|
||||
# field valid but didn't match a value
|
||||
if default == ",":
|
||||
val = ""
|
||||
else:
|
||||
val = default_val if default_val is not None else none_str
|
||||
|
||||
return val
|
||||
else:
|
||||
@@ -249,14 +292,30 @@ class PhotoTemplate:
|
||||
rendered_strings = [rendered]
|
||||
for field in MULTI_VALUE_SUBSTITUTIONS:
|
||||
# Build a regex that matches only the field being processed
|
||||
re_str = r"(?<!\\)\{(" + field + r")(,(([\w\-\%. ]{0,})))?\}"
|
||||
re_str = (
|
||||
r"(?<!\{)\{" # match { but not {{
|
||||
+ r"([^}]*\+)?" # group 1: optional DELIM+
|
||||
+ r"("
|
||||
+ field # group 2: field name
|
||||
+ r")"
|
||||
+ r"(\([^{}\)]*\))?" # group 3: optional (PATH_SEP)
|
||||
+ r"(\?[^\\,}]*)?" # group 4: optional ?TRUE_VALUE for boolean fields
|
||||
+ r"(,[\w\=\;\-\%. ]*)?" # group 5: optional ,DEFAULT
|
||||
+ r"(?=\}(?!\}))\}" # match } but not }}
|
||||
)
|
||||
regex_multi = re.compile(re_str)
|
||||
|
||||
# holds each of the new rendered_strings, dict to avoid repeats (dict.keys())
|
||||
new_strings = {}
|
||||
|
||||
for str_template in rendered_strings:
|
||||
if regex_multi.search(str_template):
|
||||
matches = regex_multi.search(str_template)
|
||||
if matches:
|
||||
path_sep = (
|
||||
matches.group(3).strip("()")
|
||||
if matches.group(3) is not None
|
||||
else path_sep
|
||||
)
|
||||
values = self.get_template_value_multi(
|
||||
field,
|
||||
path_sep,
|
||||
@@ -264,15 +323,14 @@ class PhotoTemplate:
|
||||
dirname=dirname,
|
||||
replacement=replacement,
|
||||
)
|
||||
if expand_inplace:
|
||||
# instead of returning multiple strings, join values into a single string
|
||||
val = (
|
||||
inplace_sep.join(sorted(values))
|
||||
if values and values[0]
|
||||
else None
|
||||
if expand_inplace or matches.group(1) is not None:
|
||||
delim = (
|
||||
matches.group(1)[:-1] if matches.group(1) is not None else inplace_sep
|
||||
)
|
||||
# instead of returning multiple strings, join values into a single string
|
||||
val = delim.join(sorted(values)) if values and values[0] else None
|
||||
|
||||
def lookup_template_value_multi(lookup_value, _):
|
||||
def lookup_template_value_multi(lookup_value, *_):
|
||||
""" Closure passed to make_subst_function get_func
|
||||
Capture val and field in the closure
|
||||
Allows make_subst_function to be re-used w/o modification
|
||||
@@ -293,7 +351,7 @@ class PhotoTemplate:
|
||||
# create a new template string for each value
|
||||
for val in values:
|
||||
|
||||
def lookup_template_value_multi(lookup_value, _):
|
||||
def lookup_template_value_multi(lookup_value, *_):
|
||||
""" Closure passed to make_subst_function get_func
|
||||
Capture val and field in the closure
|
||||
Allows make_subst_function to be re-used w/o modification
|
||||
@@ -319,9 +377,9 @@ class PhotoTemplate:
|
||||
for rendered_str in rendered_strings:
|
||||
unmatched.extend(
|
||||
[
|
||||
no_match[0]
|
||||
no_match[1]
|
||||
for no_match in re.findall(regex, rendered_str)
|
||||
if no_match[0] not in unmatched
|
||||
if no_match[1] not in unmatched
|
||||
]
|
||||
)
|
||||
|
||||
@@ -339,13 +397,24 @@ class PhotoTemplate:
|
||||
return rendered_strings, unmatched
|
||||
|
||||
def get_template_value(
|
||||
self, field, default, filename=False, dirname=False, replacement=":"
|
||||
self,
|
||||
field,
|
||||
default,
|
||||
bool_val=None,
|
||||
delim=None,
|
||||
path_sep=None,
|
||||
filename=False,
|
||||
dirname=False,
|
||||
replacement=":",
|
||||
):
|
||||
"""lookup value for template field (single-value template substitutions)
|
||||
|
||||
Args:
|
||||
field: template field to find value for.
|
||||
default: the default value provided by the user
|
||||
bool_val: True value if expression is boolean
|
||||
delim: delimiter for expand in place
|
||||
path_sep: path separator for fields that are path-like
|
||||
filename: if True, template output will be sanitized to produce valid file name
|
||||
dirname: if True, template output will be sanitized to produce valid directory name
|
||||
replacement: str, value to replace any illegal file path characters with; default = ":"
|
||||
@@ -372,6 +441,12 @@ class PhotoTemplate:
|
||||
value = self.photo.title
|
||||
elif field == "descr":
|
||||
value = self.photo.description
|
||||
elif field == "media_type":
|
||||
value = self.get_media_type(default)
|
||||
elif field == "photo_or_video":
|
||||
value = self.get_photo_video_type(default)
|
||||
elif field == "hdr":
|
||||
value = self.get_photo_hdr(default, bool_val)
|
||||
elif field == "created.date":
|
||||
value = DateTimeFormatter(self.photo.date).date
|
||||
elif field == "created.year":
|
||||
@@ -667,3 +742,66 @@ class PhotoTemplate:
|
||||
values = values or [None]
|
||||
return values
|
||||
|
||||
def get_photo_video_type(self, default):
|
||||
""" return media type, e.g. photo or video """
|
||||
default_dict = parse_default_kv(default, PHOTO_VIDEO_TYPE_DEFAULTS)
|
||||
if self.photo.isphoto:
|
||||
return default_dict["photo"]
|
||||
else:
|
||||
return default_dict["video"]
|
||||
|
||||
def get_media_type(self, default):
|
||||
""" return special media type, e.g. slow_mo, panorama, etc., defaults to photo or video if no special type """
|
||||
default_dict = parse_default_kv(default, MEDIA_TYPE_DEFAULTS)
|
||||
p = self.photo
|
||||
if p.selfie:
|
||||
return default_dict["selfie"]
|
||||
elif p.time_lapse:
|
||||
return default_dict["time_lapse"]
|
||||
elif p.panorama:
|
||||
return default_dict["panorama"]
|
||||
elif p.slow_mo:
|
||||
return default_dict["slow_mo"]
|
||||
elif p.screenshot:
|
||||
return default_dict["screenshot"]
|
||||
elif p.portrait:
|
||||
return default_dict["portrait"]
|
||||
elif p.live_photo:
|
||||
return default_dict["live_photo"]
|
||||
elif p.burst:
|
||||
return default_dict["burst"]
|
||||
elif p.ismovie:
|
||||
return default_dict["video"]
|
||||
else:
|
||||
return default_dict["photo"]
|
||||
|
||||
def get_photo_hdr(self, default, bool_val):
|
||||
if self.photo.hdr:
|
||||
return bool_val
|
||||
else:
|
||||
return default
|
||||
|
||||
|
||||
def parse_default_kv(default, default_dict):
|
||||
""" parse a string in form key1=value1;key2=value2,... as used for some template fields
|
||||
|
||||
Args:
|
||||
default: str, in form 'photo=foto;video=vidéo'
|
||||
default_dict: dict, in form {"photo": "fotos", "video": "vidéos"} with default values
|
||||
|
||||
Returns:
|
||||
dict in form {"photo": "fotos", "video": "vidéos"}
|
||||
"""
|
||||
|
||||
default_dict_ = default_dict.copy()
|
||||
if default:
|
||||
defaults = default.split(";")
|
||||
for kv in defaults:
|
||||
try:
|
||||
k, v = kv.split("=")
|
||||
k = k.strip()
|
||||
v = v.strip()
|
||||
default_dict_[k] = v
|
||||
except ValueError:
|
||||
pass
|
||||
return default_dict_
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
% if desc is None:
|
||||
<dc:description></dc:description>
|
||||
% else:
|
||||
<dc:description>${desc}</dc:description>
|
||||
<dc:description>${desc | x}</dc:description>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
% if title is None:
|
||||
<dc:title></dc:title>
|
||||
% else:
|
||||
<dc:title>${title}</dc:title>
|
||||
<dc:title>${title | x}</dc:title>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<dc:subject>
|
||||
<rdf:Seq>
|
||||
% for subj in subject:
|
||||
<rdf:li>${subj}</rdf:li>
|
||||
<rdf:li>${subj | x}</rdf:li>
|
||||
% endfor
|
||||
</rdf:Seq>
|
||||
</dc:subject>
|
||||
@@ -48,7 +48,7 @@
|
||||
<Iptc4xmpExt:PersonInImage>
|
||||
<rdf:Bag>
|
||||
% for person in persons:
|
||||
<rdf:li>${person}</rdf:li>
|
||||
<rdf:li>${person | x}</rdf:li>
|
||||
% endfor
|
||||
</rdf:Bag>
|
||||
</Iptc4xmpExt:PersonInImage>
|
||||
@@ -60,7 +60,7 @@
|
||||
<digiKam:TagsList>
|
||||
<rdf:Seq>
|
||||
% for keyword in keywords:
|
||||
<rdf:li>${keyword}</rdf:li>
|
||||
<rdf:li>${keyword | x}</rdf:li>
|
||||
% endfor
|
||||
</rdf:Seq>
|
||||
</digiKam:TagsList>
|
||||
@@ -81,10 +81,8 @@
|
||||
|
||||
<%def name="gps_info(latitude, longitude)">
|
||||
% if latitude is not None and longitude is not None:
|
||||
<exif:GPSLongitudeRef>${"E" if longitude >= 0 else "W"}</exif:GPSLongitudeRef>
|
||||
<exif:GPSLongitude>${abs(longitude)}</exif:GPSLongitude>
|
||||
<exif:GPSLatitude>${abs(latitude)}</exif:GPSLatitude>
|
||||
<exif:GPSLatitudeRef>${"N" if latitude >= 0 else "S"}</exif:GPSLatitudeRef>
|
||||
<exif:GPSLongitude>${int(abs(longitude))},${(abs(longitude) % 1) * 60}${"E" if longitude >= 0 else "W"}</exif:GPSLongitude>
|
||||
<exif:GPSLatitude>${int(abs(latitude))},${(abs(latitude) % 1) * 60}${"N" if latitude >= 0 else "S"}</exif:GPSLatitude>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ from plistlib import load as plistload
|
||||
import CoreFoundation
|
||||
import CoreServices
|
||||
import objc
|
||||
from Foundation import *
|
||||
|
||||
from ._constants import UNICODE_FORMAT
|
||||
from .fileutil import FileUtil
|
||||
@@ -57,10 +56,12 @@ def _debug():
|
||||
""" returns True if debugging turned on (via _set_debug), otherwise, false """
|
||||
return _DEBUG
|
||||
|
||||
|
||||
def noop(*args, **kwargs):
|
||||
""" do nothing (no operation) """
|
||||
pass
|
||||
|
||||
|
||||
def _get_os_version():
|
||||
# returns tuple containing OS version
|
||||
# e.g. 10.13.6 = (10, 13, 6)
|
||||
@@ -200,7 +201,7 @@ def get_last_library_path():
|
||||
# pylint: disable=no-member
|
||||
# pylint: disable=undefined-variable
|
||||
photosurl = CoreFoundation.CFURLCreateByResolvingBookmarkData(
|
||||
kCFAllocatorDefault, photosurlref, 0, None, None, None, None
|
||||
CoreFoundation.kCFAllocatorDefault, photosurlref, 0, None, None, None, None
|
||||
)
|
||||
|
||||
# the CFURLRef we got is a sruct that python treats as an array
|
||||
@@ -361,9 +362,35 @@ def _db_is_locked(dbname):
|
||||
|
||||
def normalize_unicode(value):
|
||||
""" normalize unicode data """
|
||||
if value is not None:
|
||||
if not isinstance(value, str):
|
||||
raise ValueError("value must be str")
|
||||
return unicodedata.normalize(UNICODE_FORMAT, value)
|
||||
else:
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
if not isinstance(value, str):
|
||||
raise ValueError("value must be str")
|
||||
return unicodedata.normalize(UNICODE_FORMAT, value)
|
||||
|
||||
|
||||
def increment_filename(filepath):
|
||||
""" Return filename (1).ext, etc if filename.ext exists
|
||||
|
||||
If file exists in filename's parent folder with same stem as filename,
|
||||
add (1), (2), etc. until a non-existing filename is found.
|
||||
|
||||
Args:
|
||||
filepath: str; full path, including file name
|
||||
|
||||
Returns:
|
||||
new filepath (or same if not incremented)
|
||||
|
||||
Note: This obviously is subject to race condition so using with caution.
|
||||
"""
|
||||
dest = pathlib.Path(str(filepath))
|
||||
count = 1
|
||||
dest_files = findfiles(f"{dest.stem}*", str(dest.parent))
|
||||
dest_files = [pathlib.Path(f).stem.lower() for f in dest_files]
|
||||
dest_new = dest.stem
|
||||
while dest_new.lower() in dest_files:
|
||||
dest_new = f"{dest.stem} ({count})"
|
||||
count += 1
|
||||
dest = dest.parent / f"{dest_new}{dest.suffix}"
|
||||
return str(dest)
|
||||
|
||||
@@ -47,6 +47,7 @@ parso==0.6.2
|
||||
pathspec==0.7.0
|
||||
pathvalidate==2.2.1
|
||||
pexpect==4.8.0
|
||||
photoscript==0.1.0
|
||||
pickleshare==0.7.5
|
||||
Pillow==7.2.0
|
||||
pkginfo==1.5.0.1
|
||||
|
||||
1
setup.py
1
setup.py
@@ -79,6 +79,7 @@ setup(
|
||||
"pathvalidate==2.2.1",
|
||||
"dataclasses==0.7;python_version<'3.7'",
|
||||
"wurlitzer>=2.0.1",
|
||||
"photoscript>=0.1.0",
|
||||
],
|
||||
entry_points={"console_scripts": ["osxphotos=osxphotos.__main__:cli"]},
|
||||
include_package_data=True,
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
114
tests/tempdiskimage.py
Normal file
114
tests/tempdiskimage.py
Normal file
@@ -0,0 +1,114 @@
|
||||
""" Create a temporary disk image on MacOS """
|
||||
|
||||
import pathlib
|
||||
import platform
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
|
||||
class TempDiskImage:
|
||||
""" Create and mount a temporary disk image """
|
||||
|
||||
def __init__(self, size=100, prefix=None):
|
||||
""" Create and mount a temporary disk image.
|
||||
|
||||
Args:
|
||||
size: int; size in MB of disk image, default = 100
|
||||
prefix: str; optional prefix to prepend to name of the temporary disk image
|
||||
name: str; name of the mounted volume, default = "TemporaryDiskImage"
|
||||
|
||||
Raises:
|
||||
TypeError if size is not int
|
||||
RunTimeError if not on MacOS
|
||||
"""
|
||||
if type(size) != int:
|
||||
raise TypeError("size must be int")
|
||||
|
||||
system = platform.system()
|
||||
if system != "Darwin":
|
||||
raise RuntimeError("TempDiskImage only runs on MacOS")
|
||||
|
||||
self._tempdir = tempfile.TemporaryDirectory()
|
||||
# hacky mktemp: this could create a race condition but unlikely given it's created in a TemporaryDirectory
|
||||
prefix = "TemporaryDiskImage" if prefix is None else prefix
|
||||
volume_name = f"{prefix}_{str(time.time()).replace('.','_')}_{str(time.perf_counter()).replace('.','_')}"
|
||||
image_name = f"{volume_name}.dmg"
|
||||
image_path = pathlib.Path(self._tempdir.name) / image_name
|
||||
hdiutil = subprocess.run(
|
||||
[
|
||||
"/usr/bin/hdiutil",
|
||||
"create",
|
||||
"-size",
|
||||
f"{size}m",
|
||||
"-fs",
|
||||
"HFS+",
|
||||
"-volname",
|
||||
volume_name,
|
||||
image_path,
|
||||
],
|
||||
check=True,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
)
|
||||
|
||||
if "created" not in hdiutil.stdout:
|
||||
raise OSError(f"Could not create DMG {image_path}")
|
||||
|
||||
self.path = image_path
|
||||
self._mount_point, self.name = self._mount_image(self.path)
|
||||
|
||||
def _mount_image(self, image_path):
|
||||
""" mount a DMG file and return path, returns (mount_point, path) """
|
||||
hdiutil = subprocess.run(
|
||||
["/usr/bin/hdiutil", "attach", image_path],
|
||||
check=True,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
)
|
||||
mount_point, path = None, None
|
||||
for line in hdiutil.stdout.split("\n"):
|
||||
line = line.strip()
|
||||
if "Apple_HFS" not in line:
|
||||
continue
|
||||
output = line.split()
|
||||
if len(output) < 3:
|
||||
raise ValueError(f"Error mounting disk image {image_path}")
|
||||
mount_point = output[0]
|
||||
path = output[2]
|
||||
break
|
||||
return (mount_point, path)
|
||||
|
||||
def unmount(self):
|
||||
try:
|
||||
if self._mount_point:
|
||||
hdiutil = subprocess.run(
|
||||
["/usr/bin/hdiutil", "detach", self._mount_point],
|
||||
check=True,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
)
|
||||
self._mount_point = None
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self.unmount()
|
||||
if exc_type:
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Create a temporary disk image, 50mb in size
|
||||
img = TempDiskImage(size=50, prefix="MyDiskImage")
|
||||
# Be sure to unmount it, image will be cleaned up automatically
|
||||
img.unmount()
|
||||
|
||||
# Or use it as a context handler
|
||||
# Default values are 100mb and prefix = "TemporaryDiskImage"
|
||||
with TempDiskImage() as img:
|
||||
print(f"image: {img.path}")
|
||||
print(f"mounted at: {img.name}")
|
||||
@@ -177,6 +177,12 @@ RAW_DICT = {
|
||||
),
|
||||
}
|
||||
|
||||
ORIGINAL_FILENAME_DICT = {
|
||||
"uuid": "D79B8D77-BFFC-460B-9312-034F2877D35B",
|
||||
"filename": "D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg",
|
||||
"original_filename": "Pumkins2.jpg",
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def photosdb():
|
||||
@@ -864,6 +870,27 @@ def test_export_14(photosdb, caplog):
|
||||
assert "Invalid destination suffix" not in caplog.text
|
||||
|
||||
|
||||
def test_export_no_original_filename(photosdb):
|
||||
# test export OK if original filename is null
|
||||
# issue #267
|
||||
|
||||
tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
|
||||
dest = tempdir.name
|
||||
photos = photosdb.photos(uuid=[UUID_DICT["export"]])
|
||||
|
||||
# monkey patch original_filename for testing
|
||||
original_filename = photos[0]._info["originalFilename"]
|
||||
photos[0]._info["originalFilename"] = None
|
||||
filename = f"{photos[0].uuid}.jpeg"
|
||||
expected_dest = os.path.join(dest, filename)
|
||||
got_dest = photos[0].export(dest)[0]
|
||||
|
||||
assert got_dest == expected_dest
|
||||
assert os.path.isfile(got_dest)
|
||||
|
||||
photos[0]._info["originalFilename"] = original_filename
|
||||
|
||||
|
||||
def test_eq():
|
||||
""" Test equality of two PhotoInfo objects """
|
||||
|
||||
@@ -1070,3 +1097,18 @@ def test_verbose(capsys):
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB, verbose=print)
|
||||
captured = capsys.readouterr()
|
||||
assert "Processing database" in captured.out
|
||||
|
||||
|
||||
def test_original_filename(photosdb):
|
||||
""" test original filename """
|
||||
uuid = ORIGINAL_FILENAME_DICT["uuid"]
|
||||
photo = photosdb.get_photo(uuid)
|
||||
assert photo.original_filename == ORIGINAL_FILENAME_DICT["original_filename"]
|
||||
assert photo.filename == ORIGINAL_FILENAME_DICT["filename"]
|
||||
|
||||
# monkey patch
|
||||
original_filename = photo._info["originalFilename"]
|
||||
photo._info["originalFilename"] = None
|
||||
assert photo.original_filename == ORIGINAL_FILENAME_DICT["filename"]
|
||||
photo._info["originalFilename"] = original_filename
|
||||
|
||||
|
||||
@@ -2693,8 +2693,8 @@ def test_export_sidecar_keyword_template():
|
||||
"EXIF:DateTimeOriginal": "2018:09:28 16:07:07",
|
||||
"EXIF:CreateDate": "2018:09:28 16:07:07",
|
||||
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||
"IPTC:DigitalCreationDate": "2018:09:28",
|
||||
"IPTC:DateCreated": "2018:09:28",
|
||||
"IPTC:DateCreated": "2018:09:28",
|
||||
"IPTC:TimeCreated": "16:07:07-04:00",
|
||||
"EXIF:ModifyDate": "2018:09:28 16:07:07"}]
|
||||
"""
|
||||
)[0]
|
||||
|
||||
@@ -103,10 +103,28 @@ def test_setvalue_1():
|
||||
|
||||
exif = osxphotos.exiftool.ExifTool(tempfile)
|
||||
exif.setvalue("IPTC:Keywords", "test")
|
||||
assert not exif.error
|
||||
|
||||
exif._read_exif()
|
||||
assert exif.data["IPTC:Keywords"] == "test"
|
||||
|
||||
|
||||
def test_setvalue_error():
|
||||
# test setting illegal tag value generates error
|
||||
import os.path
|
||||
import tempfile
|
||||
import osxphotos.exiftool
|
||||
from osxphotos.fileutil import FileUtil
|
||||
|
||||
tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
|
||||
tempfile = os.path.join(tempdir.name, os.path.basename(TEST_FILE_ONE_KEYWORD))
|
||||
FileUtil.copy(TEST_FILE_ONE_KEYWORD, tempfile)
|
||||
|
||||
exif = osxphotos.exiftool.ExifTool(tempfile)
|
||||
exif.setvalue("IPTC:Foo", "test")
|
||||
assert exif.error
|
||||
|
||||
|
||||
def test_setvalue_context_manager():
|
||||
# test setting a tag value as context manager
|
||||
import os.path
|
||||
@@ -124,6 +142,8 @@ def test_setvalue_context_manager():
|
||||
exif.setvalue("XMP:Title", "title")
|
||||
exif.setvalue("XMP:Subject", "subject")
|
||||
|
||||
assert exif.error is None
|
||||
|
||||
exif2 = osxphotos.exiftool.ExifTool(tempfile)
|
||||
exif2._read_exif()
|
||||
assert sorted(exif2.data["IPTC:Keywords"]) == ["test1", "test2"]
|
||||
@@ -131,6 +151,22 @@ def test_setvalue_context_manager():
|
||||
assert exif2.data["XMP:Subject"] == "subject"
|
||||
|
||||
|
||||
def test_setvalue_context_manager_error():
|
||||
# test setting a tag value as context manager when error generated
|
||||
import os.path
|
||||
import tempfile
|
||||
import osxphotos.exiftool
|
||||
from osxphotos.fileutil import FileUtil
|
||||
|
||||
tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
|
||||
tempfile = os.path.join(tempdir.name, os.path.basename(TEST_FILE_ONE_KEYWORD))
|
||||
FileUtil.copy(TEST_FILE_ONE_KEYWORD, tempfile)
|
||||
|
||||
with osxphotos.exiftool.ExifTool(tempfile) as exif:
|
||||
exif.setvalue("Foo:Bar", "test1")
|
||||
assert exif.error
|
||||
|
||||
|
||||
def test_clear_value():
|
||||
# test clearing a tag value
|
||||
import os.path
|
||||
|
||||
@@ -11,9 +11,9 @@ pytestmark = pytest.mark.skipif(
|
||||
PHOTOS_DB = "/Users/rhet/Pictures/Photos Library.photoslibrary"
|
||||
|
||||
UUID_DICT = {
|
||||
"has_adjustments": "A8111956-E900-4DEC-9191-A04A87C07BC5",
|
||||
"no_adjustments": "EA7BB55F-92F1-4818-94E3-E8DEDC6B2E31",
|
||||
"live": "9032C168-9319-40C0-8210-5ADC42F4C603",
|
||||
"has_adjustments": "2B2D5434-6D31-49E2-BF47-B973D34A317B",
|
||||
"no_adjustments": "A8D646C3-89A9-4D74-8001-4EB46BA55B94",
|
||||
"live": "BFF29EBD-22DF-4FCF-9817-317E7104EA50",
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ EXIF_JSON_EXPECTED = """
|
||||
"EXIF:DateTimeOriginal": "2019:04:15 14:40:24",
|
||||
"EXIF:CreateDate": "2019:04:15 14:40:24",
|
||||
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||
"IPTC:DigitalCreationDate": "2019:04:15",
|
||||
"IPTC:DateCreated": "2019:04:15",
|
||||
"IPTC:TimeCreated": "14:40:24-04:00",
|
||||
"EXIF:ModifyDate": "2019:07:27 17:33:28"}]
|
||||
"""
|
||||
|
||||
@@ -94,8 +94,8 @@ EXIF_JSON_EXPECTED_IGNORE_DATE_MODIFIED = """
|
||||
"EXIF:DateTimeOriginal": "2019:04:15 14:40:24",
|
||||
"EXIF:CreateDate": "2019:04:15 14:40:24",
|
||||
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||
"IPTC:DigitalCreationDate": "2019:04:15",
|
||||
"IPTC:DateCreated": "2019:04:15",
|
||||
"IPTC:TimeCreated": "14:40:24-04:00",
|
||||
"EXIF:ModifyDate": "2019:04:15 14:40:24"}]
|
||||
"""
|
||||
|
||||
@@ -554,8 +554,8 @@ def test_exiftool_json_sidecar_keyword_template_long(caplog):
|
||||
"EXIF:DateTimeOriginal": "2019:04:15 14:40:24",
|
||||
"EXIF:CreateDate": "2019:04:15 14:40:24",
|
||||
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||
"IPTC:DigitalCreationDate": "2019:04:15",
|
||||
"IPTC:DateCreated": "2019:04:15",
|
||||
"IPTC:TimeCreated": "14:40:24-04:00",
|
||||
"EXIF:ModifyDate": "2019:07:27 17:33:28"}]
|
||||
"""
|
||||
)[0]
|
||||
@@ -604,8 +604,8 @@ def test_exiftool_json_sidecar_keyword_template():
|
||||
"EXIF:DateTimeOriginal": "2019:04:15 14:40:24",
|
||||
"EXIF:CreateDate": "2019:04:15 14:40:24",
|
||||
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||
"IPTC:DigitalCreationDate": "2019:04:15",
|
||||
"IPTC:DateCreated": "2019:04:15",
|
||||
"IPTC:TimeCreated": "14:40:24-04:00",
|
||||
"EXIF:ModifyDate": "2019:07:27 17:33:28"}]
|
||||
"""
|
||||
)[0]
|
||||
@@ -666,8 +666,8 @@ def test_exiftool_json_sidecar_use_persons_keyword():
|
||||
"EXIF:DateTimeOriginal": "2018:09:28 15:35:49",
|
||||
"EXIF:CreateDate": "2018:09:28 15:35:49",
|
||||
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||
"IPTC:DigitalCreationDate": "2018:09:28",
|
||||
"IPTC:DateCreated": "2018:09:28",
|
||||
"IPTC:TimeCreated": "15:35:49-04:00",
|
||||
"EXIF:ModifyDate": "2018:09:28 15:35:49"}]
|
||||
"""
|
||||
)[0]
|
||||
@@ -709,8 +709,8 @@ def test_exiftool_json_sidecar_use_albums_keyword():
|
||||
"EXIF:DateTimeOriginal": "2018:09:28 15:35:49",
|
||||
"EXIF:CreateDate": "2018:09:28 15:35:49",
|
||||
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||
"IPTC:DigitalCreationDate": "2018:09:28",
|
||||
"IPTC:DateCreated": "2018:09:28",
|
||||
"IPTC:TimeCreated": "15:35:49-04:00",
|
||||
"EXIF:ModifyDate": "2018:09:28 15:35:49"}]
|
||||
"""
|
||||
)[0]
|
||||
@@ -744,7 +744,7 @@ def test_xmp_sidecar_is_valid(tmp_path):
|
||||
xmp_file = tmp_path / XMP_FILENAME
|
||||
assert xmp_file.is_file()
|
||||
exiftool = ExifTool(str(xmp_file))
|
||||
output = exiftool.run_commands("-validate", "-warning")
|
||||
output, _ = exiftool.run_commands("-validate", "-warning")
|
||||
assert output == b"[ExifTool] Validate : 0 0 0"
|
||||
|
||||
|
||||
@@ -1029,7 +1029,7 @@ def test_xmp_sidecar_gps():
|
||||
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
|
||||
<photoshop:SidecarForExtension>jpg</photoshop:SidecarForExtension>
|
||||
<dc:description></dc:description>
|
||||
<dc:title>St. James's Park</dc:title>
|
||||
<dc:title>St. James's Park</dc:title>
|
||||
<!-- keywords and persons listed in <dc:subject> as Photos does -->
|
||||
<dc:subject>
|
||||
<rdf:Seq>
|
||||
@@ -1038,7 +1038,7 @@ def test_xmp_sidecar_gps():
|
||||
<rdf:li>London</rdf:li>
|
||||
<rdf:li>United Kingdom</rdf:li>
|
||||
<rdf:li>London 2018</rdf:li>
|
||||
<rdf:li>St. James's Park</rdf:li>
|
||||
<rdf:li>St. James's Park</rdf:li>
|
||||
</rdf:Seq>
|
||||
</dc:subject>
|
||||
<photoshop:DateCreated>2018-10-13T09:18:12.501000-04:00</photoshop:DateCreated>
|
||||
@@ -1055,7 +1055,7 @@ def test_xmp_sidecar_gps():
|
||||
<rdf:li>London</rdf:li>
|
||||
<rdf:li>United Kingdom</rdf:li>
|
||||
<rdf:li>London 2018</rdf:li>
|
||||
<rdf:li>St. James's Park</rdf:li>
|
||||
<rdf:li>St. James's Park</rdf:li>
|
||||
</rdf:Seq>
|
||||
</digiKam:TagsList>
|
||||
</rdf:Description>
|
||||
@@ -1066,10 +1066,8 @@ def test_xmp_sidecar_gps():
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about=""
|
||||
xmlns:exif='http://ns.adobe.com/exif/1.0/'>
|
||||
<exif:GPSLongitudeRef>W</exif:GPSLongitudeRef>
|
||||
<exif:GPSLongitude>0.1318055</exif:GPSLongitude>
|
||||
<exif:GPSLatitude>51.50357167</exif:GPSLatitude>
|
||||
<exif:GPSLatitudeRef>N</exif:GPSLatitudeRef>
|
||||
<exif:GPSLongitude>0,7.908329999999999W</exif:GPSLongitude>
|
||||
<exif:GPSLatitude>51,30.21430019999997N</exif:GPSLatitude>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>"""
|
||||
|
||||
@@ -20,10 +20,10 @@ NAMES_DICT = {
|
||||
"heic": "7783E8E6-9CAC-40F3-BE22-81FB7051C266.jpeg",
|
||||
}
|
||||
|
||||
UUID_LIVE_HEIC = "1337F3F6-5C9F-4FC7-80CC-BD9A5B928F72"
|
||||
UUID_LIVE_HEIC = "612CE30B-3D8F-417A-9B14-EC42CBA10ACC"
|
||||
NAMES_LIVE_HEIC = [
|
||||
"1337F3F6-5C9F-4FC7-80CC-BD9A5B928F72.jpeg",
|
||||
"1337F3F6-5C9F-4FC7-80CC-BD9A5B928F72.mov",
|
||||
"612CE30B-3D8F-417A-9B14-EC42CBA10ACC.jpeg",
|
||||
"612CE30B-3D8F-417A-9B14-EC42CBA10ACC.mov",
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -58,8 +58,8 @@ EXIF_JSON_EXPECTED = """
|
||||
"EXIF:DateTimeOriginal": "2018:10:13 09:18:12",
|
||||
"EXIF:CreateDate": "2018:10:13 09:18:12",
|
||||
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||
"IPTC:DigitalCreationDate": "2018:10:13",
|
||||
"IPTC:DateCreated": "2018:10:13",
|
||||
"IPTC:TimeCreated": "09:18:12-04:00",
|
||||
"EXIF:ModifyDate": "2019:12:01 11:43:45"}]
|
||||
"""
|
||||
|
||||
|
||||
387
tests/test_photokit.py
Normal file
387
tests/test_photokit.py
Normal file
@@ -0,0 +1,387 @@
|
||||
""" test photokit.py methods """
|
||||
|
||||
import os
|
||||
import pathlib
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
|
||||
from osxphotos.photokit import (
|
||||
LivePhotoAsset,
|
||||
PhotoAsset,
|
||||
PhotoLibrary,
|
||||
VideoAsset,
|
||||
PHOTOS_VERSION_CURRENT,
|
||||
PHOTOS_VERSION_ORIGINAL,
|
||||
PHOTOS_VERSION_UNADJUSTED,
|
||||
)
|
||||
|
||||
skip_test = "OSXPHOTOS_TEST_EXPORT" not in os.environ
|
||||
pytestmark = pytest.mark.skipif(
|
||||
skip_test, reason="Skip if not running with author's personal library."
|
||||
)
|
||||
|
||||
|
||||
UUID_DICT = {
|
||||
"plain_photo": {
|
||||
"uuid": "A8D646C3-89A9-4D74-8001-4EB46BA55B94",
|
||||
"filename": "IMG_8844.JPG",
|
||||
},
|
||||
"hdr": {"uuid": "DA87C6FF-60E8-4DCB-A21D-9C57595667F1", "filename": "IMG_6162.JPG"},
|
||||
"selfie": {
|
||||
"uuid": "316AEBE0-971D-4A33-833C-6BDBFF83469B",
|
||||
"filename": "IMG_1929.JPG",
|
||||
},
|
||||
"video": {
|
||||
"uuid": "5814D9DE-FAB6-473A-9C9A-5A73C6DD1AF5",
|
||||
"filename": "IMG_9411.TRIM.MOV",
|
||||
},
|
||||
"hasadjustments": {
|
||||
"uuid": "2B2D5434-6D31-49E2-BF47-B973D34A317B",
|
||||
"filename": "IMG_2860.JPG",
|
||||
"adjusted_size": 3012634,
|
||||
"unadjusted_size": 2580058,
|
||||
},
|
||||
"slow_mo": {
|
||||
"uuid": "DAABC6D9-1FBA-4485-AA39-0A2B100300B1",
|
||||
"filename": "IMG_4055.MOV",
|
||||
},
|
||||
"live_photo": {
|
||||
"uuid": "612CE30B-3D8F-417A-9B14-EC42CBA10ACC",
|
||||
"filename": "IMG_3259.HEIC",
|
||||
"filename_video": "IMG_3259.mov",
|
||||
},
|
||||
"burst": {
|
||||
"uuid": "CD97EC84-71F0-40C6-BAC1-2BABEE305CAC",
|
||||
"filename": "IMG_8196.JPG",
|
||||
"burst_selected": 3,
|
||||
"burst_all": 5,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_fetch_uuid():
|
||||
""" test fetch_uuid """
|
||||
uuid = UUID_DICT["plain_photo"]["uuid"]
|
||||
filename = UUID_DICT["plain_photo"]["filename"]
|
||||
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
assert isinstance(photo, PhotoAsset)
|
||||
|
||||
|
||||
def test_plain_photo():
|
||||
""" test plain_photo """
|
||||
uuid = UUID_DICT["plain_photo"]["uuid"]
|
||||
filename = UUID_DICT["plain_photo"]["filename"]
|
||||
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
assert photo.original_filename == filename
|
||||
assert photo.isphoto
|
||||
assert not photo.ismovie
|
||||
|
||||
|
||||
def test_hdr():
|
||||
""" test hdr """
|
||||
uuid = UUID_DICT["hdr"]["uuid"]
|
||||
filename = UUID_DICT["hdr"]["filename"]
|
||||
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
assert photo.original_filename == filename
|
||||
assert photo.hdr
|
||||
|
||||
|
||||
def test_burst():
|
||||
""" test burst and burstid """
|
||||
test_dict = UUID_DICT["burst"]
|
||||
uuid = test_dict["uuid"]
|
||||
filename = test_dict["filename"]
|
||||
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
assert photo.original_filename == filename
|
||||
assert photo.burst
|
||||
assert photo.burstid
|
||||
|
||||
|
||||
|
||||
# def test_selfie():
|
||||
# """ test selfie """
|
||||
# uuid = UUID_DICT["selfie"]["uuid"]
|
||||
# filename = UUID_DICT["selfie"]["filename"]
|
||||
|
||||
# lib = PhotoLibrary()
|
||||
# photo = lib.fetch_uuid(uuid)
|
||||
# assert photo.original_filename == filename
|
||||
# assert photo.selfie
|
||||
|
||||
|
||||
def test_video():
|
||||
""" test ismovie """
|
||||
uuid = UUID_DICT["video"]["uuid"]
|
||||
filename = UUID_DICT["video"]["filename"]
|
||||
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
assert isinstance(photo, VideoAsset)
|
||||
assert photo.original_filename == filename
|
||||
assert photo.ismovie
|
||||
assert not photo.isphoto
|
||||
|
||||
|
||||
def test_slow_mo():
|
||||
""" test slow_mo """
|
||||
test_dict = UUID_DICT["slow_mo"]
|
||||
uuid = test_dict["uuid"]
|
||||
filename = test_dict["filename"]
|
||||
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
assert isinstance(photo, VideoAsset)
|
||||
assert photo.original_filename == filename
|
||||
assert photo.ismovie
|
||||
assert photo.slow_mo
|
||||
assert not photo.isphoto
|
||||
|
||||
|
||||
### PhotoAsset
|
||||
|
||||
|
||||
def test_export_photo_original():
|
||||
""" test PhotoAsset.export """
|
||||
test_dict = UUID_DICT["hasadjustments"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, version=PHOTOS_VERSION_ORIGINAL)
|
||||
export_path = pathlib.Path(export_path[0])
|
||||
assert export_path.is_file()
|
||||
filename = test_dict["filename"]
|
||||
assert export_path.stem == pathlib.Path(filename).stem
|
||||
assert export_path.stat().st_size == test_dict["unadjusted_size"]
|
||||
|
||||
|
||||
def test_export_photo_unadjusted():
|
||||
""" test PhotoAsset.export """
|
||||
test_dict = UUID_DICT["hasadjustments"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, version=PHOTOS_VERSION_UNADJUSTED)
|
||||
export_path = pathlib.Path(export_path[0])
|
||||
assert export_path.is_file()
|
||||
filename = test_dict["filename"]
|
||||
assert export_path.stem == pathlib.Path(filename).stem
|
||||
assert export_path.stat().st_size == test_dict["unadjusted_size"]
|
||||
|
||||
|
||||
def test_export_photo_current():
|
||||
""" test PhotoAsset.export """
|
||||
test_dict = UUID_DICT["hasadjustments"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir)
|
||||
export_path = pathlib.Path(export_path[0])
|
||||
assert export_path.is_file()
|
||||
filename = test_dict["filename"]
|
||||
assert export_path.stem == pathlib.Path(filename).stem
|
||||
assert export_path.stat().st_size == test_dict["adjusted_size"]
|
||||
|
||||
|
||||
### VideoAsset
|
||||
|
||||
|
||||
def test_export_video_original():
|
||||
""" test VideoAsset.export """
|
||||
test_dict = UUID_DICT["video"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, version=PHOTOS_VERSION_ORIGINAL)
|
||||
export_path = pathlib.Path(export_path[0])
|
||||
assert export_path.is_file()
|
||||
filename = test_dict["filename"]
|
||||
assert export_path.stem == pathlib.Path(filename).stem
|
||||
|
||||
|
||||
def test_export_video_unadjusted():
|
||||
""" test VideoAsset.export """
|
||||
test_dict = UUID_DICT["video"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, version=PHOTOS_VERSION_UNADJUSTED)
|
||||
export_path = pathlib.Path(export_path[0])
|
||||
assert export_path.is_file()
|
||||
filename = test_dict["filename"]
|
||||
assert export_path.stem == pathlib.Path(filename).stem
|
||||
|
||||
|
||||
def test_export_video_current():
|
||||
""" test VideoAsset.export """
|
||||
test_dict = UUID_DICT["video"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, version=PHOTOS_VERSION_CURRENT)
|
||||
export_path = pathlib.Path(export_path[0])
|
||||
assert export_path.is_file()
|
||||
filename = test_dict["filename"]
|
||||
assert export_path.stem == pathlib.Path(filename).stem
|
||||
|
||||
|
||||
### Slow-Mo VideoAsset
|
||||
|
||||
|
||||
def test_export_slow_mo_original():
|
||||
""" test VideoAsset.export for slow mo video"""
|
||||
test_dict = UUID_DICT["slow_mo"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, version=PHOTOS_VERSION_ORIGINAL)
|
||||
export_path = pathlib.Path(export_path[0])
|
||||
assert export_path.is_file()
|
||||
filename = test_dict["filename"]
|
||||
assert export_path.stem == pathlib.Path(filename).stem
|
||||
|
||||
|
||||
def test_export_slow_mo_unadjusted():
|
||||
""" test VideoAsset.export for slow mo video"""
|
||||
test_dict = UUID_DICT["slow_mo"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, version=PHOTOS_VERSION_UNADJUSTED)
|
||||
export_path = pathlib.Path(export_path[0])
|
||||
assert export_path.is_file()
|
||||
filename = test_dict["filename"]
|
||||
assert export_path.stem == pathlib.Path(filename).stem
|
||||
|
||||
|
||||
def test_export_slow_mo_current():
|
||||
""" test VideoAsset.export for slow mo video"""
|
||||
test_dict = UUID_DICT["slow_mo"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, version=PHOTOS_VERSION_CURRENT)
|
||||
export_path = pathlib.Path(export_path[0])
|
||||
assert export_path.is_file()
|
||||
filename = test_dict["filename"]
|
||||
assert export_path.stem == pathlib.Path(filename).stem
|
||||
|
||||
|
||||
### LivePhotoAsset
|
||||
|
||||
|
||||
def test_export_live_original():
|
||||
""" test LivePhotoAsset.export """
|
||||
test_dict = UUID_DICT["live_photo"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, version=PHOTOS_VERSION_ORIGINAL)
|
||||
for f in export_path:
|
||||
filepath = pathlib.Path(f)
|
||||
assert filepath.is_file()
|
||||
filename = test_dict["filename"]
|
||||
assert filepath.stem == pathlib.Path(filename).stem
|
||||
|
||||
|
||||
def test_export_live_unadjusted():
|
||||
""" test LivePhotoAsset.export """
|
||||
test_dict = UUID_DICT["live_photo"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, version=PHOTOS_VERSION_UNADJUSTED)
|
||||
for file in export_path:
|
||||
filepath = pathlib.Path(file)
|
||||
assert filepath.is_file()
|
||||
filename = test_dict["filename"]
|
||||
assert filepath.stem == pathlib.Path(filename).stem
|
||||
|
||||
|
||||
def test_export_live_current():
|
||||
""" test LivePhotAsset.export """
|
||||
test_dict = UUID_DICT["live_photo"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, version=PHOTOS_VERSION_CURRENT)
|
||||
for file in export_path:
|
||||
filepath = pathlib.Path(file)
|
||||
assert filepath.is_file()
|
||||
filename = test_dict["filename"]
|
||||
assert filepath.stem == pathlib.Path(filename).stem
|
||||
|
||||
|
||||
def test_export_live_current_just_photo():
|
||||
""" test LivePhotAsset.export """
|
||||
test_dict = UUID_DICT["live_photo"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, photo=True, video=False)
|
||||
assert len(export_path) == 1
|
||||
assert export_path[0].lower().endswith(".heic")
|
||||
|
||||
|
||||
def test_export_live_current_just_video():
|
||||
""" test LivePhotAsset.export """
|
||||
test_dict = UUID_DICT["live_photo"]
|
||||
uuid = test_dict["uuid"]
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="photokit_test") as tempdir:
|
||||
export_path = photo.export(tempdir, photo=False, video=True)
|
||||
assert len(export_path) == 1
|
||||
assert export_path[0].lower().endswith(".mov")
|
||||
|
||||
|
||||
def test_fetch_burst_uuid():
|
||||
""" test fetch_burst_uuid """
|
||||
test_dict = UUID_DICT["burst"]
|
||||
uuid = test_dict["uuid"]
|
||||
filename = test_dict["filename"]
|
||||
|
||||
lib = PhotoLibrary()
|
||||
photo = lib.fetch_uuid(uuid)
|
||||
bursts_selected = lib.fetch_burst_uuid(photo.burstid)
|
||||
assert len(bursts_selected) == test_dict["burst_selected"]
|
||||
assert isinstance(bursts_selected[0], PhotoAsset)
|
||||
|
||||
bursts_all = lib.fetch_burst_uuid(photo.burstid, all=True)
|
||||
assert len(bursts_all) == test_dict["burst_all"]
|
||||
assert isinstance(bursts_all[0], PhotoAsset)
|
||||
@@ -4,11 +4,10 @@ import pytest
|
||||
PHOTOS_DB_PLACES = (
|
||||
"./tests/Test-Places-Catalina-10_15_7.photoslibrary/database/photos.db"
|
||||
)
|
||||
PHOTOS_DB_15_1 = "./tests/Test-10.15.1.photoslibrary/database/photos.db"
|
||||
PHOTOS_DB_15_4 = "./tests/Test-10.15.4.photoslibrary/database/photos.db"
|
||||
PHOTOS_DB_15_7 = "./tests/Test-10.15.7.photoslibrary/database/photos.db"
|
||||
PHOTOS_DB_14_6 = "./tests/Test-10.14.6.photoslibrary/database/photos.db"
|
||||
|
||||
PHOTOS_DB_COMMENTS = "tests/Test-Cloud-10.15.6.photoslibrary"
|
||||
PHOTOS_DB_CLOUD = "./tests/Test-Cloud-10.15.6.photoslibrary/database/photos.db"
|
||||
|
||||
UUID_DICT = {
|
||||
"place_dc": "128FB4C6-0B16-4E7D-9108-FB2E90DA1546",
|
||||
@@ -22,6 +21,42 @@ UUID_DICT = {
|
||||
"date_not_modified": "128FB4C6-0B16-4E7D-9108-FB2E90DA1546",
|
||||
}
|
||||
|
||||
UUID_MEDIA_TYPE = {
|
||||
"photo": "C2BBC7A4-5333-46EE-BAF0-093E72111B39",
|
||||
"video": "45099D34-A414-464F-94A2-60D6823679C8",
|
||||
"selfie": "080525C4-1F05-48E5-A3F4-0C53127BB39C",
|
||||
"time_lapse": "4614086E-C797-4876-B3B9-3057E8D757C9",
|
||||
"panorama": "1C1C8F1F-826B-4A24-B1CB-56628946A834",
|
||||
"slow_mo": None,
|
||||
"screenshot": None,
|
||||
"portrait": "7CDA5F84-AA16-4D28-9AA6-A49E1DF8A332",
|
||||
"live_photo": "51F2BEF7-431A-4D31-8AC1-3284A57826AE",
|
||||
"burst": None,
|
||||
}
|
||||
|
||||
# multi keywords
|
||||
UUID_MULTI_KEYWORDS = "6191423D-8DB8-4D4C-92BE-9BBBA308AAC4"
|
||||
TEMPLATE_VALUES_MULTI_KEYWORDS = {
|
||||
"{keyword}": ["flowers", "wedding"],
|
||||
"{+keyword}": ["flowerswedding"],
|
||||
"{;+keyword}": ["flowers;wedding"],
|
||||
"{; +keyword}": ["flowers; wedding"],
|
||||
}
|
||||
|
||||
UUID_TITLE = "6191423D-8DB8-4D4C-92BE-9BBBA308AAC4"
|
||||
TEMPLATE_VALUES_TITLE = {
|
||||
"{title}": ["Tulips tied together at a flower shop"],
|
||||
"{+title}": ["Tulips tied together at a flower shop"],
|
||||
"{,+title}": ["Tulips tied together at a flower shop"],
|
||||
"{, +title}": ["Tulips tied together at a flower shop"],
|
||||
}
|
||||
|
||||
# Boolean type values that render to True
|
||||
UUID_BOOL_VALUES = {"hdr": "D11D25FF-5F31-47D2-ABA9-58418878DC15"}
|
||||
|
||||
# Boolean type values that render to False
|
||||
UUID_BOOL_VALUES_NOT = {"hdr": "51F2BEF7-431A-4D31-8AC1-3284A57826AE"}
|
||||
|
||||
TEMPLATE_VALUES = {
|
||||
"{name}": "128FB4C6-0B16-4E7D-9108-FB2E90DA1546",
|
||||
"{original_name}": "IMG_1064",
|
||||
@@ -267,7 +302,7 @@ def test_subst_default_val_2():
|
||||
|
||||
template = "{place.name.area_of_interest,}"
|
||||
rendered, _ = photo.render_template(template)
|
||||
assert rendered[0] == "_"
|
||||
assert rendered[0] == ""
|
||||
|
||||
|
||||
def test_subst_unknown_val():
|
||||
@@ -284,10 +319,6 @@ def test_subst_unknown_val():
|
||||
assert rendered[0] == "2020/{foo}"
|
||||
assert unknown == ["foo"]
|
||||
|
||||
template = "{place.name.area_of_interest,}"
|
||||
rendered, _ = photo.render_template(template)
|
||||
assert rendered[0] == "_"
|
||||
|
||||
|
||||
def test_subst_double_brace():
|
||||
""" Test substitution with double brace {{ which should be ignored """
|
||||
@@ -322,7 +353,7 @@ def test_subst_multi_1_1_2():
|
||||
# one album, one keyword, two persons
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["1_1_2"]])[0]
|
||||
|
||||
template = "{created.year}/{album}/{keyword}/{person}"
|
||||
@@ -336,16 +367,12 @@ def test_subst_multi_2_1_1():
|
||||
# 2 albums, 1 keyword, 1 person
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["2_1_1"]])[0]
|
||||
|
||||
template = "{created.year}/{album}/{keyword}/{person}"
|
||||
expected = [
|
||||
"2018/Pumpkin Farm/Kids/Katie",
|
||||
"2018/Test Album/Kids/Katie",
|
||||
"2018/Multi Keyword/Kids/Katie",
|
||||
]
|
||||
expected = ["2018/Pumpkin Farm/Kids/Katie", "2018/Test Album/Kids/Katie"]
|
||||
rendered, _ = photo.render_template(template)
|
||||
assert sorted(rendered) == sorted(expected)
|
||||
|
||||
@@ -355,7 +382,7 @@ def test_subst_multi_2_1_1_single():
|
||||
# 2 albums, 1 keyword, 1 person but only do keywords
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["2_1_1"]])[0]
|
||||
|
||||
@@ -370,7 +397,7 @@ def test_subst_multi_0_2_0():
|
||||
# 0 albums, 2 keywords, 0 persons
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["0_2_0"]])[0]
|
||||
|
||||
@@ -385,7 +412,7 @@ def test_subst_multi_0_2_0_single():
|
||||
# 0 albums, 2 keywords, 0 persons, but only do albums
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["0_2_0"]])[0]
|
||||
|
||||
@@ -400,7 +427,7 @@ def test_subst_multi_0_2_0_default_val():
|
||||
# 0 albums, 2 keywords, 0 persons, default vals provided
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["0_2_0"]])[0]
|
||||
|
||||
@@ -415,7 +442,7 @@ def test_subst_multi_0_2_0_default_val_unknown_val():
|
||||
# 0 albums, 2 keywords, 0 persons, default vals provided, unknown val in template
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["0_2_0"]])[0]
|
||||
|
||||
@@ -436,7 +463,7 @@ def test_subst_multi_0_2_0_default_val_unknown_val_2():
|
||||
# 0 albums, 2 keywords, 0 persons, default vals provided, unknown val in template
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["0_2_0"]])[0]
|
||||
|
||||
@@ -454,12 +481,35 @@ def test_subst_multi_folder_albums_1():
|
||||
""" Test substitutions for folder_album are correct """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_4)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
|
||||
# photo in an album in a folder
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["folder_album_1"]])[0]
|
||||
template = "{folder_album}"
|
||||
expected = ["Folder1/SubFolder2/AlbumInFolder"]
|
||||
expected = [
|
||||
"2018-10 - Sponsion, Museum, Frühstück, Römermuseum",
|
||||
"2019-10/11 Paris Clermont",
|
||||
"Folder1/SubFolder2/AlbumInFolder",
|
||||
]
|
||||
rendered, unknown = photo.render_template(template)
|
||||
assert sorted(rendered) == sorted(expected)
|
||||
assert unknown == []
|
||||
|
||||
|
||||
def test_subst_multi_folder_albums_1_path_sep():
|
||||
""" Test substitutions for folder_album are correct with custom PATH_SEP """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
|
||||
# photo in an album in a folder
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["folder_album_1"]])[0]
|
||||
template = "{folder_album(:)}"
|
||||
expected = [
|
||||
"2018-10 - Sponsion, Museum, Frühstück, Römermuseum",
|
||||
"2019-10/11 Paris Clermont",
|
||||
"Folder1:SubFolder2:AlbumInFolder",
|
||||
]
|
||||
rendered, unknown = photo.render_template(template)
|
||||
assert sorted(rendered) == sorted(expected)
|
||||
assert unknown == []
|
||||
@@ -469,7 +519,7 @@ def test_subst_multi_folder_albums_2():
|
||||
""" Test substitutions for folder_album are correct """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_4)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
|
||||
# photo in an album in a folder
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["folder_album_no_folder"]])[0]
|
||||
@@ -480,6 +530,21 @@ def test_subst_multi_folder_albums_2():
|
||||
assert unknown == []
|
||||
|
||||
|
||||
def test_subst_multi_folder_albums_2_path_sep():
|
||||
""" Test substitutions for folder_album are correct with custom PATH_SEP """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
|
||||
# photo in an album in a folder
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["folder_album_no_folder"]])[0]
|
||||
template = "{folder_album(:)}"
|
||||
expected = ["Pumpkin Farm", "Test Album"]
|
||||
rendered, unknown = photo.render_template(template)
|
||||
assert sorted(rendered) == sorted(expected)
|
||||
assert unknown == []
|
||||
|
||||
|
||||
def test_subst_multi_folder_albums_3():
|
||||
""" Test substitutions for folder_album on < Photos 5 """
|
||||
import osxphotos
|
||||
@@ -495,6 +560,21 @@ def test_subst_multi_folder_albums_3():
|
||||
assert unknown == []
|
||||
|
||||
|
||||
def test_subst_multi_folder_albums_3_path_sep():
|
||||
""" Test substitutions for folder_album on < Photos 5 with custom PATH_SEP """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_14_6)
|
||||
|
||||
# photo in an album in a folder
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["mojave_album_1"]])[0]
|
||||
template = "{folder_album(:)}"
|
||||
expected = ["Folder1:SubFolder2:AlbumInFolder", "Pumpkin Farm", "Test Album (1)"]
|
||||
rendered, unknown = photo.render_template(template)
|
||||
assert sorted(rendered) == sorted(expected)
|
||||
assert unknown == []
|
||||
|
||||
|
||||
def test_subst_strftime():
|
||||
""" Test that strftime substitutions are correct """
|
||||
import locale
|
||||
@@ -515,7 +595,7 @@ def test_subst_expand_inplace_1():
|
||||
""" Test that substitutions are correct when expand_inplace=True """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["1_1_2"]])[0]
|
||||
|
||||
@@ -529,7 +609,7 @@ def test_subst_expand_inplace_2():
|
||||
""" Test that substitutions are correct when expand_inplace=True """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["1_1_2"]])[0]
|
||||
|
||||
@@ -543,7 +623,7 @@ def test_subst_expand_inplace_3():
|
||||
""" Test that substitutions are correct when expand_inplace=True and inplace_sep specified"""
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["1_1_2"]])[0]
|
||||
|
||||
@@ -563,3 +643,97 @@ def test_comment():
|
||||
photo = photosdb.get_photo(uuid)
|
||||
comments = photo.render_template("{comment}")
|
||||
assert comments[0] == COMMENT_UUID_DICT[uuid]
|
||||
|
||||
|
||||
def test_media_type():
|
||||
""" test {media_type} template """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(PHOTOS_DB_CLOUD)
|
||||
|
||||
for field, uuid in UUID_MEDIA_TYPE.items():
|
||||
if uuid is not None:
|
||||
photo = photosdb.get_photo(uuid)
|
||||
rendered, _ = photo.render_template("{media_type}")
|
||||
assert rendered[0] == osxphotos.phototemplate.MEDIA_TYPE_DEFAULTS[field]
|
||||
|
||||
|
||||
def test_media_type_default():
|
||||
""" test {media_type,photo=foo} template style """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(PHOTOS_DB_CLOUD)
|
||||
|
||||
for field, uuid in UUID_MEDIA_TYPE.items():
|
||||
if uuid is not None:
|
||||
photo = photosdb.get_photo(uuid)
|
||||
rendered, _ = photo.render_template("{media_type," + f"{field}" + "=foo}")
|
||||
assert rendered[0] == "foo"
|
||||
|
||||
|
||||
def test_bool_values():
|
||||
""" test {bool?TRUE,FALSE} template values """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(PHOTOS_DB_CLOUD)
|
||||
|
||||
for field, uuid in UUID_BOOL_VALUES.items():
|
||||
if uuid is not None:
|
||||
photo = photosdb.get_photo(uuid)
|
||||
rendered, _ = photo.render_template("{" + f"{field}" + "?True,False}")
|
||||
assert rendered[0] == "True"
|
||||
|
||||
|
||||
def test_bool_values_not():
|
||||
""" test {bool?TRUE,FALSE} template values for FALSE values """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(PHOTOS_DB_CLOUD)
|
||||
|
||||
for field, uuid in UUID_BOOL_VALUES_NOT.items():
|
||||
if uuid is not None:
|
||||
photo = photosdb.get_photo(uuid)
|
||||
rendered, _ = photo.render_template("{" + f"{field}" + "?True,False}")
|
||||
assert rendered[0] == "False"
|
||||
|
||||
|
||||
def test_partial_match():
|
||||
""" test that template successfully rejects a field that is superset of valid field """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(PHOTOS_DB_CLOUD)
|
||||
|
||||
for uuid in COMMENT_UUID_DICT:
|
||||
photo = photosdb.get_photo(uuid)
|
||||
rendered, notmatched = photo.render_template("{keywords}")
|
||||
assert [rendered, notmatched] == [["{keywords}"], ["keywords"]]
|
||||
rendered, notmatched = photo.render_template("{keywords,}")
|
||||
assert [rendered, notmatched] == [["{keywords,}"], ["keywords"]]
|
||||
rendered, notmatched = photo.render_template("{keywords,foo}")
|
||||
assert [rendered, notmatched] == [["{keywords,foo}"], ["keywords"]]
|
||||
rendered, notmatched = photo.render_template("{,+keywords,foo}")
|
||||
assert [rendered, notmatched] == [["{,+keywords,foo}"], ["keywords"]]
|
||||
|
||||
|
||||
def test_expand_in_place_with_delim():
|
||||
""" Test that substitutions are correct when {DELIM+FIELD} format used """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
photo = photosdb.get_photo(UUID_MULTI_KEYWORDS)
|
||||
|
||||
for template in TEMPLATE_VALUES_MULTI_KEYWORDS:
|
||||
rendered, _ = photo.render_template(template)
|
||||
assert sorted(rendered) == sorted(TEMPLATE_VALUES_MULTI_KEYWORDS[template])
|
||||
|
||||
|
||||
def test_expand_in_place_with_delim_single_value():
|
||||
""" Test that single-value substitutions are correct when {DELIM+FIELD} format used """
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_7)
|
||||
photo = photosdb.get_photo(UUID_TITLE)
|
||||
|
||||
for template in TEMPLATE_VALUES_TITLE:
|
||||
rendered, _ = photo.render_template(template)
|
||||
assert sorted(rendered) == sorted(TEMPLATE_VALUES_TITLE[template])
|
||||
|
||||
Reference in New Issue
Block a user