From a57827f4da9d6259d45d5b4416265ee81f7dab46 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sun, 26 Jun 2022 04:37:41 -0700 Subject: [PATCH] [Play Counts] Fix counts for tracks with subsongs Fix counts for tracks with subsongs from piling all the counts onto the first subsong seen, by using the URL fragment in the filename check and storage. Signed-off-by: Christopher Snowhill --- Playlist/PlaylistController.m | 4 ++-- Playlist/PlaylistEntry.h | 2 ++ Playlist/PlaylistEntry.m | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index e2dfb5e6a..6b396ea7e 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -262,7 +262,7 @@ static void *playlistControllerContext = &playlistControllerContext; pc.album = pe.album; pc.artist = pe.artist; pc.title = pe.title; - pc.filename = pe.filename; + pc.filename = pe.filenameFragment; } [self commitEditing]; @@ -278,7 +278,7 @@ static void *playlistControllerContext = &playlistControllerContext; pc.album = pe.album; pc.artist = pe.artist; pc.title = pe.title; - pc.filename = pe.filename; + pc.filename = pe.filenameFragment; } } diff --git a/Playlist/PlaylistEntry.h b/Playlist/PlaylistEntry.h index 2363bf870..4f10a07b6 100644 --- a/Playlist/PlaylistEntry.h +++ b/Playlist/PlaylistEntry.h @@ -17,6 +17,7 @@ + (NSSet *_Nonnull)keyPathsForValuesAffectingLength; + (NSSet *_Nonnull)keyPathsForValuesAffectingPath; + (NSSet *_Nonnull)keyPathsForValuesAffectingFilename; ++ (NSSet *_Nonnull)keyPathsForValuesAffectingFilenameFragment; + (NSSet *_Nonnull)keyPathsForValuesAffectingStatus; + (NSSet *_Nonnull)keyPathsForValuesAffectingStatusMessage; + (NSSet *_Nonnull)keyPathsForValuesAffectingSpam; @@ -33,6 +34,7 @@ @property(nonatomic, retain, readonly) NSNumber *_Nonnull length; @property(nonatomic, readonly) NSString *_Nonnull path; @property(nonatomic, readonly) NSString *_Nonnull filename; +@property(nonatomic, readonly) NSString *_Nonnull filenameFragment; @property(nonatomic, readonly) NSString *_Nonnull spam; @property(nonatomic, readonly) NSString *_Nonnull indexedSpam; diff --git a/Playlist/PlaylistEntry.m b/Playlist/PlaylistEntry.m index 2d289a582..d83305865 100644 --- a/Playlist/PlaylistEntry.m +++ b/Playlist/PlaylistEntry.m @@ -51,6 +51,10 @@ extern NSMutableDictionary *kArtworkDictionary; return [NSSet setWithObject:@"url"]; } ++ (NSSet *)keyPathsForValuesAffectingFilenameFragment { + return [NSSet setWithObject:@"url"]; +} + + (NSSet *)keyPathsForValuesAffectingStatus { return [NSSet setWithObjects:@"current", @"queued", @"error", @"stopAfter", nil]; } @@ -431,6 +435,15 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path) { return [[self.url path] lastPathComponent]; } +@dynamic filenameFragment; +- (NSString *)filenameFragment { + if([self.url fragment]) { + return [[[self.url path] lastPathComponent] stringByAppendingFormat:@"#%@", [self.url fragment]]; + } else { + return self.filename; + } +} + @dynamic status; - (NSString *)status { if(self.stopAfter) { @@ -508,7 +521,7 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path) { NSArray *results = [kPersistentContainer.viewContext executeFetchRequest:request error:&error]; if(!results || [results count] < 1) { - NSPredicate *filenamePredicate = [NSPredicate predicateWithFormat:@"filename == %@", self.filename]; + NSPredicate *filenamePredicate = [NSPredicate predicateWithFormat:@"filename == %@", self.filenameFragment]; request = [NSFetchRequest fetchRequestWithEntityName:@"PlayCount"]; request.predicate = filenamePredicate;