2007-10-13 01:36:42 +00:00
|
|
|
//
|
|
|
|
// CueSheetMetadataReader.m
|
|
|
|
// CueSheet
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 10/12/07.
|
|
|
|
// Copyright 2007 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "CueSheetMetadataReader.h"
|
|
|
|
#import "CueSheetDecoder.h"
|
|
|
|
|
|
|
|
#import "CueSheet.h"
|
|
|
|
|
2021-11-21 08:16:16 +00:00
|
|
|
#import "AudioMetadataReader.h"
|
|
|
|
#import "NSDictionary+Merge.h"
|
|
|
|
|
2007-10-13 01:36:42 +00:00
|
|
|
@implementation CueSheetMetadataReader
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)fileTypes {
|
2007-10-13 01:36:42 +00:00
|
|
|
return [CueSheetDecoder fileTypes];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)mimeTypes {
|
2007-10-14 18:56:23 +00:00
|
|
|
return [CueSheetDecoder mimeTypes];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (float)priority {
|
|
|
|
return 16.0f;
|
2015-04-13 07:39:24 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSDictionary *)metadataForURL:(NSURL *)url {
|
|
|
|
if(![url isFileURL]) {
|
2007-10-13 01:36:42 +00:00
|
|
|
return nil;
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
BOOL embedded = NO;
|
|
|
|
CueSheet *cuesheet = nil;
|
|
|
|
NSDictionary *fileMetadata;
|
|
|
|
|
|
|
|
Class audioMetadataReader = NSClassFromString(@"AudioMetadataReader");
|
|
|
|
|
|
|
|
NSString *ext = [url pathExtension];
|
|
|
|
if([ext caseInsensitiveCompare:@"cue"] != NSOrderedSame) {
|
|
|
|
// Embedded cuesheet check
|
|
|
|
fileMetadata = [audioMetadataReader metadataForURL:url skipCue:YES];
|
2022-02-12 15:16:59 +00:00
|
|
|
|
2022-02-13 20:18:58 +00:00
|
|
|
NSDictionary *alsoMetadata = [NSClassFromString(@"AudioPropertiesReader") propertiesForURL:url skipCue:YES];
|
2022-02-12 15:16:59 +00:00
|
|
|
|
2022-10-16 21:59:19 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-12 15:16:59 +00:00
|
|
|
|
2022-10-16 21:59:19 +00:00
|
|
|
if(sheetString && [sheetString length]) {
|
|
|
|
cuesheet = [CueSheet cueSheetWithString:sheetString withFilename:[url path]];
|
2022-02-07 05:49:27 +00:00
|
|
|
embedded = YES;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
cuesheet = [CueSheet cueSheetWithFile:[url path]];
|
|
|
|
|
2022-02-11 14:03:45 +00:00
|
|
|
if(!cuesheet) {
|
|
|
|
return fileMetadata;
|
|
|
|
}
|
2007-10-13 01:36:42 +00:00
|
|
|
|
|
|
|
NSArray *tracks = [cuesheet tracks];
|
2022-02-07 05:49:27 +00:00
|
|
|
for(CueSheetTrack *track in tracks) {
|
|
|
|
if([[url fragment] isEqualToString:[track track]]) {
|
|
|
|
// Class supplied by CogAudio, which is guaranteed to be present
|
|
|
|
if(!embedded)
|
|
|
|
fileMetadata = [audioMetadataReader metadataForURL:[track url] skipCue:YES];
|
2022-02-11 14:03:45 +00:00
|
|
|
|
2022-06-12 07:55:37 +00:00
|
|
|
NSDictionary *cuesheetMetadata = [CueSheetMetadataReader processDataForTrack:track];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-02-12 15:57:13 +00:00
|
|
|
return [cuesheetMetadata dictionaryByMergingWith:fileMetadata];
|
2007-10-13 01:36:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2022-06-12 07:55:37 +00:00
|
|
|
+ (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"];
|
2022-06-17 13:39:02 +00:00
|
|
|
if([[track track] intValue]) [cuesheetMetadata setValue:@([[track track] intValue]) forKey:@"track"];
|
2022-06-12 07:55:37 +00:00
|
|
|
if([track genre]) [cuesheetMetadata setValue:[track genre] forKey:@"genre"];
|
2022-06-17 13:39:02 +00:00
|
|
|
if([[track year] intValue]) [cuesheetMetadata setValue:@([[track year] intValue]) forKey:@"year"];
|
2022-07-08 13:26:28 +00:00
|
|
|
if([track albumGain]) [cuesheetMetadata setValue:@([track albumGain]) forKey:@"replaygain_album_gain"];
|
|
|
|
if([track albumPeak]) [cuesheetMetadata setValue:@([track albumPeak]) forKey:@"replaygain_album_peak"];
|
|
|
|
if([track trackGain]) [cuesheetMetadata setValue:@([track trackGain]) forKey:@"replaygain_track_gain"];
|
|
|
|
if([track trackPeak]) [cuesheetMetadata setValue:@([track trackPeak]) forKey:@"replaygain_track_peak"];
|
2022-06-12 07:55:37 +00:00
|
|
|
|
|
|
|
return [NSDictionary dictionaryWithDictionary:cuesheetMetadata];
|
|
|
|
}
|
|
|
|
|
2007-10-13 01:36:42 +00:00
|
|
|
@end
|