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
|
|
|
|
|
|
|
|
+ (NSArray *)fileTypes
|
|
|
|
{
|
|
|
|
return [CueSheetDecoder fileTypes];
|
|
|
|
}
|
|
|
|
|
2007-10-14 18:56:23 +00:00
|
|
|
+ (NSArray *)mimeTypes
|
|
|
|
{
|
|
|
|
return [CueSheetDecoder mimeTypes];
|
|
|
|
}
|
|
|
|
|
2015-04-13 07:39:24 +00:00
|
|
|
+ (float)priority
|
|
|
|
{
|
2022-01-15 00:46:35 +00:00
|
|
|
return 16.0f;
|
2015-04-13 07:39:24 +00:00
|
|
|
}
|
|
|
|
|
2007-10-13 01:36:42 +00:00
|
|
|
+ (NSDictionary *)metadataForURL:(NSURL *)url
|
|
|
|
{
|
|
|
|
if (![url isFileURL]) {
|
|
|
|
return nil;
|
|
|
|
}
|
2022-01-15 00:46:35 +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];
|
|
|
|
NSString * sheet = [fileMetadata objectForKey:@"cuesheet"];
|
|
|
|
if ([sheet length])
|
|
|
|
{
|
|
|
|
cuesheet = [CueSheet cueSheetWithString:sheet withFilename:[url path]];
|
|
|
|
embedded = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cuesheet = [CueSheet cueSheetWithFile:[url path]];
|
|
|
|
|
|
|
|
if (!cuesheet)
|
|
|
|
return nil;
|
2007-10-13 01:36:42 +00:00
|
|
|
|
|
|
|
NSArray *tracks = [cuesheet tracks];
|
2013-10-10 08:44:45 +00:00
|
|
|
for (CueSheetTrack *track in tracks)
|
2007-10-13 01:36:42 +00:00
|
|
|
{
|
|
|
|
if ([[url fragment] isEqualToString:[track track]])
|
|
|
|
{
|
2021-11-21 08:16:16 +00:00
|
|
|
// Class supplied by CogAudio, which is guaranteed to be present
|
2022-01-15 00:46:35 +00:00
|
|
|
if (!embedded)
|
|
|
|
fileMetadata = [audioMetadataReader metadataForURL:[track url] skipCue:YES];
|
2021-11-21 08:16:16 +00:00
|
|
|
NSDictionary * cuesheetMetadata = [NSDictionary dictionaryWithObjectsAndKeys:
|
2007-10-13 01:36:42 +00:00
|
|
|
[track artist], @"artist",
|
|
|
|
[track album], @"album",
|
|
|
|
[track title], @"title",
|
2007-10-13 16:21:46 +00:00
|
|
|
[NSNumber numberWithInt:[[track track] intValue]], @"track",
|
2007-10-13 01:36:42 +00:00
|
|
|
[track genre], @"genre",
|
2013-10-11 13:20:08 +00:00
|
|
|
[NSNumber numberWithInt:[[track year] intValue]], @"year",
|
2022-01-15 02:51:44 +00:00
|
|
|
[NSNumber numberWithFloat:[track albumGain]], @"replayGainAlbumGain",
|
|
|
|
[NSNumber numberWithFloat:[track albumPeak]], @"replayGainAlbumPeak",
|
|
|
|
[NSNumber numberWithFloat:[track trackGain]], @"replayGainTrackGain",
|
|
|
|
[NSNumber numberWithFloat:[track trackPeak]], @"replayGainTrackPeak",
|
2007-10-13 01:36:42 +00:00
|
|
|
nil];
|
|
|
|
|
2021-11-21 08:16:16 +00:00
|
|
|
return [fileMetadata dictionaryByMergingWith:cuesheetMetadata];
|
2007-10-13 01:36:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|