2007-10-08 21:20:46 -04:00
|
|
|
//
|
|
|
|
// PlsContainer.m
|
|
|
|
// Pls
|
|
|
|
//
|
|
|
|
// Created by Zaphod Beeblebrox on 10/8/07.
|
|
|
|
// Copyright 2007 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "PlsContainer.h"
|
|
|
|
|
|
|
|
|
|
|
|
@implementation PlsContainer
|
|
|
|
|
|
|
|
+ (NSArray *)fileTypes
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObject:@"pls"];
|
|
|
|
}
|
|
|
|
|
2007-10-14 15:56:23 -03:00
|
|
|
+ (NSArray *)mimeTypes
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects:@"audio/x-scpls", @"application/pls", nil];
|
|
|
|
}
|
|
|
|
|
2007-10-08 21:20:46 -04:00
|
|
|
+ (NSURL *)urlForPath:(NSString *)path relativeTo:(NSString *)baseFilename
|
|
|
|
{
|
|
|
|
if ([path hasPrefix:@"/"]) {
|
2007-10-15 19:19:14 -03:00
|
|
|
return [NSURL URLWithString:[@"file://" stringByAppendingString:path]];
|
2007-10-08 21:20:46 -04:00
|
|
|
}
|
|
|
|
|
2007-10-15 19:19:14 -03:00
|
|
|
NSRange protocolRange = [path rangeOfString:@"://"];
|
|
|
|
if (protocolRange.location != NSNotFound)
|
2007-10-08 21:20:46 -04:00
|
|
|
{
|
|
|
|
return [NSURL URLWithString:path];
|
|
|
|
}
|
2007-10-15 19:19:14 -03:00
|
|
|
|
2007-10-08 21:20:46 -04:00
|
|
|
NSMutableString *unixPath = [path mutableCopy];
|
|
|
|
|
|
|
|
//Only relative paths would have windows backslashes.
|
|
|
|
[unixPath replaceOccurrencesOfString:@"\\" withString:@"/" options:0 range:NSMakeRange(0, [unixPath length])];
|
2007-10-15 19:19:14 -03:00
|
|
|
|
|
|
|
NSMutableString *urlString = [[NSMutableString alloc] init];
|
|
|
|
[urlString setString:@"file://"];
|
|
|
|
|
|
|
|
NSString *basePath = [[[baseFilename stringByStandardizingPath] stringByDeletingLastPathComponent] stringByAppendingString:@"/"];
|
|
|
|
|
|
|
|
[urlString appendString:basePath];
|
|
|
|
[urlString appendString:unixPath];
|
|
|
|
|
|
|
|
[unixPath release];
|
2007-10-08 21:20:46 -04:00
|
|
|
|
2007-10-15 19:19:14 -03:00
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
[urlString release];
|
|
|
|
|
|
|
|
return url;
|
2007-10-08 21:20:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url
|
|
|
|
{
|
|
|
|
if (![url isFileURL])
|
|
|
|
return [NSArray array];
|
|
|
|
|
|
|
|
NSString *filename = [url path];
|
|
|
|
|
|
|
|
NSError *error;
|
|
|
|
NSString *contents = [NSString stringWithContentsOfFile:filename encoding:NSUTF8StringEncoding error:&error];
|
|
|
|
if (error || !contents) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *entry;
|
|
|
|
NSEnumerator *e = [[contents componentsSeparatedByString:@"\n"] objectEnumerator];
|
|
|
|
NSMutableArray *entries = [NSMutableArray array];
|
|
|
|
|
|
|
|
while (entry = [[e nextObject] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]])
|
|
|
|
{
|
|
|
|
NSScanner *scanner = [[NSScanner alloc] initWithString:entry];
|
|
|
|
NSString *lhs = nil;
|
|
|
|
NSString *rhs = nil;
|
|
|
|
|
|
|
|
if (![scanner scanUpToString:@"=" intoString:&lhs] || // get LHS
|
|
|
|
![scanner scanString:@"=" intoString:nil] || // skip the =
|
|
|
|
![scanner scanUpToString:@"" intoString:&rhs] || // get RHS
|
|
|
|
![lhs isEqualToString:@"File"]) // We only want file entries
|
|
|
|
{
|
|
|
|
[scanner release];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//need to add basepath if its a file, and convert to URL
|
|
|
|
[entries addObject:[self urlForPath:rhs relativeTo:filename]];
|
|
|
|
|
|
|
|
[scanner release];
|
|
|
|
}
|
|
|
|
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|