PageRenderTime 89ms CodeModel.GetById 18ms app.highlight 68ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/YouTube/GDataYouTubeMediaElements.m

http://macfuse.googlecode.com/
Objective C | 269 lines | 173 code | 57 blank | 39 comment | 4 complexity | 4caaa994501d3036d09b9a5e418b1f7e MD5 | raw file
  1/* Copyright (c) 2008 Google Inc.
  2 *
  3 * Licensed under the Apache License, Version 2.0 (the "License");
  4 * you may not use this file except in compliance with the License.
  5 * You may obtain a copy of the License at
  6 *
  7 *     http://www.apache.org/licenses/LICENSE-2.0
  8 *
  9 * Unless required by applicable law or agreed to in writing, software
 10 * distributed under the License is distributed on an "AS IS" BASIS,
 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12 * See the License for the specific language governing permissions and
 13 * limitations under the License.
 14 */
 15
 16//
 17//  GDataYouTubeMediaElements.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_YOUTUBE_SERVICE
 21
 22#define GDATAYOUTUBEMEDIAELEMENTS_DEFINE_GLOBALS 1
 23#import "GDataYouTubeMediaElements.h"
 24#import "GDataYouTubeConstants.h"
 25
 26// yt:format attribute
 27@interface GDataYouTubeFormatAttribute : GDataAttribute <GDataExtension>
 28@end
 29
 30@implementation GDataYouTubeFormatAttribute
 31+ (NSString *)extensionElementURI { return kGDataNamespaceYouTube; }
 32+ (NSString *)extensionElementPrefix { return kGDataNamespaceYouTubePrefix; }
 33+ (NSString *)extensionElementLocalName { return @"format"; }
 34@end
 35
 36@implementation GDataMediaContent (YouTubeExtensions)
 37
 38// media content with YouTube's addition of an integer format attribute, 
 39// like yt:format="1"
 40- (NSNumber *)youTubeFormatNumber {
 41  NSString *str = [self attributeValueForExtensionClass:[GDataYouTubeFormatAttribute class]];
 42  NSNumber *number = [NSNumber numberWithInt:[str intValue]]; 
 43  return number;
 44}
 45
 46- (void)setYouTubeFormatNumber:(NSNumber *)num {
 47  [self setAttributeValue:[num stringValue] forExtensionClass:[GDataYouTubeFormatAttribute class]];
 48}
 49
 50@end
 51
 52// yt:name attribute
 53@interface GDataYouTubeNameAttribute : GDataAttribute <GDataExtension>
 54@end
 55
 56@implementation GDataYouTubeNameAttribute
 57+ (NSString *)extensionElementURI { return kGDataNamespaceYouTube; }
 58+ (NSString *)extensionElementPrefix { return kGDataNamespaceYouTubePrefix; }
 59+ (NSString *)extensionElementLocalName { return @"name"; }
 60@end
 61
 62@implementation GDataMediaThumbnail (YouTubeExtensions)
 63
 64// media thumbnail with YouTube's addition of a name attribute,
 65// like yt:name="default"
 66- (NSString *)youTubeName {
 67  NSString *str = [self attributeValueForExtensionClass:[GDataYouTubeNameAttribute class]];
 68  return str;
 69}
 70
 71- (void)setYouTubeName:(NSString *)str {
 72  [self setAttributeValue:str forExtensionClass:[GDataYouTubeNameAttribute class]];
 73}
 74
 75@end
 76
 77// yt:country attribute
 78@interface GDataYouTubeCountryAttribute : GDataAttribute <GDataExtension>
 79@end
 80
 81@implementation GDataYouTubeCountryAttribute
 82+ (NSString *)extensionElementURI { return kGDataNamespaceYouTube; }
 83+ (NSString *)extensionElementPrefix { return kGDataNamespaceYouTubePrefix; }
 84+ (NSString *)extensionElementLocalName { return @"country"; }
 85@end
 86
 87@implementation GDataMediaRating (YouTubeExtensions)
 88
 89// media rating with YouTube's addition of a country attribute, 
 90// like yt:country="USA"
 91- (NSString *)youTubeCountry {
 92  NSString *str = [self attributeValueForExtensionClass:[GDataYouTubeCountryAttribute class]];
 93  return str;
 94}
 95
 96- (void)setYouTubeCountry:(NSString *)str {
 97  [self setAttributeValue:str
 98        forExtensionClass:[GDataYouTubeCountryAttribute class]];
 99}
100
101@end
102
103// type attribute extension to media credit (v2.0)
104@interface GDataYouTubeTypeAttribute : GDataAttribute <GDataExtension>
105@end
106
107@implementation GDataYouTubeTypeAttribute
108+ (NSString *)extensionElementURI { return kGDataNamespaceYouTube; }
109+ (NSString *)extensionElementPrefix { return kGDataNamespaceYouTubePrefix; }
110+ (NSString *)extensionElementLocalName { return @"type"; }
111@end
112
113@implementation GDataMediaCredit (YouTubeExtensions)
114// media credit with YouTube's addition of a type attribute, 
115// like yt:type="partner"
116- (NSString *)youTubeCreditType {
117  NSString *str = [self attributeValueForExtensionClass:[GDataYouTubeTypeAttribute class]];
118  return str;
119}
120
121- (void)setYouTubeCreditType:(NSString *)str {
122  [self setAttributeValue:str
123        forExtensionClass:[GDataYouTubeTypeAttribute class]];
124}
125@end
126
127@implementation GDataYouTubeMediaGroup
128
129// a media group with YouTube extensions
130
131- (void)addExtensionDeclarations {
132  
133  [super addExtensionDeclarations];
134  
135  [self addExtensionDeclarationForParentClass:[self class]
136                                 childClasses:
137   [GDataYouTubeAspectRatio class],
138   [GDataYouTubeDuration class],
139   [GDataYouTubePrivate class],
140   [GDataYouTubeVideoID class],
141   [GDataYouTubeUploadedDate class],
142   nil];
143  
144  // add the yt:format attribute to GDataMediaContent
145  [self addAttributeExtensionDeclarationForParentClass:[GDataMediaContent class]
146                                            childClass:[GDataYouTubeFormatAttribute class]];
147
148  // add the yt:country attribute to GDataMediaRating
149  [self addAttributeExtensionDeclarationForParentClass:[GDataMediaRating class]
150                                            childClass:[GDataYouTubeCountryAttribute class]];
151
152  // add the yt:type attribute to GDataMediaCredit
153  [self addAttributeExtensionDeclarationForParentClass:[GDataMediaCredit class]
154                                            childClass:[GDataYouTubeTypeAttribute class]];
155
156  // add the yt:name attribute to GDataMediaThumbnail
157  [self addAttributeExtensionDeclarationForParentClass:[GDataMediaThumbnail class]
158                                            childClass:[GDataYouTubeNameAttribute class]];
159}
160
161#if !GDATA_SIMPLE_DESCRIPTIONS
162- (NSMutableArray *)itemsForDescription {
163
164  static struct GDataDescriptionRecord descRecs[] = {
165    { @"duration",    @"duration",     kGDataDescValueLabeled   },
166    { @"videoID",     @"videoID",      kGDataDescValueLabeled   },
167    { @"aspectRatio", @"aspectRatio",  kGDataDescValueLabeled   },
168    { @"uploaded",    @"uploadedDate", kGDataDescValueLabeled   },
169    { @"private",     @"isPrivate",    kGDataDescBooleanPresent },
170    { nil, nil, (GDataDescRecTypes)0 }
171  };
172
173  NSMutableArray *items = [super itemsForDescription];
174  [self addDescriptionRecords:descRecs toItems:items];
175  return items;
176}
177#endif
178
179#pragma mark -
180
181- (NSNumber *)duration {
182  GDataYouTubeDuration *obj = [self objectForExtensionClass:[GDataYouTubeDuration class]];
183  return [obj intNumberValue];
184}
185
186- (void)setDuration:(NSNumber *)num {
187  GDataYouTubeDuration *obj = [GDataYouTubeDuration valueWithNumber:num];
188  [self setObject:obj forExtensionClass:[GDataYouTubeDuration class]];
189}
190
191- (BOOL)isPrivate {
192  GDataYouTubePrivate *obj = [self objectForExtensionClass:[GDataYouTubePrivate class]];
193  return (obj != nil);
194}
195
196- (void)setIsPrivate:(BOOL)flag {
197  if (flag) {
198    GDataYouTubePrivate *private = [GDataYouTubePrivate implicitValue];
199    [self setObject:private forExtensionClass:[GDataYouTubePrivate class]];
200  } else {
201    [self setObject:nil forExtensionClass:[GDataYouTubePrivate class]];
202  }
203}
204
205// videoID available in v2.0
206- (NSString *)videoID {
207  GDataYouTubeVideoID *obj;
208  
209  obj = [self objectForExtensionClass:[GDataYouTubeVideoID class]];
210  return [obj stringValue];
211}
212
213- (void)setVideoID:(NSString *)str {
214  GDataYouTubeVideoID *obj = [GDataYouTubeVideoID valueWithString:str];
215  [self setObject:obj forExtensionClass:[GDataYouTubeVideoID class]];
216}
217
218// uploadedDate available in v2.0
219- (GDataDateTime *)uploadedDate {
220  GDataYouTubeUploadedDate *obj;
221  
222  obj = [self objectForExtensionClass:[GDataYouTubeUploadedDate class]];
223  return [obj dateTimeValue];
224}
225
226- (void)setUploadedDate:(GDataDateTime *)dateTime {
227  GDataYouTubeUploadedDate *obj;
228
229  obj = [GDataYouTubeUploadedDate valueWithDateTime:dateTime];
230  [self setObject:obj forExtensionClass:[GDataYouTubeUploadedDate class]];
231}
232
233// aspectRatio available in v2.0
234- (NSString *)aspectRatio {
235  GDataYouTubeAspectRatio *obj;
236
237  obj = [self objectForExtensionClass:[GDataYouTubeAspectRatio class]];
238  return [obj stringValue];
239}
240
241- (void)setAspectRatio:(NSString *)str {
242  GDataYouTubeAspectRatio *obj = [GDataYouTubeAspectRatio valueWithString:str];
243  [self setObject:obj forExtensionClass:[GDataYouTubeAspectRatio class]];
244}
245
246// convenience accessors
247- (GDataMediaThumbnail *)highQualityThumbnail {
248  // the HQ thumbnail is the one lacking a time attribute
249  NSArray *array = [self mediaThumbnails];
250  GDataMediaThumbnail *obj = [GDataUtilities firstObjectFromArray:array
251                                                        withValue:nil
252                                                       forKeyPath:@"time"];
253  return obj;
254}
255
256- (GDataMediaContent *)mediaContentWithFormatNumber:(NSInteger)formatNumber {
257  NSArray *mediaContents = [self mediaContents];
258
259  NSNumber *formatNum = [NSNumber numberWithInteger:formatNumber];
260
261  GDataMediaContent *content;
262  content = [GDataUtilities firstObjectFromArray:mediaContents
263                                       withValue:formatNum
264                                      forKeyPath:@"youTubeFormatNumber"];
265  return content;
266}
267@end
268
269#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_YOUTUBE_SERVICE