From b8a98e301e2d52980320b8f8fb9e62e66822b14c Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Mon, 14 Feb 2022 20:02:18 -0800 Subject: [PATCH] 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 --- Audio/Chain/InputNode.m | 11 ++++------- Playlist/PlaylistLoader.m | 14 ++++---------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Audio/Chain/InputNode.m b/Audio/Chain/InputNode.m index e02cea582..950097b4e 100644 --- a/Audio/Chain/InputNode.m +++ b/Audio/Chain/InputNode.m @@ -13,6 +13,8 @@ #import "OutputNode.h" #import "Plugin.h" +#import "NSDictionary+Merge.h" + #import "Logging.h" @implementation InputNode @@ -116,18 +118,13 @@ nodeLossless = [[properties valueForKey:@"encoding"] isEqualToString:@"lossless"]; } else if([keyPath isEqual:@"metadata"]) { // Inform something of metadata change - NSMutableDictionary *entryInfo = [NSMutableDictionary dictionaryWithCapacity:32]; - NSDictionary *entryProperties = [decoder properties]; if(entryProperties == nil) return; - [entryInfo addEntriesFromDictionary:[decoder metadata]]; - [entryInfo addEntriesFromDictionary:entryProperties]; + NSDictionary *entryInfo = [NSDictionary dictionaryByMerging:entryProperties with:[decoder metadata]]; - NSDictionary * info = [NSDictionary dictionaryWithDictionary:entryInfo]; - - [controller pushInfo:info]; + [controller pushInfo:entryInfo]; } } diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index e3482974f..d4ac0ea13 100644 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -32,6 +32,8 @@ #import "Logging.h" +#import "NSDictionary+Merge.h" + @implementation PlaylistLoader - (id)init { @@ -555,18 +557,13 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc DLog(@"Loading metadata for %@", weakPe.URL); - NSMutableDictionary *entryInfo = [NSMutableDictionary dictionaryWithCapacity:32]; - NSDictionary *entryProperties = [AudioPropertiesReader propertiesForURL:weakPe.URL]; if(entryProperties == nil) return; NSDictionary *entryMetadata = [AudioMetadataReader metadataForURL:weakPe.URL]; - if(entryMetadata) - [entryInfo addEntriesFromDictionary:entryMetadata]; - - [entryInfo addEntriesFromDictionary:entryProperties]; + NSDictionary *entryInfo = [NSDictionary dictionaryByMerging:entryProperties with:entryMetadata]; [weakLock lock]; [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); - NSMutableDictionary *entryInfo = [NSMutableDictionary dictionaryWithCapacity:32]; - NSDictionary *entryProperties = [AudioPropertiesReader propertiesForURL:pe.URL]; if(entryProperties == nil) return; - [entryInfo addEntriesFromDictionary:[AudioMetadataReader metadataForURL:pe.URL]]; - [entryInfo addEntriesFromDictionary:entryProperties]; + NSDictionary *entryInfo = [NSDictionary dictionaryByMerging:entryProperties with:[AudioMetadataReader metadataForURL:pe.URL]]; [pe setMetadata:entryInfo]; [store trackUpdate:pe];