2007-10-09 02:25:40 +00:00
|
|
|
//
|
|
|
|
// CueSheetContainer.m
|
|
|
|
// CueSheet
|
|
|
|
//
|
|
|
|
// Created by Zaphod Beeblebrox on 10/8/07.
|
|
|
|
// Copyright 2007 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "CueSheetContainer.h"
|
|
|
|
|
|
|
|
#import "CueSheet.h"
|
|
|
|
#import "CueSheetTrack.h"
|
|
|
|
|
2022-01-15 00:46:35 +00:00
|
|
|
#import "AudioMetadataReader.h"
|
|
|
|
|
2007-10-09 02:25:40 +00:00
|
|
|
@implementation CueSheetContainer
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)fileTypes {
|
2022-01-19 02:12:57 +00:00
|
|
|
return @[@"cue", @"ogg", @"opus", @"flac", @"wv", @"mp3"];
|
2007-10-09 02:25:40 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)mimeTypes {
|
|
|
|
return @[@"application/x-cue"]; // This is basically useless
|
2007-10-14 18:56:23 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url {
|
|
|
|
if(![url isFileURL]) {
|
2022-01-19 02:12:57 +00:00
|
|
|
return @[];
|
2007-10-09 02:25:40 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
if([url fragment]) {
|
|
|
|
// input url already has fragment defined - no need to expand further
|
|
|
|
return [NSMutableArray arrayWithObject:url];
|
|
|
|
}
|
|
|
|
|
2007-10-09 02:25:40 +00:00
|
|
|
NSMutableArray *tracks = [NSMutableArray array];
|
2022-01-15 00:46:35 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL embedded = NO;
|
|
|
|
CueSheet *cuesheet = nil;
|
|
|
|
NSDictionary *fileMetadata;
|
|
|
|
|
|
|
|
NSString *ext = [url pathExtension];
|
|
|
|
if([ext caseInsensitiveCompare:@"cue"] != NSOrderedSame) {
|
|
|
|
// Embedded cuesheet check
|
|
|
|
fileMetadata = [NSClassFromString(@"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]];
|
|
|
|
|
|
|
|
if(!cuesheet)
|
2022-08-04 04:20:42 +00:00
|
|
|
return tracks;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
for(CueSheetTrack *track in [cuesheet tracks]) {
|
2007-10-09 02:25:40 +00:00
|
|
|
[tracks addObject:[NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:@"#%@", [track track]]]];
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2007-10-09 02:25:40 +00:00
|
|
|
return tracks;
|
|
|
|
}
|
|
|
|
|
2022-06-26 09:47:49 +00:00
|
|
|
+ (NSArray *)dependencyUrlsForContainerURL:(NSURL *)url {
|
|
|
|
if(![url isFileURL]) {
|
|
|
|
return @[];
|
|
|
|
}
|
|
|
|
|
|
|
|
if([url fragment]) {
|
|
|
|
NSString *pathString = [url path];
|
|
|
|
NSString *lastComponent = [url lastPathComponent];
|
|
|
|
|
|
|
|
// Find that last component in the string from the end to make sure
|
|
|
|
// to get the last one
|
|
|
|
NSRange fragmentRange = [pathString rangeOfString:lastComponent options:NSBackwardsSearch];
|
|
|
|
|
|
|
|
// Chop the fragment.
|
|
|
|
NSString *newPathString = [pathString substringToIndex:fragmentRange.location + fragmentRange.length];
|
|
|
|
|
|
|
|
url = [NSURL fileURLWithPath:newPathString];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableArray *tracks = [NSMutableArray array];
|
|
|
|
|
|
|
|
CueSheet *cuesheet = nil;
|
|
|
|
|
|
|
|
NSString *ext = [url pathExtension];
|
|
|
|
if([ext caseInsensitiveCompare:@"cue"] != NSOrderedSame) {
|
|
|
|
return @[];
|
|
|
|
} else
|
|
|
|
cuesheet = [CueSheet cueSheetWithFile:[url path]];
|
|
|
|
|
|
|
|
if(!cuesheet)
|
|
|
|
return @[];
|
|
|
|
|
|
|
|
for(CueSheetTrack *track in [cuesheet tracks]) {
|
|
|
|
if(![tracks containsObject:track.url])
|
|
|
|
[tracks addObject:track.url];
|
|
|
|
}
|
|
|
|
|
|
|
|
return tracks;
|
|
|
|
}
|
|
|
|
|
2007-10-09 02:25:40 +00:00
|
|
|
@end
|