2008-02-11 11:10:25 -03:00
|
|
|
//
|
|
|
|
// SpotlightPlaylistEntry.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Matthew Grinshpun on 11/02/08.
|
|
|
|
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "SpotlightPlaylistEntry.h"
|
|
|
|
|
|
|
|
// Class array for metadata keys we want
|
|
|
|
static NSArray * mdKeys;
|
|
|
|
|
|
|
|
// Corresponding array for playlist entry keys
|
|
|
|
static NSArray * entryKeys;
|
2008-02-11 11:42:13 -03:00
|
|
|
|
|
|
|
// extramdKeys represents those keys that require additional processing
|
|
|
|
static NSArray * extramdKeys;
|
2008-02-11 13:39:19 -03:00
|
|
|
|
|
|
|
// allmdKeys is a combined array of both mdKeys and entryKeys
|
|
|
|
static NSArray * allmdKeys;
|
2008-02-11 11:10:25 -03:00
|
|
|
|
|
|
|
// And the dictionary that matches them
|
|
|
|
static NSDictionary * tags;
|
|
|
|
|
|
|
|
@implementation SpotlightPlaylistEntry
|
|
|
|
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
mdKeys = [NSArray arrayWithObjects:
|
|
|
|
@"kMDItemTitle",
|
|
|
|
@"kMDItemAlbum",
|
|
|
|
@"kMDItemAudioTrackNumber",
|
|
|
|
@"kMDItemRecordingYear",
|
|
|
|
@"kMDItemMusicalGenre",
|
2008-02-11 13:39:19 -03:00
|
|
|
@"kMDItemDurationSeconds",
|
2008-02-11 11:10:25 -03:00
|
|
|
nil];
|
|
|
|
entryKeys = [NSArray arrayWithObjects:
|
|
|
|
@"title",
|
|
|
|
@"album",
|
|
|
|
@"track",
|
|
|
|
@"year",
|
|
|
|
@"genre",
|
2008-02-11 13:39:19 -03:00
|
|
|
@"length",
|
2008-02-11 11:10:25 -03:00
|
|
|
nil];
|
2008-02-11 11:42:13 -03:00
|
|
|
extramdKeys = [NSArray arrayWithObjects:
|
|
|
|
@"kMDItemPath",
|
2008-02-11 13:39:19 -03:00
|
|
|
@"kMDItemAuthors",
|
2008-02-11 11:42:13 -03:00
|
|
|
nil];
|
2008-02-11 13:39:19 -03:00
|
|
|
allmdKeys = [mdKeys arrayByAddingObjectsFromArray:extramdKeys];
|
2008-02-11 11:10:25 -03:00
|
|
|
tags = [NSDictionary dictionaryWithObjects:entryKeys forKeys:mdKeys];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (SpotlightPlaylistEntry *)playlistEntryWithMetadataItem:(NSMetadataItem *)metadataItem
|
|
|
|
{
|
|
|
|
// use the matching tag sets to generate a playlist entry
|
|
|
|
SpotlightPlaylistEntry *entry = [[[SpotlightPlaylistEntry alloc] init] autorelease];
|
2008-02-11 13:39:19 -03:00
|
|
|
NSDictionary *songAttributes = [metadataItem valuesForAttributes:allmdKeys];
|
2008-02-11 11:10:25 -03:00
|
|
|
for (NSString * mdKey in tags) {
|
|
|
|
[entry setValue: [songAttributes objectForKey:mdKey]
|
|
|
|
forKey:[tags objectForKey:mdKey]];
|
|
|
|
|
|
|
|
}
|
2008-02-11 11:42:13 -03:00
|
|
|
// URL needs to be generated from the simple path stored in kMDItemPath
|
2008-02-11 13:39:19 -03:00
|
|
|
[entry setURL: [NSURL fileURLWithPath: [songAttributes objectForKey:@"kMDItemPath"]]];
|
|
|
|
|
|
|
|
// Authors is an array, but we only care about the first item in it
|
|
|
|
[entry setArtist: [[songAttributes objectForKey:@"kMDItemAuthors"] objectAtIndex:0]];
|
2008-02-11 11:10:25 -03:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
if (self = [super init])
|
|
|
|
{
|
2008-02-11 13:39:19 -03:00
|
|
|
length = nil;
|
2008-02-11 11:10:25 -03:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
2008-02-11 13:39:19 -03:00
|
|
|
|
|
|
|
@synthesize length;
|
2008-02-11 11:10:25 -03:00
|
|
|
@end
|