[Playlist Loader] Extend deduplication to CUEs

CUEs will now deduplicate playlist entries based on their dependencies,
and prevent loading redundant tracks if you add an entire directory, or
use the option to add a directory when adding single files from it.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
xcode15
Christopher Snowhill 2022-07-25 19:35:11 -07:00
parent 177f055910
commit b04be78f20
1 changed files with 24 additions and 0 deletions

View File

@ -342,6 +342,7 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
NSMutableArray *fileURLs = [NSMutableArray array]; NSMutableArray *fileURLs = [NSMutableArray array];
NSMutableArray *validURLs = [NSMutableArray array]; NSMutableArray *validURLs = [NSMutableArray array];
NSMutableArray *folderURLs = [NSMutableArray array]; NSMutableArray *folderURLs = [NSMutableArray array];
NSMutableArray *dependencyURLs = [NSMutableArray array];
NSDictionary *xmlData = nil; NSDictionary *xmlData = nil;
BOOL addOtherFilesInFolder = [[NSUserDefaults standardUserDefaults] boolForKey:@"addOtherFilesInFolders"]; BOOL addOtherFilesInFolder = [[NSUserDefaults standardUserDefaults] boolForKey:@"addOtherFilesInFolders"];
@ -423,6 +424,9 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
// Make sure the container isn't added twice. // Make sure the container isn't added twice.
[uniqueURLs addObject:url]; [uniqueURLs addObject:url];
// Find the dependencies
NSArray *depURLs = [AudioContainer dependencyUrlsForContainerURL:url];
BOOL localFound = NO; BOOL localFound = NO;
for(NSURL *u in urls) { for(NSURL *u in urls) {
@ -431,6 +435,16 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
break; break;
} }
} }
if(depURLs) {
[dependencyURLs addObjectsFromArray:depURLs];
for(NSURL *u in depURLs) {
if([u isFileURL]) {
localFound = YES;
break;
}
}
}
if(localFound) { if(localFound) {
[[SandboxBroker sharedSandboxBroker] requestFolderForFile:url]; [[SandboxBroker sharedSandboxBroker] requestFolderForFile:url];
} }
@ -459,6 +473,16 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
// Deduplication of contained URLs // Deduplication of contained URLs
[fileURLs removeObjectsInArray:containedURLs]; [fileURLs removeObjectsInArray:containedURLs];
[fileURLs removeObjectsInArray:dependencyURLs];
for(NSURL *u in dependencyURLs) {
for(NSUInteger c = 0; c < [containedURLs count];) {
if([[u path] isEqualToString:[containedURLs[c] path]]) {
[containedURLs removeObjectAtIndex:c];
} else {
++c;
}
}
}
DLog(@"File urls: %@", fileURLs); DLog(@"File urls: %@", fileURLs);