Bug Fix: Play Count data may be missing tags

Sometimes the play count data only includes the filenames, and thus will
fail a query for just the tags. Also, a file query may be stored without
the subsong fragment tag, which will also break the tags.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-02-20 01:25:44 -08:00
parent e97b96b3e9
commit 03cce1b004

View file

@ -588,6 +588,8 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path) {
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[albumPredicate, artistPredicate, titlePredicate]];
__block BOOL fixtags = NO;
__block PlayCount *item = nil;
[kPersistentContainer.viewContext performBlockAndWait:^{
@ -604,6 +606,18 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path) {
request.predicate = filenamePredicate;
results = [kPersistentContainer.viewContext executeFetchRequest:request error:&error];
if(!results || [results count] < 1) {
filenamePredicate = [NSPredicate predicateWithFormat:@"filename == %@", self.filename];
request = [NSFetchRequest fetchRequestWithEntityName:@"PlayCount"];
request.predicate = filenamePredicate;
results = [kPersistentContainer.viewContext executeFetchRequest:request error:&error];
}
if(results && [results count] >= 1) {
fixtags = YES;
}
}
if(!results || [results count] < 1) return;
@ -611,6 +625,19 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path) {
item = results[0];
}];
if(fixtags) {
// shoot, something inserted the play counts without the tags
[kPersistentContainer.viewContext performBlockAndWait:^{
item.album = self.album;
item.artist = self.artist;
item.title = self.title;
item.filename = self.filenameFragment;
}];
NSError *error = nil;
[kPersistentContainer.viewContext save:&error];
}
return item;
}