Cleaned up code.

CQTexperiment
vspader 2007-10-20 16:01:18 +00:00
parent 156ae4ef0d
commit 7bee3acc79
1 changed files with 9 additions and 14 deletions

View File

@ -43,7 +43,6 @@
break; break;
} }
} }
NSLog(@"Fragment: %@", fragment);
if (![unixPath hasPrefix:@"/"]) { if (![unixPath hasPrefix:@"/"]) {
//Only relative paths would have windows backslashes. //Only relative paths would have windows backslashes.
@ -63,29 +62,26 @@
- (void)parseFile:(NSString *)filename - (void)parseFile:(NSString *)filename
{ {
NSStringEncoding encoding; NSStringEncoding encoding;
NSError *error = nil; NSError *error = nil;
NSString *contents = [NSString stringWithContentsOfFile:filename usedEncoding:&encoding error:&error]; NSString *contents = [NSString stringWithContentsOfFile:filename usedEncoding:&encoding error:&error];
if (error) { if (error) {
NSLog(@"Trying UTF8");
error = nil; error = nil;
contents = [NSString stringWithContentsOfFile:filename encoding:NSUTF8StringEncoding error:&error]; contents = [NSString stringWithContentsOfFile:filename encoding:NSUTF8StringEncoding error:&error];
} }
if (error) { if (error) {
NSLog(@"Trying windows CP1251");
error = nil; error = nil;
contents = [NSString stringWithContentsOfFile:filename encoding:NSWindowsCP1251StringEncoding error:&error]; contents = [NSString stringWithContentsOfFile:filename encoding:NSWindowsCP1251StringEncoding error:&error];
} }
if (error) { if (error) {
NSLog(@"Trying latin1");
error = nil; error = nil;
contents = [NSString stringWithContentsOfFile:filename encoding:NSISOLatin1StringEncoding error:&error]; contents = [NSString stringWithContentsOfFile:filename encoding:NSISOLatin1StringEncoding error:&error];
} }
if (error || !contents) { if (error || !contents) {
NSLog(@"Could not open file...%@ %@ %@", filename, contents, error); NSLog(@"Could not open file...%@ %@ %@", filename, contents, error);
return; return;
} }
NSMutableArray *entries = [[NSMutableArray alloc] init]; NSMutableArray *entries = [[NSMutableArray alloc] init];
NSString *track = nil; NSString *track = nil;
@ -174,21 +170,20 @@
track = @"01"; track = @"01";
} }
//Sometimes cue sheets will contain .wav tracks when they were actually reencoded.
NSFileManager *fm = [NSFileManager defaultManager]; NSFileManager *fm = [NSFileManager defaultManager];
NSURL *url = [self urlForPath:path relativeTo:filename]; NSURL *url = [self urlForPath:path relativeTo:filename];
if ([url isFileURL] && ![fm fileExistsAtPath:[url absoluteString]] && ![[[url absoluteString] pathExtension] compare:@"wav"]) { if ([url isFileURL] && ![fm fileExistsAtPath:[url absoluteString]] && [[[url absoluteString] pathExtension] isEqualToString:@"wav"]) {
//creator fogot to edit cue... happens //creator fogot to edit cue... happens
NSString* originalURL = [url path]; NSString* originalURL = [url path];
NSString *ext; NSString *ext;
NSEnumerator *e = [[[NSClassFromString(@"PluginController") sharedPluginController] decodersByExtension] objectEnumerator]; NSEnumerator *e = [[[[NSClassFromString(@"PluginController") sharedPluginController] decodersByExtension] allKeys] objectEnumerator];
while (ext = [e nextObject]) while (ext = [e nextObject])
{ {
NSMutableString* newURL = [originalURL mutableCopy]; NSMutableString* newURL = [originalURL mutableCopy];
[newURL replaceOccurrencesOfString:@"wav" withString:ext options:(NSAnchoredSearch | NSBackwardsSearch) range:NSMakeRange(0, [newURL length])]; [newURL replaceOccurrencesOfString:@"wav" withString:ext options:(NSAnchoredSearch | NSBackwardsSearch) range:NSMakeRange(0, [newURL length])];
NSLog(@"Trying: %@", newURL);
if ([fm fileExistsAtPath:newURL]) if ([fm fileExistsAtPath:newURL])
{ {
url = [NSURL fileURLWithPath:newURL]; url = [NSURL fileURLWithPath:newURL];
@ -201,7 +196,7 @@
} }
//Need to add basePath, and convert to URL //Need to add basePath, and convert to URL
[entries addObject: [entries addObject:
[CueSheetTrack trackWithURL:[self urlForPath:path relativeTo:filename] [CueSheetTrack trackWithURL:url
track: track track: track
time: seconds time: seconds
artist:artist artist:artist