From d3c69c2027a2e593b47416729745cf3ac4efe575 Mon Sep 17 00:00:00 2001 From: Stefal Date: Thu, 28 Mar 2024 14:19:43 +0100 Subject: [PATCH] Update xmp only if needed. Should fix crash on certain images (sequence jgmvtIOe08rSpzHqNyR2hQ) --- mapillary_download.py | 4 +++- writer.py | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/mapillary_download.py b/mapillary_download.py index 550e3a1..be13deb 100644 --- a/mapillary_download.py +++ b/mapillary_download.py @@ -26,7 +26,7 @@ def parse_args(argv =None): parser.add_argument('--destination', type=str, default='data', help='Path destination for the images') parser.add_argument('--image_limit', type=int, default=None, help='How many images you want to download') parser.add_argument('--overwrite', default=False, action='store_true', help='overwrite existing images') - parser.add_argument("-v", "--version", action="version", version="release 1.5") + parser.add_argument("-v", "--version", action="version", version="release 1.6") args = parser.parse_args(argv) if args.sequence_ids is None and args.image_ids is None: parser.error("Please enter at least one sequence id or image id") @@ -163,6 +163,8 @@ if __name__ == '__main__': direction = image_data['compass_angle'], altitude = image_data['altitude'], ) + #print("metadata: ", img_metadata) + #print("path: ", image_data) image_exists = os.path.exists(path) if not args.overwrite and image_exists: print("{} already exists. Skipping ".format(path)) diff --git a/writer.py b/writer.py index 7c19acc..2f81e67 100644 --- a/writer.py +++ b/writer.py @@ -47,8 +47,13 @@ class Writer(): self.image.close() def apply(self) -> None: - self.image.modify_exif(self.updated_exif) - self.image.modify_xmp(self.updated_xmp) + try: + if self.updated_exif: + self.image.modify_exif(self.updated_exif) + if self.updated_xmp: + self.image.modify_xmp(self.updated_xmp) + except Exception as e: + print("exception \nexif: {}\nxmp: {}".format(self.updated_exif, self.updated_xmp)) def close(self) -> None: self.image.close()