Fixed up playlist-as-file loading.
This commit is contained in:
parent
321aa5782b
commit
1b1b353204
1 changed files with 45 additions and 30 deletions
|
@ -251,10 +251,11 @@
|
||||||
|
|
||||||
- (void)insertURLs:(NSArray *)urls atIndex:(int)index sort:(BOOL)sort
|
- (void)insertURLs:(NSArray *)urls atIndex:(int)index sort:(BOOL)sort
|
||||||
{
|
{
|
||||||
NSMutableSet *uniqueURLs = [[NSMutableSet alloc] init];
|
NSMutableSet *uniqueURLs = [NSMutableSet set];
|
||||||
NSMutableArray *allURLs = [[NSMutableArray alloc] init];
|
|
||||||
NSMutableArray *validURLs = [[NSMutableArray alloc] init];
|
NSMutableArray *expandedURLs = [NSMutableArray array];
|
||||||
NSArray *finalURLs;
|
NSMutableArray *allURLs = [NSMutableArray array];
|
||||||
|
NSMutableArray *validURLs = [NSMutableArray array];
|
||||||
|
|
||||||
if (!urls)
|
if (!urls)
|
||||||
return;
|
return;
|
||||||
|
@ -274,28 +275,53 @@
|
||||||
if (isDir == YES)
|
if (isDir == YES)
|
||||||
{
|
{
|
||||||
//Get subpaths
|
//Get subpaths
|
||||||
[allURLs addObjectsFromArray:[self fileURLsAtPath:[url path]]];
|
[expandedURLs addObjectsFromArray:[self fileURLsAtPath:[url path]]];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//File url
|
[expandedURLs addObject:url];
|
||||||
if ([[self acceptablePlaylistTypes] containsObject:[[url path] pathExtension]]) {
|
|
||||||
[allURLs addObjectsFromArray:[self urlsFromPlaylist:[url path]]];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//Not a playlist!
|
|
||||||
[allURLs addObject:url];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Non-file URL..
|
//Non-file URL..
|
||||||
|
[expandedURLs addObject:url];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NSLog(@"Expanded URLs: %@", expandedURLs);
|
||||||
|
|
||||||
|
NSArray *sortedURLs;
|
||||||
|
if (sort == YES)
|
||||||
|
{
|
||||||
|
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"absoluteString" ascending:YES];
|
||||||
|
|
||||||
|
sortedURLs = [expandedURLs sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
|
||||||
|
|
||||||
|
[sortDescriptor release];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sortedURLs = [expandedURLs copy];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSLog(@"Sorted URLs: %@", expandedURLs);
|
||||||
|
|
||||||
|
urlEnumerator = [sortedURLs objectEnumerator];
|
||||||
|
while (url = [urlEnumerator nextObject])
|
||||||
|
{
|
||||||
|
//File url
|
||||||
|
if ([[self acceptablePlaylistTypes] containsObject:[[url path] pathExtension]]) {
|
||||||
|
[allURLs addObjectsFromArray:[self urlsFromPlaylist:[url path]]];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
[allURLs addObject:url];
|
[allURLs addObject:url];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSLog(@"All URLs: %@", allURLs);
|
||||||
|
|
||||||
urlEnumerator = [allURLs objectEnumerator];
|
urlEnumerator = [allURLs objectEnumerator];
|
||||||
while (url = [urlEnumerator nextObject])
|
while (url = [urlEnumerator nextObject])
|
||||||
|
@ -304,7 +330,7 @@
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//Need a better way to determine acceptable file types than basing it on extensions.
|
//Need a better way to determine acceptable file types than basing it on extensions.
|
||||||
if (![[self acceptableFileTypes] containsObject:[[[url path] pathExtension] lowercaseString]])
|
if (![[AudioPlayer fileTypes] containsObject:[[[url path] pathExtension] lowercaseString]])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (![uniqueURLs containsObject:url])
|
if (![uniqueURLs containsObject:url])
|
||||||
|
@ -315,23 +341,16 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finalURLs = validURLs;
|
NSLog(@"Valid URLs: %@", validURLs);
|
||||||
if (sort == YES)
|
|
||||||
{
|
|
||||||
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"absoluteString" ascending:YES];
|
|
||||||
|
|
||||||
finalURLs = [validURLs sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
|
|
||||||
|
|
||||||
[sortDescriptor release];
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create actual entries
|
//Create actual entries
|
||||||
int i;
|
int i;
|
||||||
NSMutableArray *entries = [NSMutableArray array];
|
NSMutableArray *entries = [NSMutableArray array];
|
||||||
for (i = 0; i < [finalURLs count]; i++)
|
for (i = 0; i < [validURLs count]; i++)
|
||||||
{
|
{
|
||||||
PlaylistEntry *pe = [[PlaylistEntry alloc] init];
|
PlaylistEntry *pe = [[PlaylistEntry alloc] init];
|
||||||
NSURL *url = [finalURLs objectAtIndex:i];
|
NSURL *url = [validURLs objectAtIndex:i];
|
||||||
|
|
||||||
[pe setURL:url];
|
[pe setURL:url];
|
||||||
[pe setIndex:[NSNumber numberWithInt:(index+i)]];
|
[pe setIndex:[NSNumber numberWithInt:(index+i)]];
|
||||||
|
@ -352,10 +371,6 @@
|
||||||
//Other thread for reading things...
|
//Other thread for reading things...
|
||||||
[NSThread detachNewThreadSelector:@selector(readEntriesInfoThread:) toTarget:self withObject:entries];
|
[NSThread detachNewThreadSelector:@selector(readEntriesInfoThread:) toTarget:self withObject:entries];
|
||||||
|
|
||||||
[allURLs release];
|
|
||||||
[validURLs release];
|
|
||||||
[uniqueURLs release];
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue