cog/Spotlight/SpotlightPlaylistEntry.m

83 lines
2.6 KiB
Matlab
Raw Normal View History

//
// 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 14:42:13 +00:00
// extramdKeys represents those keys that require additional processing
static NSArray * extramdKeys;
// allmdKeys is a combined array of both mdKeys and entryKeys
static NSArray * allmdKeys;
// And the dictionary that matches them
static NSDictionary * tags;
@implementation SpotlightPlaylistEntry
+ (void)initialize
{
mdKeys = [NSArray arrayWithObjects:
@"kMDItemTitle",
@"kMDItemAlbum",
@"kMDItemAudioTrackNumber",
@"kMDItemRecordingYear",
@"kMDItemMusicalGenre",
@"kMDItemDurationSeconds",
nil];
entryKeys = [NSArray arrayWithObjects:
@"title",
@"album",
@"track",
@"year",
@"genre",
@"length",
nil];
2008-02-11 14:42:13 +00:00
extramdKeys = [NSArray arrayWithObjects:
@"kMDItemPath",
@"kMDItemAuthors",
2008-02-11 14:42:13 +00:00
nil];
allmdKeys = [mdKeys arrayByAddingObjectsFromArray:extramdKeys];
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];
NSDictionary *songAttributes = [metadataItem valuesForAttributes:allmdKeys];
for (NSString * mdKey in tags) {
[entry setValue: [songAttributes objectForKey:mdKey]
forKey:[tags objectForKey:mdKey]];
}
2008-02-11 14:42:13 +00:00
// URL needs to be generated from the simple path stored in kMDItemPath
[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]];
return entry;
}
- (id)init
{
if (self = [super init])
{
length = nil;
}
return self;
}
@synthesize length;
@end