@@ -63,14 +63,30 @@ def process(
6363
6464 final_metadatas : list [types .MetadataOrError ] = []
6565
66+ video_geotags = [_build_video_geotag (option ) for option in options ]
67+ image_geotags = [_build_image_geotag (option ) for option in options ]
68+
6669 # Paths (image path or video path) that will be sent to the next geotag process
6770 reprocessable_paths = set (paths )
6871
69- for idx , option in enumerate (options ):
72+ for idx , (option , video_geotag , image_geotag ) in enumerate (
73+ zip (options , video_geotags , image_geotags )
74+ ):
7075 LOG .debug ("Processing %d files with %s" , len (reprocessable_paths ), option )
7176
72- image_metadata_or_errors = _build_image_geotag (reprocessable_paths , option )
73- video_metadata_or_errors = _build_video_geotag (reprocessable_paths , option )
77+ image_videos , video_paths = _filter_images_and_videos (
78+ reprocessable_paths , option .filetypes
79+ )
80+
81+ if image_videos and image_geotag is not None :
82+ image_metadata_or_errors = image_geotag .to_description (image_videos )
83+ else :
84+ image_metadata_or_errors = []
85+
86+ if video_paths and video_geotag is not None :
87+ video_metadata_or_errors = video_geotag .to_description (video_paths )
88+ else :
89+ video_metadata_or_errors = []
7490
7591 more_option = idx < len (options ) - 1
7692
@@ -139,14 +155,7 @@ def _ensure_source_path(option: SourceOption) -> Path:
139155 return option .source_path .source_path
140156
141157
142- def _build_image_geotag (
143- paths : T .Iterable [Path ], option : SourceOption
144- ) -> list [types .ImageMetadataOrError ]:
145- image_paths , _ = _filter_images_and_videos (paths , option .filetypes )
146-
147- if not image_paths :
148- return []
149-
158+ def _build_image_geotag (option : SourceOption ) -> base .GeotagImagesFromGeneric | None :
150159 if option .interpolation is None :
151160 interpolation = InterpolationOption ()
152161 else :
@@ -158,17 +167,13 @@ def _build_image_geotag(
158167 geotag = geotag_images_from_exif .GeotagImagesFromEXIF (
159168 num_processes = option .num_processes
160169 )
161- return geotag . to_description ( image_paths )
170+ return geotag
162171
163172 if option .source is SourceType .EXIFTOOL_RUNTIME :
164173 geotag = geotag_images_from_exiftool .GeotagImagesFromExifToolRunner (
165174 num_processes = option .num_processes
166175 )
167- try :
168- return geotag .to_description (image_paths )
169- except exceptions .MapillaryExiftoolNotFoundError as ex :
170- LOG .warning ('Skip "%s" because: %s' , option .source .value , ex )
171- return []
176+ return geotag
172177
173178 elif option .source is SourceType .EXIFTOOL_XML :
174179 # This is to ensure 'video_process --geotag={"source": "exiftool_xml", "source_path": "/tmp/xml_path"}'
@@ -177,7 +182,7 @@ def _build_image_geotag(
177182 xml_path = _ensure_source_path (option ),
178183 num_processes = option .num_processes ,
179184 )
180- return geotag . to_description ( image_paths )
185+ return geotag
181186
182187 elif option .source is SourceType .GPX :
183188 geotag = geotag_images_from_gpx_file .GeotagImagesFromGPXFile (
@@ -186,7 +191,7 @@ def _build_image_geotag(
186191 offset_time = interpolation .offset_time ,
187192 num_processes = option .num_processes ,
188193 )
189- return geotag . to_description ( image_paths )
194+ return geotag
190195
191196 elif option .source is SourceType .NMEA :
192197 geotag = geotag_images_from_nmea_file .GeotagImagesFromNMEAFile (
@@ -196,73 +201,62 @@ def _build_image_geotag(
196201 num_processes = option .num_processes ,
197202 )
198203
199- return geotag . to_description ( image_paths )
204+ return geotag
200205
201206 elif option .source is SourceType .EXIF :
202207 geotag = geotag_images_from_exif .GeotagImagesFromEXIF (
203208 num_processes = option .num_processes
204209 )
205- return geotag . to_description ( image_paths )
210+ return geotag
206211
207212 elif option .source in [SourceType .GOPRO , SourceType .BLACKVUE , SourceType .CAMM ]:
208213 geotag = geotag_images_from_video .GeotagImageSamplesFromVideo (
209214 _ensure_source_path (option ),
210215 offset_time = interpolation .offset_time ,
211216 num_processes = option .num_processes ,
212217 )
213- return geotag . to_description ( image_paths )
218+ return geotag
214219
215220 else :
216221 raise ValueError (f"Invalid geotag source { option .source } " )
217222
218223
219- def _build_video_geotag (
220- paths : T .Iterable [Path ], option : SourceOption
221- ) -> list [types .VideoMetadataOrError ]:
222- _ , video_paths = _filter_images_and_videos (paths , option .filetypes )
223-
224- if not video_paths :
225- return []
226-
224+ def _build_video_geotag (option : SourceOption ) -> base .GeotagVideosFromGeneric | None :
227225 geotag : base .GeotagVideosFromGeneric
228226
229227 if option .source is SourceType .NATIVE :
230228 geotag = geotag_videos_from_video .GeotagVideosFromVideo (
231229 num_processes = option .num_processes , filetypes = option .filetypes
232230 )
233- return geotag . to_description ( video_paths )
231+ return geotag
234232
235233 if option .source is SourceType .EXIFTOOL_RUNTIME :
236234 geotag = geotag_videos_from_exiftool .GeotagVideosFromExifToolRunner (
237235 num_processes = option .num_processes
238236 )
239- try :
240- return geotag .to_description (video_paths )
241- except exceptions .MapillaryExiftoolNotFoundError as ex :
242- LOG .warning ('Skip "%s" because: %s' , option .source .value , ex )
243- return []
237+ return geotag
244238
245239 elif option .source is SourceType .EXIFTOOL_XML :
246240 geotag = geotag_videos_from_exiftool .GeotagVideosFromExifToolXML (
247241 xml_path = _ensure_source_path (option ),
248242 )
249- return geotag . to_description ( video_paths )
243+ return geotag
250244
251245 elif option .source is SourceType .GPX :
252246 geotag = geotag_videos_from_gpx .GeotagVideosFromGPX ()
253- return geotag . to_description ( video_paths )
247+ return geotag
254248
255249 elif option .source is SourceType .NMEA :
256250 # TODO: geotag videos from NMEA
257- return []
251+ return None
258252
259253 elif option .source is SourceType .EXIF :
260254 # Legacy image-specific geotag types
261- return []
255+ return None
262256
263257 elif option .source in [SourceType .GOPRO , SourceType .BLACKVUE , SourceType .CAMM ]:
264258 # Legacy image-specific geotag types
265- return []
259+ return None
266260
267261 else :
268262 raise ValueError (f"Invalid geotag source { option .source } " )
0 commit comments