Metadata loading: Correctly merge over empty tags

Metadata versus properties merging, correctly merge over empty fields if
they are assigned with empty strings or zeroed numbers, instead of only
merging over completely missing fields.

Fixes emailed bug, CUE Sheet metadata reading, primarily.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
CQTexperiment
Christopher Snowhill 2022-02-14 20:02:18 -08:00
parent 67fcd2bb27
commit b8a98e301e
2 changed files with 8 additions and 17 deletions

View File

@ -13,6 +13,8 @@
#import "OutputNode.h" #import "OutputNode.h"
#import "Plugin.h" #import "Plugin.h"
#import "NSDictionary+Merge.h"
#import "Logging.h" #import "Logging.h"
@implementation InputNode @implementation InputNode
@ -116,18 +118,13 @@
nodeLossless = [[properties valueForKey:@"encoding"] isEqualToString:@"lossless"]; nodeLossless = [[properties valueForKey:@"encoding"] isEqualToString:@"lossless"];
} else if([keyPath isEqual:@"metadata"]) { } else if([keyPath isEqual:@"metadata"]) {
// Inform something of metadata change // Inform something of metadata change
NSMutableDictionary *entryInfo = [NSMutableDictionary dictionaryWithCapacity:32];
NSDictionary *entryProperties = [decoder properties]; NSDictionary *entryProperties = [decoder properties];
if(entryProperties == nil) if(entryProperties == nil)
return; return;
[entryInfo addEntriesFromDictionary:[decoder metadata]]; NSDictionary *entryInfo = [NSDictionary dictionaryByMerging:entryProperties with:[decoder metadata]];
[entryInfo addEntriesFromDictionary:entryProperties];
NSDictionary * info = [NSDictionary dictionaryWithDictionary:entryInfo]; [controller pushInfo:entryInfo];
[controller pushInfo:info];
} }
} }

View File

@ -32,6 +32,8 @@
#import "Logging.h" #import "Logging.h"
#import "NSDictionary+Merge.h"
@implementation PlaylistLoader @implementation PlaylistLoader
- (id)init { - (id)init {
@ -555,18 +557,13 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
DLog(@"Loading metadata for %@", weakPe.URL); DLog(@"Loading metadata for %@", weakPe.URL);
NSMutableDictionary *entryInfo = [NSMutableDictionary dictionaryWithCapacity:32];
NSDictionary *entryProperties = [AudioPropertiesReader propertiesForURL:weakPe.URL]; NSDictionary *entryProperties = [AudioPropertiesReader propertiesForURL:weakPe.URL];
if(entryProperties == nil) if(entryProperties == nil)
return; return;
NSDictionary *entryMetadata = [AudioMetadataReader metadataForURL:weakPe.URL]; NSDictionary *entryMetadata = [AudioMetadataReader metadataForURL:weakPe.URL];
if(entryMetadata) NSDictionary *entryInfo = [NSDictionary dictionaryByMerging:entryProperties with:entryMetadata];
[entryInfo addEntriesFromDictionary:entryMetadata];
[entryInfo addEntriesFromDictionary:entryProperties];
[weakLock lock]; [weakLock lock];
[weakArray addObject:weakPe]; [weakArray addObject:weakPe];
@ -639,14 +636,11 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
DLog(@"Loading metadata for %@", pe.URL); DLog(@"Loading metadata for %@", pe.URL);
NSMutableDictionary *entryInfo = [NSMutableDictionary dictionaryWithCapacity:32];
NSDictionary *entryProperties = [AudioPropertiesReader propertiesForURL:pe.URL]; NSDictionary *entryProperties = [AudioPropertiesReader propertiesForURL:pe.URL];
if(entryProperties == nil) if(entryProperties == nil)
return; return;
[entryInfo addEntriesFromDictionary:[AudioMetadataReader metadataForURL:pe.URL]]; NSDictionary *entryInfo = [NSDictionary dictionaryByMerging:entryProperties with:[AudioMetadataReader metadataForURL:pe.URL]];
[entryInfo addEntriesFromDictionary:entryProperties];
[pe setMetadata:entryInfo]; [pe setMetadata:entryInfo];
[store trackUpdate:pe]; [store trackUpdate:pe];