Skip to content

Commit

Permalink
Bug Fix: Play Count data may be missing tags
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kode54 committed Feb 20, 2025
1 parent ff9bd89 commit e3209e8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Playlist/PlaylistEntry.m
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ - (PlayCount *)playCountItem {

NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[albumPredicate, artistPredicate, titlePredicate]];

__block BOOL fixtags = NO;

__block PlayCount *item = nil;

[kPersistentContainer.viewContext performBlockAndWait:^{
Expand All @@ -604,13 +606,38 @@ - (PlayCount *)playCountItem {
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;

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;
}

Expand Down

0 comments on commit e3209e8

Please sign in to comment.