-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUKITunesPlaylist.m
151 lines (119 loc) · 2.96 KB
/
UKITunesPlaylist.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//
// UKITunesPlaylist.m
// TrackStorer
//
// Created by Uli Kusterer on 25.03.06.
// Copyright 2006 Uli Kusterer. All rights reserved.
//
#import "UKITunesPlaylist.h"
#import "UKITunesLibrary.h"
@implementation UKITunesPlaylist
-(id) initWithPlaylistDictionary: (NSDictionary*)plData owner: (UKITunesLibrary*)boss
{
self = [super init];
if( !self )
return nil;
playlistData = [plData retain];
owner = [boss retain];
return self;
}
-(void) dealloc
{
[playlistData release];
playlistData = nil;
[owner release];
owner = nil;
[icon release];
icon = nil;
[super dealloc];
}
-(BOOL) isMainLibrary
{
NSNumber* theFlagObj = [playlistData objectForKey: @"Master"];
BOOL theFlag = theFlagObj != nil && [theFlagObj boolValue];
return theFlag;
}
-(BOOL) isPodcasts
{
NSNumber* theFlagObj = [playlistData objectForKey: @"Podcasts"];
BOOL theFlag = theFlagObj != nil && [theFlagObj boolValue];
return theFlag;
}
-(BOOL) isVideos
{
NSNumber* theFlagObj = [playlistData objectForKey: @"Videos"];
BOOL theFlag = theFlagObj != nil && [theFlagObj boolValue];
return theFlag;
}
-(BOOL) isSmart
{
return( [playlistData objectForKey: @"Smart Info"] != nil );
}
-(BOOL) isFolder
{
NSNumber* theFlagObj = [playlistData objectForKey: @"Folder"];
BOOL theFlag = theFlagObj != nil && [theFlagObj boolValue];
return theFlag;
}
-(NSString*) name
{
return [playlistData objectForKey: @"Name"];
}
-(NSImage*) icon
{
if( !icon )
{
if( [self isMainLibrary] )
icon = [[NSImage imageNamed: @"itunes_library"] retain];
else if( [self isPodcasts] )
icon = [[NSImage imageNamed: @"itunes_podcasts"] retain];
else if( [self isVideos] )
icon = [[NSImage imageNamed: @"itunes_videos"] retain];
else if( [self isFolder] )
icon = [[NSImage imageNamed: @"itunes_folder"] retain];
else if( [self isSmart] )
icon = [[NSImage imageNamed: @"itunes_smart_playlist"] retain];
else
icon = [[NSImage imageNamed: @"itunes_simple_playlist"] retain];
}
return icon;
}
-(int) count
{
return [[playlistData objectForKey: @"Playlist Items"] count];
}
-(NSDictionary*) trackDictionaryForItemAtIndex: (int)n
{
NSArray* playlistItems = [playlistData objectForKey: @"Playlist Items"];
if( !playlistItems )
{
NSLog(@"playlistItems == NULL");
return nil;
}
NSDictionary* playlistItem = [playlistItems objectAtIndex: n];
if( !playlistItem )
{
NSLog(@"playlistItems = %@", playlistItems);
return nil;
}
NSNumber* trackID = [playlistItem objectForKey: @"Track ID"];
if( !trackID )
{
NSLog(@"playlistItem = %@", playlistItem);
return nil;
}
return [owner trackDictionaryByID: trackID];
}
-(NSString*) persistentID
{
return [playlistData objectForKey: @"Playlist Persistent ID"];
}
-(NSString*) parentPersistentID
{
return [playlistData objectForKey: @"Parent Persistent ID"];
}
-(NSString*) description
{
return [NSString stringWithFormat: @"%@ { playlistData = %@, owner = %lx }", NSStringFromClass( [self class] ), playlistData, (int)owner];
}
@end