[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>
main
Christopher Snowhill 2022-07-25 19:35:11 -07:00
parent 59ac5769ad
commit 03c498c0fc
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 *validURLs = [NSMutableArray array];
NSMutableArray *folderURLs = [NSMutableArray array];
NSMutableArray *dependencyURLs = [NSMutableArray array];
NSDictionary *xmlData = nil;
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.
[uniqueURLs addObject:url];
// Find the dependencies
NSArray *depURLs = [AudioContainer dependencyUrlsForContainerURL:url];
BOOL localFound = NO;
for(NSURL *u in urls) {
@ -431,6 +435,16 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
break;
}
}
if(depURLs) {
[dependencyURLs addObjectsFromArray:depURLs];
for(NSURL *u in depURLs) {
if([u isFileURL]) {
localFound = YES;
break;
}
}
}
if(localFound) {
[[SandboxBroker sharedSandboxBroker] requestFolderForFile:url];
}
@ -459,6 +473,16 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
// Deduplication of contained URLs
[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);