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
|
|
|
|
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
2008-02-18 12:59:20 +00:00
|
|
|
// We need to translate the path string to a full URL
|
|
|
|
NSArray *URLTransform =
|
2008-02-20 00:44:40 +00:00
|
|
|
[NSArray arrayWithObjects:@"URL", @"PathToURLTransformer", nil];
|
2008-02-18 12:59:20 +00:00
|
|
|
|
|
|
|
// Extract the artist name from the authors array
|
|
|
|
NSArray *artistTransform =
|
|
|
|
[NSArray arrayWithObjects:@"artist", @"AuthorToArtistTransformer", nil];
|
2008-03-03 23:02:52 +00:00
|
|
|
|
|
|
|
// Track numbers must sometimes be converted from NSNumber to NSString
|
|
|
|
NSArray *trackTransform =
|
|
|
|
[NSArray arrayWithObjects:@"spotlightTrack", @"NumberToStringTransformer", nil];
|
2008-02-18 12:59:20 +00:00
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
importKeys = [NSDictionary dictionaryWithObjectsAndKeys:
|
2008-02-18 12:59:20 +00:00
|
|
|
@"title", @"kMDItemTitle",
|
|
|
|
@"album", @"kMDItemAlbum",
|
2008-03-03 23:02:52 +00:00
|
|
|
trackTransform, @"kMDItemAudioTrackNumber",
|
2008-02-18 12:59:20 +00:00
|
|
|
@"year", @"kMDItemRecordingYear",
|
|
|
|
@"genre", @"kMDItemMusicalGenre",
|
|
|
|
@"length", @"kMDItemDurationSeconds",
|
|
|
|
URLTransform, @"kMDItemPath",
|
|
|
|
artistTransform, @"kMDItemAuthors",
|
2016-05-05 20:05:39 +00:00
|
|
|
nil];
|
2008-02-12 10:30:32 +00:00
|
|
|
}
|
|
|
|
|
2008-02-11 14:10:25 +00:00
|
|
|
+ (SpotlightPlaylistEntry *)playlistEntryWithMetadataItem:(NSMetadataItem *)metadataItem
|
|
|
|
{
|
2016-05-05 20:05:39 +00:00
|
|
|
SpotlightPlaylistEntry *entry = [[SpotlightPlaylistEntry alloc]init];
|
2008-02-11 14:10:25 +00:00
|
|
|
|
2008-02-18 12:59:20 +00:00
|
|
|
// 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]])
|
|
|
|
{
|
2008-03-08 23:47:29 +00:00
|
|
|
[entry setValue: [metadataItem valueForAttribute:mdKey]
|
2008-02-18 12:59:20 +00:00
|
|
|
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:
|
2008-03-08 23:47:29 +00:00
|
|
|
[metadataItem valueForAttribute:mdKey]];
|
2008-02-18 16:55:31 +00:00
|
|
|
[entry setValue:transformedValue forKey: importKey];
|
2008-02-18 12:59:20 +00:00
|
|
|
}
|
|
|
|
// The importKeys dictionary contains something strange...
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSString *errString =
|
|
|
|
[NSString stringWithFormat:@"ERROR: Could not import key %@", mdKey];
|
|
|
|
NSAssert(NO, errString);
|
|
|
|
}
|
2008-02-11 14:10:25 +00:00
|
|
|
}
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2008-02-29 21:54:09 +00:00
|
|
|
// Length is no longer a dependent key
|
|
|
|
+ (NSSet *)keyPathsForValuesAffectingLength
|
|
|
|
{
|
2008-03-09 00:22:48 +00:00
|
|
|
return nil;
|
2008-02-29 21:54:09 +00:00
|
|
|
}
|
|
|
|
|
2008-03-08 23:47:29 +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-03-09 02:05:00 +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
|
|
|
|
2008-02-12 11:11:26 +00:00
|
|
|
@end
|