@@ -185,7 +185,7 @@ public void StartService()
185
185
186
186
_workService . AddJobSource ( this ) ;
187
187
}
188
-
188
+
189
189
/// <summary>
190
190
/// Read the metadata, and handle any exceptions.
191
191
/// </summary>
@@ -216,6 +216,20 @@ private IReadOnlyList<Directory> SafeReadImageMetadata(string imagePath)
216
216
return metadata ;
217
217
}
218
218
219
+ private string ? GetXMPFieldValue ( Dictionary < string , string > kvps , string prefix )
220
+ {
221
+ if ( kvps . TryGetValue ( prefix , out var result ) && ! string . IsNullOrEmpty ( result ) )
222
+ return result ;
223
+
224
+ var possibilities = Enumerable . Range ( 1 , 5 ) . Select ( n => $ "{ prefix } [{ n } ]") ;
225
+
226
+ foreach ( var key in possibilities )
227
+ if ( kvps . TryGetValue ( key , out var indexed ) && ! string . IsNullOrEmpty ( indexed ) )
228
+ return indexed ;
229
+
230
+ return null ;
231
+ }
232
+
219
233
/// <summary>
220
234
/// Pull out the XMP attributes
221
235
/// </summary>
@@ -227,18 +241,19 @@ private void ReadXMPData(XmpDirectory xmpDirectory, Image image)
227
241
{
228
242
var nvps = xmpDirectory . XmpMeta . Properties
229
243
. Where ( x => ! string . IsNullOrEmpty ( x . Path ) )
230
- . ToDictionary ( x => x . Path , y => y . Value ) ;
244
+ . ToDictionary ( x => x . Path , y => y . Value , StringComparer . OrdinalIgnoreCase ) ;
231
245
232
246
if ( image . MetaData . DateTaken == DateTime . MinValue )
233
247
{
234
248
if ( nvps . ContainsKey ( "exif:DateTimeOriginal" ) && DateTime . TryParse ( nvps [ "exif:DateTimeOriginal" ] , out var dateTime ) )
235
249
image . MetaData . DateTaken = dateTime ;
236
250
}
237
- if ( string . IsNullOrEmpty ( image . MetaData . Description ) && nvps . ContainsKey ( "exif:Description" ) )
238
- image . MetaData . Description = nvps [ "exif:Description" ] ;
239
-
240
- if ( string . IsNullOrEmpty ( image . MetaData . Caption ) && nvps . ContainsKey ( "exif:Caption" ) )
241
- image . MetaData . Caption = nvps [ "exif:Caption" ] ;
251
+
252
+ if ( string . IsNullOrEmpty ( image . MetaData . Description ) )
253
+ image . MetaData . Description = GetXMPFieldValue ( nvps , "dc:Description" ) ;
254
+
255
+ if ( string . IsNullOrEmpty ( image . MetaData . Caption ) )
256
+ image . MetaData . Caption = GetXMPFieldValue ( nvps , "dc:Caption" ) ;
242
257
}
243
258
catch ( Exception ex )
244
259
{
@@ -359,6 +374,9 @@ private bool GetImageMetaData(ref ImageMetaData imgMetaData, out string[] keywor
359
374
360
375
if ( metadata != null )
361
376
{
377
+ // We've read some EXIF data, so clear out the existing metadata to replace it
378
+ imgMetaData . Clear ( ) ;
379
+
362
380
metaDataReadSuccess = true ;
363
381
364
382
var subIfdDirectory = metadata . OfType < ExifSubIfdDirectory > ( ) . FirstOrDefault ( ) ;
0 commit comments