Compare commits

..

7 Commits

Author SHA1 Message Date
Rhet Turnbull
30273509d4 Fix for issue #366, --jpeg-ext, --convert-to-jpeg bug 2021-02-12 07:52:18 -08:00
Rhet Turnbull
15a3e69015 Updated CHANGELOG.md, [skip ci] 2021-02-10 06:50:56 -08:00
Rhet Turnbull
2691902d5c Added test for #374 2021-02-10 06:50:40 -08:00
Rhet Turnbull
da47821fae Bug fix for --jpeg-ext, #374 2021-02-09 22:17:20 -08:00
Rhet Turnbull
6f38e2da49 Updated CHANGELOG.md, [skip ci] 2021-02-08 22:07:17 -08:00
Rhet Turnbull
857e3db6cc Fixed --exiftool-option, #369, for real this time 2021-02-08 21:59:20 -08:00
Rhet Turnbull
7ed3115f36 Updated CHANGELOG.md, [skip ci] 2021-02-08 21:31:21 -08:00
6 changed files with 179 additions and 9 deletions

View File

@@ -4,6 +4,24 @@ 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.40.13](https://github.com/RhetTbull/osxphotos/compare/v0.40.12...v0.40.13)
> 10 February 2021
- Bug fix for --jpeg-ext, #374 [`da47821`](https://github.com/RhetTbull/osxphotos/commit/da47821fae7ee7b2d6d89f5542e729e01d3338df)
#### [v0.40.12](https://github.com/RhetTbull/osxphotos/compare/v0.40.11...v0.40.12)
> 9 February 2021
- Fixed --exiftool-option, #369, for real this time [`857e3db`](https://github.com/RhetTbull/osxphotos/commit/857e3db6ccce810d682cd4632ac9bc8448c4f86b)
#### [v0.40.11](https://github.com/RhetTbull/osxphotos/compare/v0.40.10...v0.40.11)
> 9 February 2021
- Fixed --exiftool-option, #369 [`198adda`](https://github.com/RhetTbull/osxphotos/commit/198addaa07a86ac5b0fd82787fdffff0a0fc19c6)
#### [v0.40.10](https://github.com/RhetTbull/osxphotos/compare/v0.40.9...v0.40.10)
> 7 February 2021

View File

@@ -1,3 +1,3 @@
""" version info """
__version__ = "0.40.11"
__version__ = "0.40.14"

View File

@@ -2386,9 +2386,9 @@ def export_photo(
# change the file extension to correct jpeg extension if needed
file_ext = (
"." + jpeg_ext
if jpeg_ext and (photo.uti == "public.jpeg" or convert_to_jpeg)
if jpeg_ext and (photo.uti_original == "public.jpeg" or convert_to_jpeg)
else ".jpeg"
if convert_to_jpeg and photo.uti != "public.jpeg"
if convert_to_jpeg and photo.uti_original != "public.jpeg"
else original_filename.suffix
)
original_filename = (
@@ -2522,17 +2522,28 @@ def export_photo(
if export_edited and photo.hasadjustments:
edited_filename = pathlib.Path(filename)
edited_ext = (
"." + jpeg_ext
if jpeg_ext and photo.uti_edited == "public.jpeg"
else "." + get_preferred_uti_extension(photo.uti_edited)
# rare cases on Photos <= 4 that uti_edited is None
"." + get_preferred_uti_extension(photo.uti_edited)
if photo.uti_edited
else pathlib.Path(photo.path_edited).suffix
if photo.path_edited
else pathlib.Path(photo.filename).suffix
)
if (
photo.isphoto
and jpeg_ext
and edited_ext.lower() in [".jpg", ".jpeg"]
):
edited_ext = "." + jpeg_ext
# Big Sur uses .heic for some edited photos so need to check
# if extension isn't jpeg/jpg and using --convert-to-jpeg
if convert_to_jpeg and edited_ext.lower() not in [".jpg", ".jpeg"]:
if (
photo.isphoto
and convert_to_jpeg
and edited_ext.lower() not in [".jpg", ".jpeg"]
):
edited_ext = "." + jpeg_ext if jpeg_ext else ".jpeg"
if edited_suffix:

View File

@@ -315,7 +315,13 @@ class ExifTool:
if not json_str:
return dict()
exifdict = json.loads(json_str)
try:
exifdict = json.loads(json_str)
except Exception as e:
# will fail with some commands, e.g --ext AVI which produces
# 'No file with specified extension' instead of json
return dict()
exifdict = exifdict[0]
if not tag_groups:
# strip tag groups

File diff suppressed because one or more lines are too long

View File

@@ -20,6 +20,7 @@ PHOTOS_DB_15_6 = "tests/Test-10.15.6.photoslibrary"
PHOTOS_DB_15_7 = "tests/Test-10.15.7.photoslibrary"
PHOTOS_DB_TOUCH = PHOTOS_DB_15_6
PHOTOS_DB_14_6 = "tests/Test-10.14.6.photoslibrary"
PHOTOS_DB_MOVIES = "tests/Test-Movie-5_0.photoslibrary"
UUID_FILE = "tests/uuid_from_file.txt"
@@ -571,6 +572,17 @@ UUID_JPEGS_DICT = {
"E2078879-A29C-4D6F-BACB-E3BBE6C3EB91": ["screenshot-really-a-png", "jpeg"],
}
UUID_JPEGS_DICT_NOT_JPEG = {
"7783E8E6-9CAC-40F3-BE22-81FB7051C266": ["IMG_3092", "heic"],
"D05A5FE3-15FB-49A1-A15D-AB3DA6F8B068": ["DSC03584", "dng"],
"8846E3E6-8AC8-4857-8448-E3D025784410": ["IMG_1693", "tif"],
}
UUID_MOVIES_NOT_JPEGS_DICT = {
"423C0683-672D-4DDD-979C-23A6A53D7256": ["IMG_0670B_NOGPS", "MOV"]
}
UUID_HEIC = {"7783E8E6-9CAC-40F3-BE22-81FB7051C266": "IMG_3092"}
UUID_IS_REFERENCE = [
@@ -5449,6 +5461,91 @@ def test_export_jpeg_ext():
assert f"{filename}.{jpeg_ext}" in files
def test_export_jpeg_ext_not_jpeg():
""" test --jpeg-ext with non-jpeg files"""
import glob
import os
import os.path
from osxphotos.cli import export
runner = CliRunner()
cwd = os.getcwd()
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
for uuid, fileinfo in UUID_JPEGS_DICT.items():
result = runner.invoke(
export, [os.path.join(cwd, PHOTOS_DB_15_7), ".", "-V", "--uuid", uuid]
)
assert result.exit_code == 0
files = glob.glob("*")
filename, ext = fileinfo
assert f"{filename}.{ext}" in files
for jpeg_ext in ["jpg", "JPG", "jpeg", "JPEG"]:
with runner.isolated_filesystem():
for uuid, fileinfo in UUID_JPEGS_DICT_NOT_JPEG.items():
result = runner.invoke(
export,
[
os.path.join(cwd, PHOTOS_DB_15_7),
".",
"-V",
"--uuid",
uuid,
"--jpeg-ext",
jpeg_ext,
],
)
assert result.exit_code == 0
files = glob.glob("*")
filename, ext = fileinfo
assert f"{filename}.{ext}" in files
def test_export_jpeg_ext_edited_movie():
""" test --jpeg-ext doesn't change extension on edited movie (issue #366)"""
import glob
import os
import os.path
from osxphotos.cli import export
runner = CliRunner()
cwd = os.getcwd()
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
for uuid, fileinfo in UUID_MOVIES_NOT_JPEGS_DICT.items():
result = runner.invoke(
export, [os.path.join(cwd, PHOTOS_DB_MOVIES), ".", "-V", "--uuid", uuid]
)
assert result.exit_code == 0
files = glob.glob("*")
files = [f.lower() for f in files]
filename, ext = fileinfo
assert f"{filename}_edited.{ext}".lower() in files
for jpeg_ext in ["jpg", "JPG", "jpeg", "JPEG"]:
with runner.isolated_filesystem():
for uuid, fileinfo in UUID_MOVIES_NOT_JPEGS_DICT.items():
result = runner.invoke(
export,
[
os.path.join(cwd, PHOTOS_DB_MOVIES),
".",
"-V",
"--uuid",
uuid,
"--jpeg-ext",
jpeg_ext,
],
)
assert result.exit_code == 0
files = glob.glob("*")
files = [f.lower() for f in files]
filename, ext = fileinfo
assert f"{filename}_edited.{jpeg_ext}".lower() not in files
assert f"{filename}_edited.{ext}".lower() in files
@pytest.mark.skipif(
"OSXPHOTOS_TEST_CONVERT" not in os.environ,
reason="Skip if running in Github actions, no GPU.",
@@ -5481,3 +5578,41 @@ def test_export_jpeg_ext_convert_to_jpeg():
assert result.exit_code == 0
files = glob.glob("*")
assert f"{filename}.jpg" in files
@pytest.mark.skipif(
"OSXPHOTOS_TEST_CONVERT" not in os.environ,
reason="Skip if running in Github actions, no GPU.",
)
def test_export_jpeg_ext_convert_to_jpeg_movie():
""" test --jpeg-ext with --convert-to-jpeg and a movie, shouldn't convert or change extensions, #366"""
import glob
import os
import os.path
from osxphotos.cli import export
runner = CliRunner()
cwd = os.getcwd()
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
for uuid, fileinfo in UUID_MOVIES_NOT_JPEGS_DICT.items():
result = runner.invoke(
export,
[
os.path.join(cwd, PHOTOS_DB_MOVIES),
".",
"-V",
"--uuid",
uuid,
"--convert-to-jpeg",
"--jpeg-ext",
"jpg",
],
)
assert result.exit_code == 0
files = glob.glob("*")
files = [f.lower() for f in files]
filename, ext = fileinfo
assert f"{filename}.jpg".lower() not in files
assert f"{filename}.{ext}".lower() in files
assert f"{filename}_edited.{ext}".lower() in files