Fix a crash with embedded cue sheet handling

Tag reading can read cue sheets as either a single NSString, or an
NSArray of NSStrings, so handle either case.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
xcode15
Christopher Snowhill 2022-10-16 14:59:19 -07:00
parent 695a03d9e8
commit e25cfbf22c
3 changed files with 81 additions and 12 deletions

View File

@ -50,11 +50,34 @@
NSDictionary *alsoMetadata = [NSClassFromString(@"AudioPropertiesReader") propertiesForURL:url skipCue:YES];
NSString *sheet = [fileMetadata objectForKey:@"cuesheet"];
if(!sheet || ![sheet length]) sheet = [alsoMetadata objectForKey:@"cuesheet"];
id sheet = [fileMetadata objectForKey:@"cuesheet"];
NSString *sheetString = nil;
if(sheet) {
if([sheet isKindOfClass:[NSArray class]]) {
NSArray *sheetContainer = sheet;
if([sheetContainer count]) {
sheetString = sheetContainer[0];
}
} else if([sheet isKindOfClass:[NSString class]]) {
sheetString = sheet;
}
}
if(!sheetString || ![sheetString length]) {
sheet = [alsoMetadata objectForKey:@"cuesheet"];
if(sheet) {
if([sheet isKindOfClass:[NSArray class]]) {
NSArray *sheetContainer = sheet;
if([sheetContainer count]) {
sheetString = sheetContainer[0];
}
} else if([sheet isKindOfClass:[NSString class]]) {
sheetString = sheet;
}
}
}
if([sheet length]) {
cuesheet = [CueSheet cueSheetWithString:sheet withFilename:[url path]];
if(sheetString && [sheetString length]) {
cuesheet = [CueSheet cueSheetWithString:sheetString withFilename:[url path]];
}
embedded = YES;
} else

View File

@ -92,11 +92,34 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext;
NSDictionary *alsoMetadata = [decoder metadata];
NSString *sheet = [fileMetadata objectForKey:@"cuesheet"];
if(!sheet || ![sheet length]) sheet = [alsoMetadata objectForKey:@"cuesheet"];
id sheet = [fileMetadata objectForKey:@"cuesheet"];
NSString *sheetString = nil;
if(sheet) {
if([sheet isKindOfClass:[NSArray class]]) {
NSArray *sheetContainer = sheet;
if([sheetContainer count]) {
sheetString = sheetContainer[0];
}
} else if([sheet isKindOfClass:[NSString class]]) {
sheetString = sheet;
}
}
if(!sheetString || ![sheetString length]) {
sheet = [alsoMetadata objectForKey:@"cuesheet"];
if(sheet) {
if([sheet isKindOfClass:[NSArray class]]) {
NSArray *sheetContainer = sheet;
if([sheetContainer count]) {
sheetString = sheetContainer[0];
}
} else if([sheet isKindOfClass:[NSString class]]) {
sheetString = sheet;
}
}
}
if([sheet length]) {
cuesheet = [CueSheet cueSheetWithString:sheet withFilename:[url path]];
if(sheetString && [sheetString length]) {
cuesheet = [CueSheet cueSheetWithString:sheetString withFilename:[url path]];
embedded = YES;
}

View File

@ -46,11 +46,34 @@
NSDictionary *alsoMetadata = [NSClassFromString(@"AudioPropertiesReader") propertiesForURL:url skipCue:YES];
NSString *sheet = [fileMetadata objectForKey:@"cuesheet"];
if(!sheet || ![sheet length]) sheet = [alsoMetadata objectForKey:@"cuesheet"];
id sheet = [fileMetadata objectForKey:@"cuesheet"];
NSString *sheetString = nil;
if(sheet) {
if([sheet isKindOfClass:[NSArray class]]) {
NSArray *sheetContainer = sheet;
if([sheetContainer count]) {
sheetString = sheetContainer[0];
}
} else if([sheet isKindOfClass:[NSString class]]) {
sheetString = sheet;
}
}
if(!sheetString || ![sheetString length]) {
sheet = [alsoMetadata objectForKey:@"cuesheet"];
if(sheet) {
if([sheet isKindOfClass:[NSArray class]]) {
NSArray *sheetContainer = sheet;
if([sheetContainer count]) {
sheetString = sheetContainer[0];
}
} else if([sheet isKindOfClass:[NSString class]]) {
sheetString = sheet;
}
}
}
if([sheet length]) {
cuesheet = [CueSheet cueSheetWithString:sheet withFilename:[url path]];
if(sheetString && [sheetString length]) {
cuesheet = [CueSheet cueSheetWithString:sheetString withFilename:[url path]];
embedded = YES;
}
} else