Now supports reading playlists from remote paths
parent
fa6c02d3e8
commit
5422338d58
|
@ -70,37 +70,48 @@
|
||||||
|
|
||||||
+ (NSArray *)urlsForContainerURL:(NSURL *)url
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url
|
||||||
{
|
{
|
||||||
if (![url isFileURL])
|
char * filecontents = nil;
|
||||||
|
|
||||||
|
{
|
||||||
|
id audioSourceClass = NSClassFromString(@"AudioSource");
|
||||||
|
id<CogSource> source = [audioSourceClass audioSourceForURL:url];
|
||||||
|
|
||||||
|
if (![source open:url])
|
||||||
return [NSArray array];
|
return [NSArray array];
|
||||||
|
|
||||||
NSString *filename = [url path];
|
long size = 0;
|
||||||
|
long bytesread = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
filecontents = (char *) realloc(filecontents, size + 1024);
|
||||||
|
bytesread = [source read:(filecontents + size) amount:1024];
|
||||||
|
size += bytesread;
|
||||||
|
} while (bytesread == 1024);
|
||||||
|
|
||||||
|
filecontents = (char *) realloc(filecontents, size + 1);
|
||||||
|
|
||||||
|
filecontents[size] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
NSStringEncoding encoding;
|
|
||||||
NSError *error = nil;
|
|
||||||
NSString *contents = [NSString stringWithContentsOfFile:filename usedEncoding:&encoding error:&error];
|
|
||||||
if (error) {
|
|
||||||
DLog(@"Trying UTF8");
|
DLog(@"Trying UTF8");
|
||||||
error = nil;
|
NSStringEncoding encoding = NSUTF8StringEncoding;
|
||||||
contents = [NSString stringWithContentsOfFile:filename encoding:NSUTF8StringEncoding error:&error];
|
NSString *contents = [NSString stringWithCString:filecontents encoding:encoding];
|
||||||
}
|
if (!contents) {
|
||||||
if (error) {
|
|
||||||
DLog(@"Trying windows GB 18030 2000");
|
DLog(@"Trying windows GB 18030 2000");
|
||||||
error = nil;
|
contents = [NSString stringWithCString:filecontents encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000)];
|
||||||
contents = [NSString stringWithContentsOfFile:filename encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000) error:&error];
|
|
||||||
}
|
}
|
||||||
if (error) {
|
if (!contents) {
|
||||||
DLog(@"Trying windows CP1251");
|
DLog(@"Trying windows CP1251");
|
||||||
error = nil;
|
contents = [NSString stringWithCString:filecontents encoding:NSWindowsCP1251StringEncoding];
|
||||||
contents = [NSString stringWithContentsOfFile:filename encoding:NSWindowsCP1251StringEncoding error:&error];
|
|
||||||
}
|
}
|
||||||
if (error) {
|
if (!contents) {
|
||||||
DLog(@"Trying latin1");
|
DLog(@"Trying latin1");
|
||||||
error = nil;
|
contents = [NSString stringWithCString:filecontents encoding:NSISOLatin1StringEncoding];
|
||||||
contents = [NSString stringWithContentsOfFile:filename encoding:NSISOLatin1StringEncoding error:&error];
|
|
||||||
}
|
}
|
||||||
if (error || !contents) {
|
free(filecontents);
|
||||||
ALog(@"Could not open file...%@ %@ %@", filename, contents, error);
|
if (!contents) {
|
||||||
return nil;
|
ALog(@"Could not open file...%@ %@", url, contents);
|
||||||
|
return [NSArray array];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray *entries = [NSMutableArray array];
|
NSMutableArray *entries = [NSMutableArray array];
|
||||||
|
@ -113,7 +124,7 @@
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//Need to add basePath, and convert to URL
|
//Need to add basePath, and convert to URL
|
||||||
[entries addObject:[self urlForPath:_entry relativeTo:filename]];
|
[entries addObject:[self urlForPath:_entry relativeTo:[url path]]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
|
|
|
@ -72,37 +72,48 @@
|
||||||
|
|
||||||
+ (NSArray *)urlsForContainerURL:(NSURL *)url
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url
|
||||||
{
|
{
|
||||||
if (![url isFileURL])
|
char * filecontents = nil;
|
||||||
|
|
||||||
|
{
|
||||||
|
id audioSourceClass = NSClassFromString(@"AudioSource");
|
||||||
|
id<CogSource> source = [audioSourceClass audioSourceForURL:url];
|
||||||
|
|
||||||
|
if (![source open:url])
|
||||||
return [NSArray array];
|
return [NSArray array];
|
||||||
|
|
||||||
NSString *filename = [url path];
|
long size = 0;
|
||||||
|
long bytesread = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
filecontents = (char *) realloc(filecontents, size + 1024);
|
||||||
|
bytesread = [source read:(filecontents + size) amount:1024];
|
||||||
|
size += bytesread;
|
||||||
|
} while (bytesread == 1024);
|
||||||
|
|
||||||
|
filecontents = (char *) realloc(filecontents, size + 1);
|
||||||
|
|
||||||
|
filecontents[size] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
NSStringEncoding encoding;
|
|
||||||
NSError *error;
|
|
||||||
NSString *contents = [NSString stringWithContentsOfFile:filename usedEncoding:&encoding error:&error];
|
|
||||||
if (error) {
|
|
||||||
DLog(@"Trying UTF8");
|
DLog(@"Trying UTF8");
|
||||||
error = nil;
|
NSStringEncoding encoding = NSUTF8StringEncoding;
|
||||||
contents = [NSString stringWithContentsOfFile:filename encoding:NSUTF8StringEncoding error:&error];
|
NSString *contents = [NSString stringWithCString:filecontents encoding:encoding];
|
||||||
}
|
if (!contents) {
|
||||||
if (error) {
|
|
||||||
DLog(@"Trying windows GB 18030 2000");
|
DLog(@"Trying windows GB 18030 2000");
|
||||||
error = nil;
|
contents = [NSString stringWithCString:filecontents encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000)];
|
||||||
contents = [NSString stringWithContentsOfFile:filename encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000) error:&error];
|
|
||||||
}
|
}
|
||||||
if (error) {
|
if (!contents) {
|
||||||
DLog(@"Trying windows CP1251");
|
DLog(@"Trying windows CP1251");
|
||||||
error = nil;
|
contents = [NSString stringWithCString:filecontents encoding:NSWindowsCP1251StringEncoding];
|
||||||
contents = [NSString stringWithContentsOfFile:filename encoding:NSWindowsCP1251StringEncoding error:&error];
|
|
||||||
}
|
}
|
||||||
if (error) {
|
if (!contents) {
|
||||||
DLog(@"Trying latin1");
|
DLog(@"Trying latin1");
|
||||||
error = nil;
|
contents = [NSString stringWithCString:filecontents encoding:NSISOLatin1StringEncoding];
|
||||||
contents = [NSString stringWithContentsOfFile:filename encoding:NSISOLatin1StringEncoding error:&error];
|
|
||||||
}
|
}
|
||||||
if (error || !contents) {
|
free(filecontents);
|
||||||
ALog(@"Could not open file...%@ %@ %@", filename, contents, error);
|
if (!contents) {
|
||||||
return nil;
|
ALog(@"Could not open file...%@ %@", url, contents);
|
||||||
|
return [NSArray array];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray *entries = [NSMutableArray array];
|
NSMutableArray *entries = [NSMutableArray array];
|
||||||
|
@ -124,7 +135,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
//need to add basepath if its a file, and convert to URL
|
//need to add basepath if its a file, and convert to URL
|
||||||
[entries addObject:[self urlForPath:rhs relativeTo:filename]];
|
[entries addObject:[self urlForPath:rhs relativeTo:[url path]]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
|
|
Loading…
Reference in New Issue