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:
parent
ff9bd89389
commit
e3209e8901
1 changed files with 27 additions and 0 deletions
|
@ -588,6 +588,8 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path) {
|
||||||
|
|
||||||
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[albumPredicate, artistPredicate, titlePredicate]];
|
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[albumPredicate, artistPredicate, titlePredicate]];
|
||||||
|
|
||||||
|
__block BOOL fixtags = NO;
|
||||||
|
|
||||||
__block PlayCount *item = nil;
|
__block PlayCount *item = nil;
|
||||||
|
|
||||||
[kPersistentContainer.viewContext performBlockAndWait:^{
|
[kPersistentContainer.viewContext performBlockAndWait:^{
|
||||||
|
@ -604,6 +606,18 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path) {
|
||||||
request.predicate = filenamePredicate;
|
request.predicate = filenamePredicate;
|
||||||
|
|
||||||
results = [kPersistentContainer.viewContext executeFetchRequest:request error:&error];
|
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;
|
if(!results || [results count] < 1) return;
|
||||||
|
@ -611,6 +625,19 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path) {
|
||||||
item = results[0];
|
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;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue