@@ -63,28 +63,29 @@ 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-
6966 # Paths (image path or video path) that will be sent to the next geotag process
7067 reprocessable_paths = set (paths )
7168
72- for idx , (option , video_geotag , image_geotag ) in enumerate (
73- zip (options , video_geotags , image_geotags )
74- ):
69+ for idx , option in enumerate (options ):
7570 LOG .debug ("Processing %d files with %s" , len (reprocessable_paths ), option )
7671
7772 image_videos , video_paths = _filter_images_and_videos (
7873 reprocessable_paths , option .filetypes
7974 )
8075
81- if image_videos and image_geotag is not None :
82- image_metadata_or_errors = image_geotag .to_description (image_videos )
76+ if image_videos :
77+ image_geotag = _build_image_geotag (option )
78+ image_metadata_or_errors = (
79+ image_geotag .to_description (image_videos ) if image_geotag else []
80+ )
8381 else :
8482 image_metadata_or_errors = []
8583
86- if video_paths and video_geotag is not None :
87- video_metadata_or_errors = video_geotag .to_description (video_paths )
84+ if video_paths :
85+ video_geotag = _build_video_geotag (option )
86+ video_metadata_or_errors = (
87+ video_geotag .to_description (video_paths ) if video_geotag else []
88+ )
8889 else :
8990 video_metadata_or_errors = []
9091
@@ -161,90 +162,74 @@ def _build_image_geotag(option: SourceOption) -> base.GeotagImagesFromGeneric |
161162 else :
162163 interpolation = option .interpolation
163164
164- geotag : base .GeotagImagesFromGeneric
165-
166165 if option .source is SourceType .NATIVE :
167- geotag = geotag_images_from_exif .GeotagImagesFromEXIF (
166+ return geotag_images_from_exif .GeotagImagesFromEXIF (
168167 num_processes = option .num_processes
169168 )
170- return geotag
171169
172170 if option .source is SourceType .EXIFTOOL_RUNTIME :
173- geotag = geotag_images_from_exiftool .GeotagImagesFromExifToolRunner (
171+ return geotag_images_from_exiftool .GeotagImagesFromExifToolRunner (
174172 num_processes = option .num_processes
175173 )
176- return geotag
177174
178175 elif option .source is SourceType .EXIFTOOL_XML :
179176 # This is to ensure 'video_process --geotag={"source": "exiftool_xml", "source_path": "/tmp/xml_path"}'
180177 # to work
181- geotag = geotag_images_from_exiftool .GeotagImagesFromExifToolWithSamples (
178+ return geotag_images_from_exiftool .GeotagImagesFromExifToolWithSamples (
182179 xml_path = _ensure_source_path (option ),
183180 num_processes = option .num_processes ,
184181 )
185- return geotag
186182
187183 elif option .source is SourceType .GPX :
188- geotag = geotag_images_from_gpx_file .GeotagImagesFromGPXFile (
184+ return geotag_images_from_gpx_file .GeotagImagesFromGPXFile (
189185 source_path = _ensure_source_path (option ),
190186 use_gpx_start_time = interpolation .use_gpx_start_time ,
191187 offset_time = interpolation .offset_time ,
192188 num_processes = option .num_processes ,
193189 )
194- return geotag
195190
196191 elif option .source is SourceType .NMEA :
197- geotag = geotag_images_from_nmea_file .GeotagImagesFromNMEAFile (
192+ return geotag_images_from_nmea_file .GeotagImagesFromNMEAFile (
198193 source_path = _ensure_source_path (option ),
199194 use_gpx_start_time = interpolation .use_gpx_start_time ,
200195 offset_time = interpolation .offset_time ,
201196 num_processes = option .num_processes ,
202197 )
203198
204- return geotag
205-
206199 elif option .source is SourceType .EXIF :
207- geotag = geotag_images_from_exif .GeotagImagesFromEXIF (
200+ return geotag_images_from_exif .GeotagImagesFromEXIF (
208201 num_processes = option .num_processes
209202 )
210- return geotag
211203
212204 elif option .source in [SourceType .GOPRO , SourceType .BLACKVUE , SourceType .CAMM ]:
213- geotag = geotag_images_from_video .GeotagImageSamplesFromVideo (
205+ return geotag_images_from_video .GeotagImageSamplesFromVideo (
214206 _ensure_source_path (option ),
215207 offset_time = interpolation .offset_time ,
216208 num_processes = option .num_processes ,
217209 )
218- return geotag
219210
220211 else :
221212 raise ValueError (f"Invalid geotag source { option .source } " )
222213
223214
224215def _build_video_geotag (option : SourceOption ) -> base .GeotagVideosFromGeneric | None :
225- geotag : base .GeotagVideosFromGeneric
226-
227216 if option .source is SourceType .NATIVE :
228- geotag = geotag_videos_from_video .GeotagVideosFromVideo (
217+ return geotag_videos_from_video .GeotagVideosFromVideo (
229218 num_processes = option .num_processes , filetypes = option .filetypes
230219 )
231- return geotag
232220
233221 if option .source is SourceType .EXIFTOOL_RUNTIME :
234- geotag = geotag_videos_from_exiftool .GeotagVideosFromExifToolRunner (
222+ return geotag_videos_from_exiftool .GeotagVideosFromExifToolRunner (
235223 num_processes = option .num_processes
236224 )
237- return geotag
238225
239226 elif option .source is SourceType .EXIFTOOL_XML :
240- geotag = geotag_videos_from_exiftool .GeotagVideosFromExifToolXML (
227+ return geotag_videos_from_exiftool .GeotagVideosFromExifToolXML (
241228 xml_path = _ensure_source_path (option ),
242229 )
243- return geotag
244230
245231 elif option .source is SourceType .GPX :
246- geotag = geotag_videos_from_gpx .GeotagVideosFromGPX ()
247- return geotag
232+ return geotag_videos_from_gpx .GeotagVideosFromGPX ()
248233
249234 elif option .source is SourceType .NMEA :
250235 # TODO: geotag videos from NMEA
0 commit comments