From aaade588428183327cd4c53547dca57fb1c59ee4 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sun, 12 Jun 2022 00:55:37 -0700 Subject: [PATCH] [Cuesheet Input] Fix metadata handling by merge The inputs now have their own metadata function, so it should merge in the track tags from the Cuesheet, and not just forward it to the decoder. Signed-off-by: Christopher Snowhill --- Plugins/CueSheet/CueSheetDecoder.m | 11 +++++--- Plugins/CueSheet/CueSheetMetadataReader.h | 4 +++ Plugins/CueSheet/CueSheetMetadataReader.m | 31 +++++++++++++---------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Plugins/CueSheet/CueSheetDecoder.m b/Plugins/CueSheet/CueSheetDecoder.m index a9359b3a1..2d1aa005d 100644 --- a/Plugins/CueSheet/CueSheetDecoder.m +++ b/Plugins/CueSheet/CueSheetDecoder.m @@ -10,7 +10,9 @@ #import "CueSheet.h" #import "CueSheetContainer.h" -#import "CueSheetTrack.h" +#import "CueSheetMetadataReader.h" + +#import "NSDictionary+Merge.h" #import "Logging.h" @@ -45,10 +47,13 @@ } - (NSDictionary *)metadata { + NSDictionary *metadata = @{}; + if(track != nil) + metadata = [CueSheetMetadataReader processDataForTrack:track]; if(decoder != nil) - return [decoder metadata]; + return [metadata dictionaryByMergingWith:[decoder metadata]]; else - return @{}; + return metadata; } - (BOOL)open:(id)s { diff --git a/Plugins/CueSheet/CueSheetMetadataReader.h b/Plugins/CueSheet/CueSheetMetadataReader.h index 154cb8ae3..674223716 100644 --- a/Plugins/CueSheet/CueSheetMetadataReader.h +++ b/Plugins/CueSheet/CueSheetMetadataReader.h @@ -10,7 +10,11 @@ #import "Plugin.h" +#import "CueSheetTrack.h" + @interface CueSheetMetadataReader : NSObject { } ++ (NSDictionary *)processDataForTrack:(CueSheetTrack *)track; + @end diff --git a/Plugins/CueSheet/CueSheetMetadataReader.m b/Plugins/CueSheet/CueSheetMetadataReader.m index 7d56bcca3..97ec28e3d 100644 --- a/Plugins/CueSheet/CueSheetMetadataReader.m +++ b/Plugins/CueSheet/CueSheetMetadataReader.m @@ -10,7 +10,6 @@ #import "CueSheetDecoder.h" #import "CueSheet.h" -#import "CueSheetTrack.h" #import "AudioMetadataReader.h" #import "NSDictionary+Merge.h" @@ -68,18 +67,7 @@ if(!embedded) fileMetadata = [audioMetadataReader metadataForURL:[track url] skipCue:YES]; - NSMutableDictionary *cuesheetMetadata = [[NSMutableDictionary alloc] init]; - - if([track artist]) [cuesheetMetadata setValue:[track artist] forKey:@"artist"]; - if([track album]) [cuesheetMetadata setValue:[track album] forKey:@"album"]; - if([track title]) [cuesheetMetadata setValue:[track title] forKey:@"title"]; - if([[track track] intValue]) [cuesheetMetadata setValue:[NSNumber numberWithInt:[[track track] intValue]] forKey:@"track"]; - if([track genre]) [cuesheetMetadata setValue:[track genre] forKey:@"genre"]; - if([[track year] intValue]) [cuesheetMetadata setValue:[NSNumber numberWithInt:[[track year] intValue]] forKey:@"year"]; - if([track albumGain]) [cuesheetMetadata setValue:[NSNumber numberWithFloat:[track albumGain]] forKey:@"replayGainAlbumGain"]; - if([track albumPeak]) [cuesheetMetadata setValue:[NSNumber numberWithFloat:[track albumPeak]] forKey:@"replayGainAlbumPeak"]; - if([track trackGain]) [cuesheetMetadata setValue:[NSNumber numberWithFloat:[track trackGain]] forKey:@"replayGainTrackGain"]; - if([track trackPeak]) [cuesheetMetadata setValue:[NSNumber numberWithFloat:[track trackPeak]] forKey:@"replayGainTrackPeak"]; + NSDictionary *cuesheetMetadata = [CueSheetMetadataReader processDataForTrack:track]; return [cuesheetMetadata dictionaryByMergingWith:fileMetadata]; } @@ -88,4 +76,21 @@ return nil; } ++ (NSDictionary *)processDataForTrack:(CueSheetTrack *)track { + NSMutableDictionary *cuesheetMetadata = [[NSMutableDictionary alloc] init]; + + if([track artist]) [cuesheetMetadata setValue:[track artist] forKey:@"artist"]; + if([track album]) [cuesheetMetadata setValue:[track album] forKey:@"album"]; + if([track title]) [cuesheetMetadata setValue:[track title] forKey:@"title"]; + if([[track track] intValue]) [cuesheetMetadata setValue:[NSNumber numberWithInt:[[track track] intValue]] forKey:@"track"]; + if([track genre]) [cuesheetMetadata setValue:[track genre] forKey:@"genre"]; + if([[track year] intValue]) [cuesheetMetadata setValue:[NSNumber numberWithInt:[[track year] intValue]] forKey:@"year"]; + if([track albumGain]) [cuesheetMetadata setValue:[NSNumber numberWithFloat:[track albumGain]] forKey:@"replayGainAlbumGain"]; + if([track albumPeak]) [cuesheetMetadata setValue:[NSNumber numberWithFloat:[track albumPeak]] forKey:@"replayGainAlbumPeak"]; + if([track trackGain]) [cuesheetMetadata setValue:[NSNumber numberWithFloat:[track trackGain]] forKey:@"replayGainTrackGain"]; + if([track trackPeak]) [cuesheetMetadata setValue:[NSNumber numberWithFloat:[track trackPeak]] forKey:@"replayGainTrackPeak"]; + + return [NSDictionary dictionaryWithDictionary:cuesheetMetadata]; +} + @end