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"
|
|
|
|
#import "CueSheetTrack.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
|
|
|
|
|
|
|
NSDictionary *alsoMetadata = [NSClassFromString(@"AudioPropertiesReader") propertiesForURL:url];
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSString *sheet = [fileMetadata objectForKey:@"cuesheet"];
|
2022-02-12 15:16:59 +00:00
|
|
|
if(!sheet || ![sheet length]) sheet = [alsoMetadata objectForKey:@"cuesheet"];
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if([sheet length]) {
|
|
|
|
cuesheet = [CueSheet cueSheetWithString:sheet withFilename:[url path]];
|
|
|
|
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
|
|
|
|
|
|
|
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"];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
return [fileMetadata dictionaryByMergingWith:cuesheetMetadata];
|
2007-10-13 01:36:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|