diff --git a/README.md b/README.md index 970b7b77..a4f8523c 100644 --- a/README.md +++ b/README.md @@ -282,6 +282,13 @@ Options: output directory in the form '{name,DEFAULT}'. See below for additional details on templating system. + --edited-suffix SUFFIX Optional suffix for naming edited photos. + Default name for edited photos is in form + 'photoname_edited.ext'. For example, with ' + --edited-suffix _bearbeiten', the edited + photo would be named + 'photoname_bearbeiten.ext'. The default + suffix is '_edited'. --no-extended-attributes Don't copy extended attributes when exporting. You only need this if exporting to a filesystem that doesn't support Mac OS @@ -373,6 +380,8 @@ Substitution Description 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) {modified.date} Photo's modification date in ISO format, diff --git a/osxphotos/__main__.py b/osxphotos/__main__.py index 52da6373..7fff6a3b 100644 --- a/osxphotos/__main__.py +++ b/osxphotos/__main__.py @@ -1038,6 +1038,14 @@ def query( help="Optional template for specifying name of output directory in the form '{name,DEFAULT}'. " "See below for additional details on templating system.", ) +@click.option( + "--edited-suffix", + metavar="SUFFIX", + default="_edited", + help="Optional suffix for naming edited photos. Default name for edited photos is in form " + "'photoname_edited.ext'. For example, with '--edited-suffix _bearbeiten', the edited photo " + "would be named 'photoname_bearbeiten.ext'. The default suffix is '_edited'." +) @click.option( "--no-extended-attributes", is_flag=True, @@ -1116,6 +1124,7 @@ def export( not_panorama, has_raw, directory, + edited_suffix, place, no_place, no_extended_attributes, @@ -1309,6 +1318,7 @@ def export( export_db=export_db, fileutil=fileutil, dry_run = dry_run, + edited_suffix=edited_suffix, ) results_exported.extend(results.exported) results_new.extend(results.new) @@ -1340,6 +1350,7 @@ def export( export_db=export_db, fileutil=fileutil, dry_run=dry_run, + edited_suffix=edited_suffix ) results_exported.extend(results.exported) results_new.extend(results.new) @@ -1759,6 +1770,7 @@ def export_photo( export_db=None, fileutil=FileUtil, dry_run=None, + edited_suffix="_edited" ): """ Helper function for export that does the actual export photo: PhotoInfo object @@ -1910,12 +1922,12 @@ def export_photo( edited_name = pathlib.Path(filename) # check for correct edited suffix if photo.path_edited is not None: - edited_suffix = pathlib.Path(photo.path_edited).suffix + edited_ext = pathlib.Path(photo.path_edited).suffix else: # use filename suffix which might be wrong, # will be corrected by use_photos_export - edited_suffix = pathlib.Path(photo.filename).suffix - edited_name = f"{edited_name.stem}_edited{edited_suffix}" + edited_ext = pathlib.Path(photo.filename).suffix + edited_name = f"{edited_name.stem}{edited_suffix}{edited_ext}" verbose(f"Exporting edited version of {filename} as {edited_name}") export_results_edited = photo.export2( dest_path, diff --git a/osxphotos/_version.py b/osxphotos/_version.py index af638e6c..8424be87 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.29.7" +__version__ = "0.29.8" diff --git a/tests/test_cli.py b/tests/test_cli.py index 3e9f33b0..2e644ace 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -47,6 +47,20 @@ CLI_EXPORT_FILENAMES = [ "wedding_edited.jpeg", ] +CLI_EXPORT_EDITED_SUFFIX = "_bearbeiten" + +CLI_EXPORT_FILENAMES_EDITED_SUFFIX = [ + "Pumkins1.jpg", + "Pumkins2.jpg", + "Pumpkins3.jpg", + "St James Park.jpg", + "St James Park_bearbeiten.jpeg", + "Tulips.jpg", + "wedding.jpg", + "wedding_bearbeiten.jpeg", +] + + CLI_EXPORT_FILENAMES_CURRENT = [ "1EB2B765-0765-43BA-A90C-0D0580E6172C.jpeg", "3DD2C897-F19E-4CA6-8C22-B027D5A71907.jpeg", @@ -414,6 +428,33 @@ def test_export_exiftool(): assert exif[key] == CLI_EXIFTOOL[uuid][key] +def test_export_edited_suffix(): + """ test export with --edited-suffix """ + import glob + import os + import os.path + import osxphotos + from osxphotos.__main__ import export + + runner = CliRunner() + cwd = os.getcwd() + # pylint: disable=not-context-manager + with runner.isolated_filesystem(): + result = runner.invoke( + export, + [ + os.path.join(cwd, CLI_PHOTOS_DB), + ".", + "--edited-suffix", + CLI_EXPORT_EDITED_SUFFIX, + "-V", + ], + ) + assert result.exit_code == 0 + files = glob.glob("*") + assert sorted(files) == sorted(CLI_EXPORT_FILENAMES_EDITED_SUFFIX) + + def test_query_date(): import json import osxphotos