2008-02-11 14:10:25 +00:00
|
|
|
//
|
|
|
|
// SpotlightPlaylistEntry.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Matthew Grinshpun on 11/02/08.
|
2008-02-14 14:07:10 +00:00
|
|
|
// Copyright 2008 Matthew Leon Grinshpun. All rights reserved.
|
2008-02-11 14:10:25 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "SpotlightPlaylistEntry.h"
|
|
|
|
|
2008-02-18 12:59:20 +00:00
|
|
|
// dictionary that lets us translate from and mdKey to an entryKey
|
|
|
|
// if we need the help of a transformer, we use an nsarray
|
|
|
|
// with format (entryKey, transformerName)
|
|
|
|
static NSDictionary *importKeys;
|
2008-02-11 14:10:25 +00:00
|
|
|
|
|
|
|
@implementation SpotlightPlaylistEntry
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (void)initialize {
|
|
|
|
// We need to translate the path string to a full URL
|
|
|
|
NSArray *URLTransform =
|
|
|
|
@[@"URL", @"PathToURLTransformer"];
|
|
|
|
|
|
|
|
// Extract the artist name from the authors array
|
|
|
|
NSArray *artistTransform =
|
|
|
|
@[@"artist", @"AuthorToArtistTransformer"];
|
|
|
|
|
|
|
|
// Track numbers must sometimes be converted from NSNumber to NSString
|
|
|
|
NSArray *trackTransform =
|
|
|
|
@[@"spotlightTrack", @"NumberToStringTransformer"];
|
|
|
|
|
2022-02-09 03:42:03 +00:00
|
|
|
importKeys = @{@"kMDItemTitle": @"title",
|
|
|
|
@"kMDItemAlbum": @"album",
|
|
|
|
@"kMDItemAudioTrackNumber": trackTransform,
|
|
|
|
@"kMDItemRecordingYear": @"year",
|
|
|
|
@"kMDItemMusicalGenre": @"genre",
|
|
|
|
@"kMDItemDurationSeconds": @"length",
|
|
|
|
@"kMDItemPath": URLTransform,
|
|
|
|
@"kMDItemAuthors": artistTransform};
|
2008-02-12 10:30:32 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (SpotlightPlaylistEntry *)playlistEntryWithMetadataItem:(NSMetadataItem *)metadataItem {
|
|
|
|
SpotlightPlaylistEntry *entry = [[SpotlightPlaylistEntry alloc] init];
|
|
|
|
|
|
|
|
// loop through the keys we want to extract
|
|
|
|
for(NSString *mdKey in importKeys) {
|
|
|
|
id importTarget = [importKeys objectForKey:mdKey];
|
|
|
|
// Just copy the object from metadata
|
|
|
|
if([importTarget isKindOfClass:[NSString class]]) {
|
|
|
|
[entry setValue:[metadataItem valueForAttribute:mdKey]
|
|
|
|
forKey:importTarget];
|
|
|
|
}
|
|
|
|
// Transform the value in metadata before copying it in
|
|
|
|
else if([importTarget isKindOfClass:[NSArray class]]) {
|
|
|
|
NSString *importKey = [importTarget objectAtIndex:0];
|
|
|
|
NSValueTransformer *transformer =
|
|
|
|
[NSValueTransformer valueTransformerForName:[importTarget objectAtIndex:1]];
|
|
|
|
id transformedValue = [transformer transformedValue:
|
|
|
|
[metadataItem valueForAttribute:mdKey]];
|
|
|
|
[entry setValue:transformedValue forKey:importKey];
|
|
|
|
}
|
|
|
|
// The importKeys dictionary contains something strange...
|
|
|
|
else {
|
|
|
|
NSString *errString =
|
|
|
|
[NSString stringWithFormat:@"ERROR: Could not import key %@", mdKey];
|
|
|
|
NSAssert(NO, errString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return entry;
|
2008-02-11 14:10:25 +00:00
|
|
|
}
|
|
|
|
|
2008-02-29 21:54:09 +00:00
|
|
|
// Length is no longer a dependent key
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingLength {
|
|
|
|
return nil;
|
2008-02-29 21:54:09 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)dealloc {
|
2008-03-09 02:05:00 +00:00
|
|
|
self.length = nil;
|
|
|
|
self.spotlightTrack = nil;
|
2008-03-08 23:47:29 +00:00
|
|
|
}
|
|
|
|
|
2008-02-11 16:39:19 +00:00
|
|
|
@synthesize length;
|
2008-03-03 23:02:52 +00:00
|
|
|
@synthesize spotlightTrack;
|
2008-02-18 12:59:20 +00:00
|
|
|
|
2022-01-19 02:12:57 +00:00
|
|
|
@end
|