[Spotlight Panel] Fixed to work with new Core Data

Fixed the implementation to work correctly with the new Core Data
storage system. Tracks will be garbage collected later.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
swiftingly
Christopher Snowhill 2022-06-16 17:37:11 -07:00
parent c71021fc9b
commit 333c6c7e8b
4 changed files with 16 additions and 8 deletions

View File

@ -130,7 +130,7 @@ DQ
</textFieldCell> </textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/> <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<connections> <connections>
<binding destination="16" name="value" keyPath="arrangedObjects.lengthText" id="K4A-L7-jOn"> <binding destination="16" name="value" keyPath="arrangedObjects.spotlightLength" id="gWF-nL-fqJ">
<dictionary key="options"> <dictionary key="options">
<bool key="NSConditionallySetsEditable" value="YES"/> <bool key="NSConditionallySetsEditable" value="YES"/>
</dictionary> </dictionary>
@ -285,9 +285,8 @@ DQ
<string>artist</string> <string>artist</string>
<string>album</string> <string>album</string>
<string>genre</string> <string>genre</string>
<string>lengthText</string> <string>spotlightLength</string>
<string>track</string> <string>spotlightTrack</string>
<string>trackText</string>
</declaredKeys> </declaredKeys>
<classReference key="objectClass" className="PlaylistEntry"/> <classReference key="objectClass" className="PlaylistEntry"/>
<connections> <connections>

View File

@ -40,6 +40,8 @@
<attribute name="sampleRate" optional="YES" attributeType="Float" defaultValueString="0.0" usesScalarValueType="YES"/> <attribute name="sampleRate" optional="YES" attributeType="Float" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="seekable" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/> <attribute name="seekable" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="shuffleIndex" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/> <attribute name="shuffleIndex" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="spotlightLength" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
<attribute name="spotlightTrack" optional="YES" attributeType="String"/>
<attribute name="stopAfter" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/> <attribute name="stopAfter" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="totalFrames" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/> <attribute name="totalFrames" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="track" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/> <attribute name="track" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
@ -50,7 +52,7 @@
<attribute name="year" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/> <attribute name="year" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
</entity> </entity>
<elements> <elements>
<element name="PlaylistEntry" positionX="-36" positionY="9" width="128" height="674"/>
<element name="AlbumArtwork" positionX="0" positionY="207" width="128" height="59"/> <element name="AlbumArtwork" positionX="0" positionY="207" width="128" height="59"/>
<element name="PlaylistEntry" positionX="-36" positionY="9" width="128" height="704"/>
</elements> </elements>
</model> </model>

View File

@ -26,11 +26,16 @@ extern NSPersistentContainer *__persistentContainer;
NSArray *artistTransform = NSArray *artistTransform =
@[@"artist", @"AuthorToArtistTransformer"]; @[@"artist", @"AuthorToArtistTransformer"];
// Track numbers must sometimes be converted from NSNumber to NSString
NSArray *trackTransform =
@[@"spotlightTrack", @"NumberToStringTransformer"];
importKeys = @{ @"kMDItemTitle": @"title", importKeys = @{ @"kMDItemTitle": @"title",
@"kMDItemAlbum": @"album", @"kMDItemAlbum": @"album",
@"kMDItemAudioTrackNumber": @"track", @"kMDItemAudioTrackNumber": trackTransform,
@"kMDItemRecordingYear": @"year", @"kMDItemRecordingYear": @"year",
@"kMDItemMusicalGenre": @"genre", @"kMDItemMusicalGenre": @"genre",
@"kMDItemDurationSeconds": @"spotlightLength",
@"kMDItemPath": URLTransform, @"kMDItemPath": URLTransform,
@"kMDItemAuthors": artistTransform }; @"kMDItemAuthors": artistTransform };
} }
@ -38,6 +43,8 @@ extern NSPersistentContainer *__persistentContainer;
+ (PlaylistEntry *)playlistEntryWithMetadataItem:(NSMetadataItem *)metadataItem { + (PlaylistEntry *)playlistEntryWithMetadataItem:(NSMetadataItem *)metadataItem {
PlaylistEntry *entry = [NSEntityDescription insertNewObjectForEntityForName:@"PlaylistEntry" inManagedObjectContext:__persistentContainer.viewContext]; PlaylistEntry *entry = [NSEntityDescription insertNewObjectForEntityForName:@"PlaylistEntry" inManagedObjectContext:__persistentContainer.viewContext];
entry.deLeted = YES;
// loop through the keys we want to extract // loop through the keys we want to extract
for(NSString *mdKey in importKeys) { for(NSString *mdKey in importKeys) {
id importTarget = [importKeys objectForKey:mdKey]; id importTarget = [importKeys objectForKey:mdKey];

View File

@ -244,8 +244,8 @@ static NSPredicate *musicOnlyPredicate = nil;
if([tracks count] == 0) if([tracks count] == 0)
tracks = playlistController.arrangedObjects; tracks = playlistController.arrangedObjects;
[playlistLoader willInsertURLs:[tracks valueForKey:@"URL"] origin:URLOriginExternal]; [playlistLoader willInsertURLs:[tracks valueForKey:@"url"] origin:URLOriginExternal];
[playlistLoader didInsertURLs:[playlistLoader addURLs:[tracks valueForKey:@"URL"] sort:NO] origin:URLOriginExternal]; [playlistLoader didInsertURLs:[playlistLoader addURLs:[tracks valueForKey:@"url"] sort:NO] origin:URLOriginExternal];
[self.query enableUpdates]; [self.query enableUpdates];
} }