2007-10-12 21:36:42 -04: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 05:16:16 -03:00
|
|
|
#import "AudioMetadataReader.h"
|
|
|
|
#import "NSDictionary+Merge.h"
|
2025-06-20 22:42:43 -04:00
|
|
|
#import "NSDictionary+Optional.h"
|
2021-11-21 05:16:16 -03:00
|
|
|
|
2007-10-12 21:36:42 -04:00
|
|
|
@implementation CueSheetMetadataReader
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
+ (NSArray *)fileTypes {
|
2007-10-12 21:36:42 -04:00
|
|
|
return [CueSheetDecoder fileTypes];
|
|
|
|
}
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
+ (NSArray *)mimeTypes {
|
2007-10-14 15:56:23 -03:00
|
|
|
return [CueSheetDecoder mimeTypes];
|
|
|
|
}
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
+ (float)priority {
|
|
|
|
return 16.0f;
|
2015-04-13 04:39:24 -03:00
|
|
|
}
|
|
|
|
|
2022-02-07 02:49:27 -03:00
|
|
|
+ (NSDictionary *)metadataForURL:(NSURL *)url {
|
|
|
|
if(![url isFileURL]) {
|
2007-10-12 21:36:42 -04:00
|
|
|
return nil;
|
|
|
|
}
|
2022-02-07 02:49:27 -03: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 12:16:59 -03:00
|
|
|
|
2022-02-13 17:18:58 -03:00
|
|
|
NSDictionary *alsoMetadata = [NSClassFromString(@"AudioPropertiesReader") propertiesForURL:url skipCue:YES];
|
2022-02-12 12:16:59 -03:00
|
|
|
|
2022-10-16 18:59:19 -03: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 12:16:59 -03:00
|
|
|
|
2022-10-16 18:59:19 -03:00
|
|
|
if(sheetString && [sheetString length]) {
|
|
|
|
cuesheet = [CueSheet cueSheetWithString:sheetString withFilename:[url path]];
|
2022-02-07 02:49:27 -03:00
|
|
|
embedded = YES;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
cuesheet = [CueSheet cueSheetWithFile:[url path]];
|
|
|
|
|
2022-02-11 11:03:45 -03:00
|
|
|
if(!cuesheet) {
|
|
|
|
return fileMetadata;
|
|
|
|
}
|
2007-10-12 21:36:42 -04:00
|
|
|
|
|
|
|
NSArray *tracks = [cuesheet tracks];
|
2022-02-07 02:49:27 -03: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 11:03:45 -03:00
|
|
|
|
2022-06-12 03:55:37 -04:00
|
|
|
NSDictionary *cuesheetMetadata = [CueSheetMetadataReader processDataForTrack:track];
|
2022-02-07 02:49:27 -03:00
|
|
|
|
2022-02-12 12:57:13 -03:00
|
|
|
return [cuesheetMetadata dictionaryByMergingWith:fileMetadata];
|
2007-10-12 21:36:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2022-06-12 03:55:37 -04:00
|
|
|
+ (NSDictionary *)processDataForTrack:(CueSheetTrack *)track {
|
2025-06-20 22:42:43 -04:00
|
|
|
const NSString* keys[] = {
|
|
|
|
@"artist",
|
|
|
|
@"album",
|
|
|
|
@"title",
|
|
|
|
@"track",
|
|
|
|
@"genre",
|
|
|
|
@"year",
|
|
|
|
@"replaygain_album_gain",
|
|
|
|
@"replaygain_album_peak",
|
|
|
|
@"replaygain_track_gain",
|
|
|
|
@"replaygain_track_peak"
|
|
|
|
};
|
|
|
|
const id values[] = {
|
|
|
|
[track artist],
|
|
|
|
[track album],
|
|
|
|
[track title],
|
|
|
|
@([[track track] intValue]),
|
|
|
|
[track genre],
|
|
|
|
@([[track year] intValue]),
|
|
|
|
@([track albumGain]),
|
|
|
|
@([track albumPeak]),
|
|
|
|
@([track trackGain]),
|
|
|
|
@([track trackPeak])
|
|
|
|
};
|
|
|
|
return [NSDictionary initWithOptionalObjects:values forKeys:keys count:sizeof(keys) / sizeof(keys[0])];
|
2022-06-12 03:55:37 -04:00
|
|
|
}
|
|
|
|
|
2007-10-12 21:36:42 -04:00
|
|
|
@end
|