From 86de03a1ab80de7fb6585c25768c874214475613 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sat, 25 Jun 2022 02:40:05 -0700 Subject: [PATCH] [Play Count Info] Tabulate first seen info later Tabulate first seen information when loading the metadata, rather than when first adding the tracks to the playlist. This should fix first seen information when metadata is available, as the information will be useless without track titles. Signed-off-by: Christopher Snowhill --- Playlist/PlaylistController.h | 1 + Playlist/PlaylistController.m | 5 ----- Playlist/PlaylistLoader.m | 5 +++++ 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Playlist/PlaylistController.h b/Playlist/PlaylistController.h index a5e0195aa..a2ce9e19d 100644 --- a/Playlist/PlaylistController.h +++ b/Playlist/PlaylistController.h @@ -143,6 +143,7 @@ typedef NS_ENUM(NSInteger, URLOrigin) { // Play statistics - (void)updatePlayCountForTrack:(PlaylistEntry *_Nonnull)pe; +- (void)firstSawTrack:(PlaylistEntry *_Nonnull)pe; - (void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *_Nullable)indexSet toIndex:(NSUInteger)insertIndex; diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index 0a0cf899e..e2dfb5e6a 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -1675,11 +1675,6 @@ static void *playlistControllerContext = &playlistControllerContext; - (void)didInsertURLs:(NSArray *)urls origin:(URLOrigin)origin { if(![urls count]) return; - for(PlaylistEntry *pe in urls) { - [self firstSawTrack:pe]; - } - [self commitPersistentStore]; - NSArray *nsurls = [urls valueForKey:@"url"]; if(![[SandboxBroker sharedSandboxBroker] areAllPathsSafe:nsurls]) { [appController showPathSuggester]; diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index c2e093461..f464eb299 100644 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -735,9 +735,13 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path); __block NSString *entryKey = [outArray objectAtIndex:i]; __block NSDictionary *entryInfo = [outArray objectAtIndex:i + 1]; __block NSMutableIndexSet *weakUpdateIndexes = update_indexes; + PlaylistController *playlistController = self->playlistController; dispatch_sync_reentrant(dispatch_get_main_queue(), ^{ NSArray *entrySet = [uniquePathsEntries objectForKey:entryKey]; if(entrySet) { + if([entrySet count] > 0) { + [playlistController firstSawTrack:entrySet[0]]; + } for(PlaylistEntry *pe in entrySet) { [pe setMetadata:entryInfo]; if(pe.index >= 0 && pe.index < NSNotFound) { @@ -811,6 +815,7 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path); NSDictionary *entryInfo = [NSDictionary dictionaryByMerging:entryProperties with:[AudioMetadataReader metadataForURL:pe.url]]; [pe setMetadata:entryInfo]; + [playlistController firstSawTrack:pe]; }]; [self->playlistController updateTotalTime];