From 30273509d40a270d2610b662ed9238449350064c Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Fri, 12 Feb 2021 07:52:18 -0800 Subject: [PATCH] Fix for issue #366, --jpeg-ext, --convert-to-jpeg bug --- osxphotos/_version.py | 2 +- osxphotos/cli.py | 19 ++++-- tests/search_info_test_data_10_15_7.json | 2 +- tests/test_cli.py | 87 +++++++++++++++++++++++- 4 files changed, 103 insertions(+), 7 deletions(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 707c9215..733a8fb0 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.40.13" +__version__ = "0.40.14" diff --git a/osxphotos/cli.py b/osxphotos/cli.py index 44840bc8..da20941d 100644 --- a/osxphotos/cli.py +++ b/osxphotos/cli.py @@ -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: diff --git a/tests/search_info_test_data_10_15_7.json b/tests/search_info_test_data_10_15_7.json index d1c7e144..c9acc42d 100644 --- a/tests/search_info_test_data_10_15_7.json +++ b/tests/search_info_test_data_10_15_7.json @@ -1 +1 @@ -{"UUID_SEARCH_INFO": {"C8EAF50A-D891-4E0C-8086-C417E1284153": {"labels": ["Food", "Butter"], "place_names": ["Durham Bulls Athletic Park"], "streets": ["Blackwell St"], "neighborhoods": ["American Tobacco District", "Downtown Durham"], "city": "Durham", "locality_names": ["Durham"], "state": "North Carolina", "state_abbreviation": "NC", "country": "United States", "bodies_of_water": [], "month": "October", "year": "2018", "holidays": [], "activities": ["Dinner", "Travel", "Entertainment", "Dining", "Trip"], "season": "Fall", "venues": ["Copa", "Pie Pusher's", "The Pinhook", "Luna Rotisserie and Empanadas"], "venue_types": ["Cocktail Bar", "Nightlife", "Pizza", "Restaurant", "Bar", "Tapas & Small Plates", "Food", "Empanadas", "Chicken Wings", "Arts & Entertainment", "Latin American", "Cuban", "Music Venue"], "media_types": []}, "71DFB4C3-E868-4BE4-906E-D96BD8692D7E": {"labels": ["Sunset Sunrise", "Desert", "Sky", "Outdoor", "Land"], "place_names": ["Royal Palms State Beach"], "streets": [], "neighborhoods": ["San Pedro"], "city": "Los Angeles", "locality_names": [], "state": "California", "state_abbreviation": "", "country": "United States", "bodies_of_water": ["Catalina Channel"], "month": "November", "year": "2017", "holidays": [], "activities": ["Beach Activity", "Activity"], "season": "Fall", "venues": [], "venue_types": [], "media_types": ["Live Photos"]}, "2C151013-5BBA-4D00-B70F-1C9420418B86": {"labels": ["Water Body", "Water", "People", "Vegetation", "Forest", "Land", "Outdoor", "Furniture", "Bench"], "place_names": [], "streets": [], "neighborhoods": [], "city": "", "locality_names": [], "state": "", "state_abbreviation": "", "country": "", "bodies_of_water": [], "month": "December", "year": "2014", "holidays": ["Christmas Day"], "activities": ["Celebration", "Holiday"], "season": "Winter", "venues": [], "venue_types": [], "media_types": []}}, "UUID_SEARCH_INFO_NORMALIZED": {"C8EAF50A-D891-4E0C-8086-C417E1284153": {"labels": ["food", "butter"], "place_names": ["durham bulls athletic park"], "streets": ["blackwell st"], "neighborhoods": ["american tobacco district", "downtown durham"], "city": "durham", "locality_names": ["durham"], "state": "north carolina", "state_abbreviation": "nc", "country": "united states", "bodies_of_water": [], "month": "october", "year": "2018", "holidays": [], "activities": ["dinner", "travel", "entertainment", "dining", "trip"], "season": "fall", "venues": ["copa", "pie pusher's", "the pinhook", "luna rotisserie and empanadas"], "venue_types": ["cocktail bar", "nightlife", "pizza", "restaurant", "bar", "tapas & small plates", "food", "empanadas", "chicken wings", "arts & entertainment", "latin american", "cuban", "music venue"], "media_types": []}, "71DFB4C3-E868-4BE4-906E-D96BD8692D7E": {"labels": ["sunset sunrise", "desert", "sky", "outdoor", "land"], "place_names": ["royal palms state beach"], "streets": [], "neighborhoods": ["san pedro"], "city": "los angeles", "locality_names": [], "state": "california", "state_abbreviation": "", "country": "united states", "bodies_of_water": ["catalina channel"], "month": "november", "year": "2017", "holidays": [], "activities": ["beach activity", "activity"], "season": "fall", "venues": [], "venue_types": [], "media_types": ["live photos"]}, "2C151013-5BBA-4D00-B70F-1C9420418B86": {"labels": ["water body", "water", "people", "vegetation", "forest", "land", "outdoor", "furniture", "bench"], "place_names": [], "streets": [], "neighborhoods": [], "city": "", "locality_names": [], "state": "", "state_abbreviation": "", "country": "", "bodies_of_water": [], "month": "december", "year": "2014", "holidays": ["christmas day"], "activities": ["celebration", "holiday"], "season": "winter", "venues": [], "venue_types": [], "media_types": []}}, "UUID_SEARCH_INFO_ALL": {"C8EAF50A-D891-4E0C-8086-C417E1284153": ["Food", "Butter", "Durham Bulls Athletic Park", "Blackwell St", "American Tobacco District", "Downtown Durham", "Durham", "Dinner", "Travel", "Entertainment", "Dining", "Trip", "Copa", "Pie Pusher's", "The Pinhook", "Luna Rotisserie and Empanadas", "Cocktail Bar", "Nightlife", "Pizza", "Restaurant", "Bar", "Tapas & Small Plates", "Food", "Empanadas", "Chicken Wings", "Arts & Entertainment", "Latin American", "Cuban", "Music Venue", "Durham", "North Carolina", "NC", "United States", "October", "2018", "Fall"], "71DFB4C3-E868-4BE4-906E-D96BD8692D7E": ["Sunset Sunrise", "Desert", "Sky", "Outdoor", "Land", "Royal Palms State Beach", "San Pedro", "Catalina Channel", "Beach Activity", "Activity", "Live Photos", "Los Angeles", "California", "United States", "November", "2017", "Fall"], "2C151013-5BBA-4D00-B70F-1C9420418B86": ["Water Body", "Water", "People", "Vegetation", "Forest", "Land", "Outdoor", "Furniture", "Bench", "Christmas Day", "Celebration", "Holiday", "December", "2014", "Winter"]}, "UUID_SEARCH_INFO_ALL_NORMALIZED": {"C8EAF50A-D891-4E0C-8086-C417E1284153": ["food", "butter", "durham bulls athletic park", "blackwell st", "american tobacco district", "downtown durham", "durham", "dinner", "travel", "entertainment", "dining", "trip", "copa", "pie pusher's", "the pinhook", "luna rotisserie and empanadas", "cocktail bar", "nightlife", "pizza", "restaurant", "bar", "tapas & small plates", "food", "empanadas", "chicken wings", "arts & entertainment", "latin american", "cuban", "music venue", "durham", "north carolina", "nc", "united states", "october", "2018", "fall"], "71DFB4C3-E868-4BE4-906E-D96BD8692D7E": ["sunset sunrise", "desert", "sky", "outdoor", "land", "royal palms state beach", "san pedro", "catalina channel", "beach activity", "activity", "live photos", "los angeles", "california", "united states", "november", "2017", "fall"], "2C151013-5BBA-4D00-B70F-1C9420418B86": ["water body", "water", "people", "vegetation", "forest", "land", "outdoor", "furniture", "bench", "christmas day", "celebration", "holiday", "december", "2014", "winter"]}} +{"UUID_SEARCH_INFO": {"C8EAF50A-D891-4E0C-8086-C417E1284153": {"labels": ["Butter", "Food"], "place_names": ["Durham Bulls Athletic Park"], "streets": ["Blackwell St"], "neighborhoods": ["American Tobacco District", "Downtown Durham"], "city": "Durham", "locality_names": ["Durham"], "state": "North Carolina", "state_abbreviation": "NC", "country": "United States", "bodies_of_water": [], "month": "October", "year": "2018", "holidays": [], "activities": ["Entertainment", "Travel", "Dining", "Dinner", "Trip"], "season": "Fall", "venues": ["Copa", "Luna Rotisserie and Empanadas", "The Pinhook", "Pie Pushers"], "venue_types": [], "media_types": []}, "71DFB4C3-E868-4BE4-906E-D96BD8692D7E": {"labels": ["Desert", "Land", "Outdoor", "Sky", "Sunset Sunrise"], "place_names": ["Royal Palms State Beach"], "streets": [], "neighborhoods": ["San Pedro"], "city": "Los Angeles", "locality_names": [], "state": "California", "state_abbreviation": "", "country": "United States", "bodies_of_water": ["Catalina Channel"], "month": "November", "year": "2017", "holidays": [], "activities": ["Beach Activity", "Activity"], "season": "Fall", "venues": [], "venue_types": [], "media_types": ["Live Photos"]}, "2C151013-5BBA-4D00-B70F-1C9420418B86": {"labels": ["People", "Land", "Water Body", "Bench", "Water", "Plant", "Outdoor", "Vegetation", "Forest", "Furniture"], "place_names": [], "streets": [], "neighborhoods": [], "city": "", "locality_names": [], "state": "", "state_abbreviation": "", "country": "", "bodies_of_water": [], "month": "December", "year": "2014", "holidays": ["Christmas Day"], "activities": ["Celebration", "Holiday"], "season": "Winter", "venues": [], "venue_types": [], "media_types": []}}, "UUID_SEARCH_INFO_NORMALIZED": {"C8EAF50A-D891-4E0C-8086-C417E1284153": {"labels": ["butter", "food"], "place_names": ["durham bulls athletic park"], "streets": ["blackwell st"], "neighborhoods": ["american tobacco district", "downtown durham"], "city": "durham", "locality_names": ["durham"], "state": "north carolina", "state_abbreviation": "nc", "country": "united states", "bodies_of_water": [], "month": "october", "year": "2018", "holidays": [], "activities": ["entertainment", "travel", "dining", "dinner", "trip"], "season": "fall", "venues": ["copa", "luna rotisserie and empanadas", "the pinhook", "pie pushers"], "venue_types": [], "media_types": []}, "71DFB4C3-E868-4BE4-906E-D96BD8692D7E": {"labels": ["desert", "land", "outdoor", "sky", "sunset sunrise"], "place_names": ["royal palms state beach"], "streets": [], "neighborhoods": ["san pedro"], "city": "los angeles", "locality_names": [], "state": "california", "state_abbreviation": "", "country": "united states", "bodies_of_water": ["catalina channel"], "month": "november", "year": "2017", "holidays": [], "activities": ["beach activity", "activity"], "season": "fall", "venues": [], "venue_types": [], "media_types": ["live photos"]}, "2C151013-5BBA-4D00-B70F-1C9420418B86": {"labels": ["people", "land", "water body", "bench", "water", "plant", "outdoor", "vegetation", "forest", "furniture"], "place_names": [], "streets": [], "neighborhoods": [], "city": "", "locality_names": [], "state": "", "state_abbreviation": "", "country": "", "bodies_of_water": [], "month": "december", "year": "2014", "holidays": ["christmas day"], "activities": ["celebration", "holiday"], "season": "winter", "venues": [], "venue_types": [], "media_types": []}}, "UUID_SEARCH_INFO_ALL": {"C8EAF50A-D891-4E0C-8086-C417E1284153": ["Butter", "Food", "Durham Bulls Athletic Park", "Blackwell St", "American Tobacco District", "Downtown Durham", "Durham", "Entertainment", "Travel", "Dining", "Dinner", "Trip", "Copa", "Luna Rotisserie and Empanadas", "The Pinhook", "Pie Pushers", "Durham", "North Carolina", "NC", "United States", "October", "2018", "Fall"], "71DFB4C3-E868-4BE4-906E-D96BD8692D7E": ["Desert", "Land", "Outdoor", "Sky", "Sunset Sunrise", "Royal Palms State Beach", "San Pedro", "Catalina Channel", "Beach Activity", "Activity", "Live Photos", "Los Angeles", "California", "United States", "November", "2017", "Fall"], "2C151013-5BBA-4D00-B70F-1C9420418B86": ["People", "Land", "Water Body", "Bench", "Water", "Plant", "Outdoor", "Vegetation", "Forest", "Furniture", "Christmas Day", "Celebration", "Holiday", "December", "2014", "Winter"]}, "UUID_SEARCH_INFO_ALL_NORMALIZED": {"C8EAF50A-D891-4E0C-8086-C417E1284153": ["butter", "food", "durham bulls athletic park", "blackwell st", "american tobacco district", "downtown durham", "durham", "entertainment", "travel", "dining", "dinner", "trip", "copa", "luna rotisserie and empanadas", "the pinhook", "pie pushers", "durham", "north carolina", "nc", "united states", "october", "2018", "fall"], "71DFB4C3-E868-4BE4-906E-D96BD8692D7E": ["desert", "land", "outdoor", "sky", "sunset sunrise", "royal palms state beach", "san pedro", "catalina channel", "beach activity", "activity", "live photos", "los angeles", "california", "united states", "november", "2017", "fall"], "2C151013-5BBA-4D00-B70F-1C9420418B86": ["people", "land", "water body", "bench", "water", "plant", "outdoor", "vegetation", "forest", "furniture", "christmas day", "celebration", "holiday", "december", "2014", "winter"]}} diff --git a/tests/test_cli.py b/tests/test_cli.py index d110e25f..e212e924 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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" @@ -575,9 +576,12 @@ UUID_JPEGS_DICT = { 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"] + "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"} @@ -5498,6 +5502,49 @@ def test_export_jpeg_ext_not_jpeg(): 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, @@ -5531,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