| 1 | /* |
|---|
| 2 | * SapphireMediaPreview.m |
|---|
| 3 | * Sapphire |
|---|
| 4 | * |
|---|
| 5 | * Created by Graham Booker on Jun. 26, 2007. |
|---|
| 6 | * Copyright 2007 Sapphire Development Team and/or www.nanopi.net |
|---|
| 7 | * All rights reserved. |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU |
|---|
| 10 | * General Public License as published by the Free Software Foundation; either version 3 of the License, |
|---|
| 11 | * or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
|---|
| 14 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|---|
| 15 | * Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License along with this program; if not, |
|---|
| 18 | * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #import "SapphireMediaPreview.h" |
|---|
| 22 | #import "SapphireFileMetaData.h" |
|---|
| 23 | #import "SapphireDirectoryMetaData.h" |
|---|
| 24 | #import "SapphireMedia.h" |
|---|
| 25 | #import "SapphireSettings.h" |
|---|
| 26 | #import <objc/objc-class.h> |
|---|
| 27 | #import <SapphireCompatClasses/SapphireFrontRowCompat.h> |
|---|
| 28 | |
|---|
| 29 | NSString *META_EPISODE_AND_SEASON_KEY = @"S/E"; |
|---|
| 30 | NSString *META_MOVIE_IMDB_STATS_KEY = @"IMDB"; |
|---|
| 31 | NSString *AUDIO_DESC_LABEL_KEY = @"Audio"; |
|---|
| 32 | NSString *VIDEO_DESC_LABEL_KEY = @"Video"; |
|---|
| 33 | NSString *AUDIO2_DESC_LABEL_KEY = @"Audio2"; |
|---|
| 34 | NSString *VIDEO2_DESC_LABEL_KEY = @"Video2"; |
|---|
| 35 | NSString *SUBTITLE_LABEL_KEY = @"Subtitles"; |
|---|
| 36 | |
|---|
| 37 | /*These interfaces are to access variables not available*/ |
|---|
| 38 | @interface BRMetadataLayer (protectedAccess) |
|---|
| 39 | - (NSArray *)gimmieMetadataObjs; |
|---|
| 40 | @end |
|---|
| 41 | |
|---|
| 42 | @implementation BRMetadataLayer (protectedAccess) |
|---|
| 43 | - (NSArray *)gimmieMetadataObjs |
|---|
| 44 | { |
|---|
| 45 | Class myClass = [self class]; |
|---|
| 46 | Ivar ret = class_getInstanceVariable(myClass,"_metadataLabels"); |
|---|
| 47 | |
|---|
| 48 | return *(NSArray * *)(((char *)self)+ret->ivar_offset); |
|---|
| 49 | } |
|---|
| 50 | @end |
|---|
| 51 | |
|---|
| 52 | /* There is no BRMetadataLayer class in ATV2.0 anymore, it seems to be BRMetadataControl now*/ |
|---|
| 53 | /* So just do the same stuff as above, but for BRMetadataControl*/ |
|---|
| 54 | @interface BRMetadataControl : NSObject |
|---|
| 55 | @end |
|---|
| 56 | |
|---|
| 57 | @implementation BRMetadataControl (protectedAccess) |
|---|
| 58 | - (NSArray *)gimmieMetadataObjs { |
|---|
| 59 | Class klass = [self class]; |
|---|
| 60 | Ivar ret = class_getInstanceVariable(klass, "_metadataObjs"); |
|---|
| 61 | return *(NSArray * *)(((char *)self)+ret->ivar_offset); |
|---|
| 62 | } |
|---|
| 63 | @end |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | @interface BRMetadataPreviewController (compat) |
|---|
| 67 | - (void)_updateMetadataLayer; |
|---|
| 68 | @end |
|---|
| 69 | |
|---|
| 70 | @interface BRMetadataPreviewController (protectedAccess) |
|---|
| 71 | - (BRMetadataLayer *)gimmieMetadataLayer; |
|---|
| 72 | @end |
|---|
| 73 | |
|---|
| 74 | @implementation BRMetadataPreviewController (protectedAccess) |
|---|
| 75 | - (BRMetadataLayer *)gimmieMetadataLayer |
|---|
| 76 | { |
|---|
| 77 | Class myClass = [self class]; |
|---|
| 78 | Ivar ret = class_getInstanceVariable(myClass,"_metadataLayer"); |
|---|
| 79 | |
|---|
| 80 | return *(BRMetadataLayer * *)(((char *)self)+ret->ivar_offset); |
|---|
| 81 | } |
|---|
| 82 | @end |
|---|
| 83 | |
|---|
| 84 | @interface SapphireMediaPreview () |
|---|
| 85 | - (void)doPopulation; |
|---|
| 86 | - (NSString *)coverArtForPath; |
|---|
| 87 | - (NSString *)keyForDisplay:(NSString *)key; |
|---|
| 88 | @end |
|---|
| 89 | |
|---|
| 90 | @implementation SapphireMediaPreview |
|---|
| 91 | |
|---|
| 92 | /*List of extensions to look for cover art*/ |
|---|
| 93 | static NSSet *coverArtExtentions = nil; |
|---|
| 94 | |
|---|
| 95 | + (void)initialize |
|---|
| 96 | { |
|---|
| 97 | /*Initialize the set of cover art extensions*/ |
|---|
| 98 | coverArtExtentions = [[NSSet alloc] initWithObjects: |
|---|
| 99 | @"jpg", |
|---|
| 100 | @"jpeg", |
|---|
| 101 | @"tif", |
|---|
| 102 | @"tiff", |
|---|
| 103 | @"png", |
|---|
| 104 | @"gif", |
|---|
| 105 | nil]; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | - (id)initWithScene:(BRRenderScene *)scene |
|---|
| 109 | { |
|---|
| 110 | if([[BRMetadataPreviewController class] instancesRespondToSelector:@selector(initWithScene:)]) |
|---|
| 111 | return [super initWithScene:scene]; |
|---|
| 112 | else |
|---|
| 113 | return [super init]; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | - (void)dealloc |
|---|
| 117 | { |
|---|
| 118 | [meta release]; |
|---|
| 119 | [dirMeta release]; |
|---|
| 120 | [super dealloc]; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | - (void)setImageOnly:(BOOL)newImageOnly |
|---|
| 124 | { |
|---|
| 125 | imageOnly = newImageOnly; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | - (void)setUtilityData:(NSMutableDictionary *)newMeta |
|---|
| 129 | { |
|---|
| 130 | [meta release]; |
|---|
| 131 | meta=[newMeta retain]; |
|---|
| 132 | SapphireMedia *asset = [[SapphireMedia alloc] init]; |
|---|
| 133 | [asset setImagePath:[[NSBundle bundleForClass:[self class]] pathForResource:@"DefaultPreview" ofType:@"png"]]; |
|---|
| 134 | [self setAsset:asset]; |
|---|
| 135 | [asset release]; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | - (void)setMetaData:(id <SapphireMetaData>)newMeta inMetaData:(id <SapphireDirectory>)dir |
|---|
| 139 | { |
|---|
| 140 | [meta release]; |
|---|
| 141 | NSString *path = [newMeta path]; |
|---|
| 142 | if(path == nil) |
|---|
| 143 | { |
|---|
| 144 | meta = nil; |
|---|
| 145 | return; |
|---|
| 146 | } |
|---|
| 147 | meta = [newMeta retain]; |
|---|
| 148 | [dirMeta release]; |
|---|
| 149 | dirMeta = [dir retain]; |
|---|
| 150 | /*Now that we know the file, set the asset*/ |
|---|
| 151 | NSURL *url = [NSURL fileURLWithPath:[meta path]]; |
|---|
| 152 | SapphireMedia *asset =[[SapphireMedia alloc] initWithMediaURL:url]; |
|---|
| 153 | [asset setImagePath:[self coverArtForPath]]; |
|---|
| 154 | [self setAsset:asset]; |
|---|
| 155 | [asset release]; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | /*! |
|---|
| 159 | * @brief Search for cover art for the current metadata |
|---|
| 160 | * |
|---|
| 161 | * @return The path to the found cover art |
|---|
| 162 | */ |
|---|
| 163 | - (NSString *)coverArtForPath |
|---|
| 164 | { |
|---|
| 165 | /*See if this is a directory*/ |
|---|
| 166 | if([meta conformsToProtocol:@protocol(SapphireDirectory)]) |
|---|
| 167 | { |
|---|
| 168 | NSString *ret = [(id <SapphireDirectory>)meta coverArtPath]; |
|---|
| 169 | if(ret != nil) |
|---|
| 170 | return ret; |
|---|
| 171 | } else { |
|---|
| 172 | NSString *ret = [(SapphireFileMetaData *)meta coverArtPath]; |
|---|
| 173 | if(ret != nil) |
|---|
| 174 | return ret; |
|---|
| 175 | else if ((ret = [dirMeta coverArtPath]) != nil) |
|---|
| 176 | return ret; |
|---|
| 177 | } |
|---|
| 178 | /*Fallback to default*/ |
|---|
| 179 | return [[NSBundle bundleForClass:[self class]] pathForResource:@"DefaultPreview" ofType:@"png"]; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | /*! |
|---|
| 183 | * @brief Override the loading of the cover art method |
|---|
| 184 | */ |
|---|
| 185 | - (void)_loadCoverArt |
|---|
| 186 | { |
|---|
| 187 | [super _loadCoverArt]; |
|---|
| 188 | |
|---|
| 189 | /*See if it loaded something*/ |
|---|
| 190 | if([_coverArtLayer texture] != nil) |
|---|
| 191 | return; |
|---|
| 192 | |
|---|
| 193 | /*Get our cover art*/ |
|---|
| 194 | NSString *path = [self coverArtForPath]; |
|---|
| 195 | NSURL *url = [NSURL fileURLWithPath:path]; |
|---|
| 196 | /*Create an image source*/; |
|---|
| 197 | CGImageSourceRef sourceRef; |
|---|
| 198 | CGImageRef imageRef = NULL; |
|---|
| 199 | sourceRef = CGImageSourceCreateWithURL((CFURLRef)url, NULL); |
|---|
| 200 | if(sourceRef) { |
|---|
| 201 | imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, NULL); |
|---|
| 202 | CFRelease(sourceRef); |
|---|
| 203 | } |
|---|
| 204 | if(imageRef) |
|---|
| 205 | { |
|---|
| 206 | [_coverArtLayer setImage:imageRef]; |
|---|
| 207 | CFRelease(imageRef); |
|---|
| 208 | } |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | /*! |
|---|
| 212 | * @brief populate metadata for TV Shows |
|---|
| 213 | */ |
|---|
| 214 | - (void) populateTVShowMetadataWith:(NSMutableDictionary*)allMeta |
|---|
| 215 | { |
|---|
| 216 | NSString *value = [allMeta objectForKey:META_TITLE_KEY]; |
|---|
| 217 | BRMetadataLayer *metaLayer = [self gimmieMetadataLayer]; |
|---|
| 218 | if(value != nil) |
|---|
| 219 | { |
|---|
| 220 | /*If there is an air date, put it in the title*/ |
|---|
| 221 | NSDate *airDate = [allMeta objectForKey:META_SHOW_AIR_DATE]; |
|---|
| 222 | if(airDate != nil) |
|---|
| 223 | { |
|---|
| 224 | NSDateFormatter *format = [[NSDateFormatter alloc] init]; |
|---|
| 225 | [format setDateStyle:NSDateFormatterShortStyle]; |
|---|
| 226 | [format setTimeZone:NSDateFormatterNoStyle]; |
|---|
| 227 | value = [[format stringFromDate:airDate]stringByAppendingFormat:@" - %@", value]; |
|---|
| 228 | [format release]; |
|---|
| 229 | } |
|---|
| 230 | [metaLayer setTitle:value]; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | SapphireSettings *settings = [SapphireSettings sharedSettings]; |
|---|
| 234 | BOOL displayOnlyPlot = [settings displayOnlyPlot]; |
|---|
| 235 | /*Get the rating*/ |
|---|
| 236 | value = [allMeta objectForKey:META_RATING_KEY]; |
|---|
| 237 | if(value != nil && !displayOnlyPlot) |
|---|
| 238 | [metaLayer setRating:value]; |
|---|
| 239 | |
|---|
| 240 | /*Get the description*/ |
|---|
| 241 | value = [allMeta objectForKey:META_DESCRIPTION_KEY]; |
|---|
| 242 | if(value != nil) |
|---|
| 243 | if([settings displaySpoilers] || displayOnlyPlot) |
|---|
| 244 | [metaLayer setSummary:value]; |
|---|
| 245 | |
|---|
| 246 | /*Get the copyright*/ |
|---|
| 247 | value = [allMeta objectForKey:META_COPYRIGHT_KEY]; |
|---|
| 248 | if(value != nil && !displayOnlyPlot) |
|---|
| 249 | [metaLayer setCopyright:value]; |
|---|
| 250 | |
|---|
| 251 | /*Get the season and episodes*/ |
|---|
| 252 | value = [allMeta objectForKey:META_EPISODE_AND_SEASON_KEY]; |
|---|
| 253 | if(value != nil) |
|---|
| 254 | { |
|---|
| 255 | /*Remove the individuals so we don't display them*/ |
|---|
| 256 | [allMeta removeObjectForKey:META_EPISODE_NUMBER_KEY]; |
|---|
| 257 | [allMeta removeObjectForKey:META_EPISODE_2_NUMBER_KEY]; |
|---|
| 258 | [allMeta removeObjectForKey:META_SEASON_NUMBER_KEY]; |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | /*! |
|---|
| 263 | * @brief populate metadata for Movies |
|---|
| 264 | */ |
|---|
| 265 | - (void) populateMovieMetadataWith:(NSMutableDictionary*)allMeta |
|---|
| 266 | { |
|---|
| 267 | /* Get the movie title */ |
|---|
| 268 | NSString *value=nil; |
|---|
| 269 | value = [allMeta objectForKey:META_MOVIE_TITLE_KEY]; |
|---|
| 270 | BRMetadataLayer *metaLayer = [self gimmieMetadataLayer]; |
|---|
| 271 | |
|---|
| 272 | /*Get the release date*/ |
|---|
| 273 | NSDate *releaseDate = [allMeta objectForKey:META_MOVIE_RELEASE_DATE_KEY]; |
|---|
| 274 | if(releaseDate != nil) |
|---|
| 275 | { |
|---|
| 276 | NSDateFormatter *format = [[NSDateFormatter alloc] init]; |
|---|
| 277 | [format setDateStyle:NSDateFormatterLongStyle]; |
|---|
| 278 | [format setTimeZone:NSDateFormatterNoStyle]; |
|---|
| 279 | value = [NSString stringWithFormat:@"Premiered: %@",[format stringFromDate:releaseDate]]; |
|---|
| 280 | [format release]; |
|---|
| 281 | [allMeta removeObjectForKey:META_MOVIE_RELEASE_DATE_KEY]; |
|---|
| 282 | [allMeta removeObjectForKey:META_MOVIE_TITLE_KEY]; |
|---|
| 283 | } |
|---|
| 284 | SapphireSettings *settings = [SapphireSettings sharedSettings]; |
|---|
| 285 | BOOL displayOnlyPlot = [settings displayOnlyPlot]; |
|---|
| 286 | /* No release date, sub in the movie title */ |
|---|
| 287 | [metaLayer setTitle:value]; |
|---|
| 288 | |
|---|
| 289 | /*Get the rating*/ |
|---|
| 290 | value=nil; |
|---|
| 291 | value = [allMeta objectForKey:META_MOVIE_MPAA_RATING_KEY]; |
|---|
| 292 | if(value != nil && !displayOnlyPlot) |
|---|
| 293 | [metaLayer setRating:value]; |
|---|
| 294 | /*Get the movie plot*/ |
|---|
| 295 | value=nil; |
|---|
| 296 | value = [allMeta objectForKey:META_MOVIE_PLOT_KEY]; |
|---|
| 297 | if(value != nil) |
|---|
| 298 | if([settings displaySpoilers] || displayOnlyPlot) |
|---|
| 299 | [metaLayer setSummary:value]; |
|---|
| 300 | |
|---|
| 301 | NSArray *values=nil; |
|---|
| 302 | /* Get genres */ |
|---|
| 303 | values=[allMeta objectForKey:META_MOVIE_GENRES_KEY]; |
|---|
| 304 | if(values!=nil) |
|---|
| 305 | { |
|---|
| 306 | value = [(NSArray *)values componentsJoinedByString:@", "]; |
|---|
| 307 | /* sub the array for a formatted string */ |
|---|
| 308 | [allMeta setObject:value forKey:META_MOVIE_GENRES_KEY]; |
|---|
| 309 | } |
|---|
| 310 | /* Get directors */ |
|---|
| 311 | values=nil; |
|---|
| 312 | values=[allMeta objectForKey:META_MOVIE_DIRECTOR_KEY]; |
|---|
| 313 | if(values!=nil) |
|---|
| 314 | { |
|---|
| 315 | value = [(NSArray *)values componentsJoinedByString:@", "]; |
|---|
| 316 | /* sub the array for a formatted string */ |
|---|
| 317 | [allMeta setObject:value forKey:META_MOVIE_DIRECTOR_KEY]; |
|---|
| 318 | } |
|---|
| 319 | /* Get cast */ |
|---|
| 320 | values=nil; |
|---|
| 321 | values=[allMeta objectForKey:META_MOVIE_CAST_KEY]; |
|---|
| 322 | if(values!=nil) |
|---|
| 323 | { |
|---|
| 324 | NSArray *subCast = (NSArray *)values; |
|---|
| 325 | if([subCast count] > 3) |
|---|
| 326 | subCast = [(NSArray *)values subarrayWithRange:NSMakeRange(0, 3)]; |
|---|
| 327 | value = [subCast componentsJoinedByString:@", "]; |
|---|
| 328 | [allMeta setObject:value forKey:META_MOVIE_CAST_KEY]; |
|---|
| 329 | } |
|---|
| 330 | /* Get IMDB Stats */ |
|---|
| 331 | value=nil ; |
|---|
| 332 | value=[allMeta objectForKey:META_MOVIE_IMDB_RATING_KEY]; |
|---|
| 333 | if(value!=nil) |
|---|
| 334 | { |
|---|
| 335 | value=[NSString stringWithFormat:@"%1.1f/10",[value floatValue]]; |
|---|
| 336 | NSString *top250=nil; |
|---|
| 337 | top250=[allMeta objectForKey:META_MOVIE_IMDB_250_KEY]; |
|---|
| 338 | if(top250!=nil) |
|---|
| 339 | value=[NSString stringWithFormat:@"#%@ on Top 250 (%@)",top250,value]; |
|---|
| 340 | else |
|---|
| 341 | value=[NSString stringWithFormat:@"User Rated %@",value]; |
|---|
| 342 | [allMeta removeObjectForKey:META_MOVIE_IMDB_RATING_KEY]; |
|---|
| 343 | [allMeta removeObjectForKey:META_MOVIE_IMDB_250_KEY]; |
|---|
| 344 | [allMeta setObject:value forKey:META_MOVIE_IMDB_STATS_KEY]; |
|---|
| 345 | } |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | /*! |
|---|
| 349 | * @brief populate utility data |
|---|
| 350 | */ |
|---|
| 351 | - (void)populateUtilityDataWith:(NSMutableDictionary *)allMeta |
|---|
| 352 | { |
|---|
| 353 | BRMetadataLayer *metaLayer = [self gimmieMetadataLayer]; |
|---|
| 354 | /* Get the setting name */ |
|---|
| 355 | NSString *value = [allMeta objectForKey:META_TITLE_KEY]; |
|---|
| 356 | if(value != nil) |
|---|
| 357 | [metaLayer setTitle:value]; |
|---|
| 358 | /*Get the setting description*/ |
|---|
| 359 | value = [allMeta objectForKey:META_DESCRIPTION_KEY]; |
|---|
| 360 | if(value != nil) |
|---|
| 361 | [metaLayer setSummary:value]; |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | /*! |
|---|
| 365 | * @brief populate generic file data |
|---|
| 366 | */ |
|---|
| 367 | - (void)populateGenericMetadataWith:(NSMutableDictionary *)allMeta |
|---|
| 368 | { |
|---|
| 369 | NSString *value = [allMeta objectForKey:META_TITLE_KEY]; |
|---|
| 370 | BRMetadataLayer *metaLayer = [self gimmieMetadataLayer]; |
|---|
| 371 | if(value != nil) |
|---|
| 372 | [metaLayer setTitle:value]; |
|---|
| 373 | |
|---|
| 374 | /*Get the rating*/ |
|---|
| 375 | value = [allMeta objectForKey:META_RATING_KEY]; |
|---|
| 376 | if(value != nil) |
|---|
| 377 | [metaLayer setRating:value]; |
|---|
| 378 | |
|---|
| 379 | /*Get the description*/ |
|---|
| 380 | value = [allMeta objectForKey:META_DESCRIPTION_KEY]; |
|---|
| 381 | if(value != nil) |
|---|
| 382 | if([[SapphireSettings sharedSettings] displaySpoilers]) |
|---|
| 383 | [metaLayer setSummary:value]; |
|---|
| 384 | |
|---|
| 385 | /*Get the copyright*/ |
|---|
| 386 | value = [allMeta objectForKey:META_COPYRIGHT_KEY]; |
|---|
| 387 | if(value != nil) |
|---|
| 388 | [metaLayer setCopyright:value]; |
|---|
| 389 | |
|---|
| 390 | /*Get the rating*/ |
|---|
| 391 | value=nil; |
|---|
| 392 | value = [allMeta objectForKey:META_MOVIE_MPAA_RATING_KEY]; |
|---|
| 393 | if(value != nil) |
|---|
| 394 | [metaLayer setRating:value]; |
|---|
| 395 | /*Get the movie plot*/ |
|---|
| 396 | value=nil; |
|---|
| 397 | value = [allMeta objectForKey:META_MOVIE_PLOT_KEY]; |
|---|
| 398 | if(value != nil) |
|---|
| 399 | if([[SapphireSettings sharedSettings] displaySpoilers]) |
|---|
| 400 | [metaLayer setSummary:value]; |
|---|
| 401 | |
|---|
| 402 | NSArray *values=nil; |
|---|
| 403 | /* Get genres */ |
|---|
| 404 | values=[allMeta objectForKey:META_MOVIE_GENRES_KEY]; |
|---|
| 405 | value=[NSString string]; |
|---|
| 406 | if(values!=nil) |
|---|
| 407 | { |
|---|
| 408 | NSEnumerator *valuesEnum = [values objectEnumerator] ; |
|---|
| 409 | NSString *aValue=nil; |
|---|
| 410 | while((aValue = [valuesEnum nextObject]) !=nil) |
|---|
| 411 | { |
|---|
| 412 | value=[value stringByAppendingString:[NSString stringWithFormat:@"%@, ",aValue]]; |
|---|
| 413 | } |
|---|
| 414 | /* get rid of the extra comma */ |
|---|
| 415 | value=[value substringToIndex:[value length]-2]; |
|---|
| 416 | /* sub the array for a formatted string */ |
|---|
| 417 | [allMeta setObject:value forKey:META_MOVIE_GENRES_KEY]; |
|---|
| 418 | } |
|---|
| 419 | /* Get directors */ |
|---|
| 420 | values=nil; |
|---|
| 421 | values=[allMeta objectForKey:META_MOVIE_DIRECTOR_KEY]; |
|---|
| 422 | value=[NSString string]; |
|---|
| 423 | if(values!=nil) |
|---|
| 424 | { |
|---|
| 425 | NSEnumerator *valuesEnum = [values objectEnumerator] ; |
|---|
| 426 | NSString *aValue=nil; |
|---|
| 427 | while((aValue = [valuesEnum nextObject]) !=nil) |
|---|
| 428 | { |
|---|
| 429 | value=[value stringByAppendingString:[NSString stringWithFormat:@"%@, ",aValue]]; |
|---|
| 430 | } |
|---|
| 431 | /* get rid of the extra comma */ |
|---|
| 432 | value=[value substringToIndex:[value length]-2]; |
|---|
| 433 | /* sub the array for a formatted string */ |
|---|
| 434 | [allMeta setObject:value forKey:META_MOVIE_DIRECTOR_KEY]; |
|---|
| 435 | } |
|---|
| 436 | /* Get cast */ |
|---|
| 437 | values=nil; |
|---|
| 438 | values=[allMeta objectForKey:META_MOVIE_CAST_KEY]; |
|---|
| 439 | value=[NSString string]; |
|---|
| 440 | if(values!=nil) |
|---|
| 441 | { |
|---|
| 442 | NSEnumerator *valuesEnum = [values objectEnumerator] ; |
|---|
| 443 | NSString *aValue=nil; |
|---|
| 444 | NSString *lastToAdd = nil; |
|---|
| 445 | if([values count]>2) |
|---|
| 446 | lastToAdd=[values objectAtIndex:2] ; |
|---|
| 447 | while((aValue = [valuesEnum nextObject]) !=nil) |
|---|
| 448 | { |
|---|
| 449 | value=[value stringByAppendingString:[NSString stringWithFormat:@"%@, ",aValue]]; |
|---|
| 450 | if([aValue isEqualToString:lastToAdd])break; |
|---|
| 451 | } |
|---|
| 452 | /* get rid of the extra comma */ |
|---|
| 453 | value=[value substringToIndex:[value length]-2]; |
|---|
| 454 | /* sub the array for a formatted string */ |
|---|
| 455 | [allMeta setObject:value forKey:META_MOVIE_CAST_KEY]; |
|---|
| 456 | } |
|---|
| 457 | } |
|---|
| 458 | |
|---|
| 459 | /*! |
|---|
| 460 | * @brief populate metadata for media files |
|---|
| 461 | */ |
|---|
| 462 | - (void)_populateMetadata |
|---|
| 463 | { |
|---|
| 464 | [super _populateMetadata]; |
|---|
| 465 | [self doPopulation]; |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | /*! |
|---|
| 469 | * @brief populate metadata for media files |
|---|
| 470 | */ |
|---|
| 471 | - (void)_updateMetadataLayer |
|---|
| 472 | { |
|---|
| 473 | [super _updateMetadataLayer]; |
|---|
| 474 | /*See if it loaded anything*/ |
|---|
| 475 | if(![SapphireFrontRowCompat usingLeopardOrATypeOfTakeTwo]) |
|---|
| 476 | return; |
|---|
| 477 | |
|---|
| 478 | [self doPopulation]; |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | - (NSString *)keyForDisplay:(NSString *)key |
|---|
| 482 | { |
|---|
| 483 | static NSDictionary *keyTranslations = nil; |
|---|
| 484 | if(keyTranslations == nil) |
|---|
| 485 | { |
|---|
| 486 | keyTranslations = [[NSDictionary alloc] initWithObjectsAndKeys: |
|---|
| 487 | //File Info |
|---|
| 488 | BRLocalizedString( @"Audio", @"First audio track details" ), AUDIO_DESC_LABEL_KEY, |
|---|
| 489 | BRLocalizedString( @"Audio2", @"Second audio track details" ), AUDIO2_DESC_LABEL_KEY, |
|---|
| 490 | BRLocalizedString( @"Duration", @"Track duration" ), META_FILE_DURATION_KEY, |
|---|
| 491 | BRLocalizedString( @"Size", @"Track size" ), META_FILE_SIZE_KEY, |
|---|
| 492 | BRLocalizedString( @"Subtitles", @"Track subtitles" ), SUBTITLE_LABEL_KEY, |
|---|
| 493 | BRLocalizedString( @"Video", @"First video track details" ), VIDEO_DESC_LABEL_KEY, |
|---|
| 494 | BRLocalizedString( @"Video2", @"Second video track details" ), VIDEO2_DESC_LABEL_KEY, |
|---|
| 495 | //Movie Info |
|---|
| 496 | BRLocalizedString( @"Cast", @"Movie cast" ), META_MOVIE_CAST_KEY, |
|---|
| 497 | BRLocalizedString( @"Director", @"Director" ), META_MOVIE_DIRECTOR_KEY, |
|---|
| 498 | BRLocalizedString( @"Genres", @"Movie genres" ), META_MOVIE_GENRES_KEY, |
|---|
| 499 | BRLocalizedString( @"IMDB", @"IMDb rating" ), META_MOVIE_IMDB_STATS_KEY, |
|---|
| 500 | nil]; |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | NSString *translation = [keyTranslations objectForKey:key]; |
|---|
| 504 | if(translation) |
|---|
| 505 | return translation; |
|---|
| 506 | |
|---|
| 507 | //Nothing found, return the original |
|---|
| 508 | return key; |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | - (void)doPopulation |
|---|
| 512 | { |
|---|
| 513 | /*Get our data then*/ |
|---|
| 514 | NSArray *order = nil; |
|---|
| 515 | NSMutableDictionary *allMeta = nil; |
|---|
| 516 | FileClass fileClass=FILE_CLASS_UNKNOWN ; |
|---|
| 517 | if([meta respondsToSelector:@selector(getDisplayedMetaDataInOrder:)]) |
|---|
| 518 | { |
|---|
| 519 | allMeta=[(id)meta getDisplayedMetaDataInOrder:&order]; |
|---|
| 520 | if([meta conformsToProtocol:@protocol(SapphireDirectory)]) |
|---|
| 521 | fileClass=FILE_CLASS_NOT_FILE; |
|---|
| 522 | else |
|---|
| 523 | fileClass=(FileClass)[(SapphireFileMetaData *) meta fileClassValue]; |
|---|
| 524 | } |
|---|
| 525 | if(!allMeta) |
|---|
| 526 | fileClass=FILE_CLASS_UTILITY; |
|---|
| 527 | if(imageOnly) |
|---|
| 528 | { |
|---|
| 529 | fileClass = FILE_CLASS_NOT_FILE; |
|---|
| 530 | [allMeta removeAllObjects]; |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | BRMetadataLayer *metaLayer = [self gimmieMetadataLayer]; |
|---|
| 534 | /* TV Show Preview Handeling */ |
|---|
| 535 | if(fileClass==FILE_CLASS_TV_SHOW) |
|---|
| 536 | { |
|---|
| 537 | [self populateTVShowMetadataWith:allMeta]; |
|---|
| 538 | } |
|---|
| 539 | /* Movie Preview Handeling */ |
|---|
| 540 | else if(fileClass==FILE_CLASS_MOVIE) |
|---|
| 541 | { |
|---|
| 542 | [self populateMovieMetadataWith:allMeta]; |
|---|
| 543 | } |
|---|
| 544 | /* Utility Preview Handeling */ |
|---|
| 545 | else if(fileClass == FILE_CLASS_UTILITY) |
|---|
| 546 | { |
|---|
| 547 | [self populateUtilityDataWith:(NSMutableDictionary *)meta]; |
|---|
| 548 | } |
|---|
| 549 | else if(fileClass != FILE_CLASS_NOT_FILE) |
|---|
| 550 | { |
|---|
| 551 | [self populateGenericMetadataWith:allMeta]; |
|---|
| 552 | } |
|---|
| 553 | /* Directory Preview Handeling */ |
|---|
| 554 | else |
|---|
| 555 | { |
|---|
| 556 | NSString *value = [allMeta objectForKey:META_TITLE_KEY]; |
|---|
| 557 | if(value != nil) |
|---|
| 558 | [metaLayer setTitle:value]; |
|---|
| 559 | } |
|---|
| 560 | |
|---|
| 561 | SapphireSettings *settings = [SapphireSettings sharedSettings]; |
|---|
| 562 | BOOL displayOnlyPlot = [settings displayOnlyPlot]; |
|---|
| 563 | /* Show / Hide perian info */ |
|---|
| 564 | if(![settings displayAudio] || displayOnlyPlot) |
|---|
| 565 | { |
|---|
| 566 | [allMeta removeObjectForKey:AUDIO_DESC_LABEL_KEY]; |
|---|
| 567 | [allMeta removeObjectForKey:AUDIO2_DESC_LABEL_KEY]; |
|---|
| 568 | [allMeta removeObjectForKey:SUBTITLE_LABEL_KEY]; |
|---|
| 569 | } |
|---|
| 570 | if(![settings displayVideo] || displayOnlyPlot) |
|---|
| 571 | { |
|---|
| 572 | [allMeta removeObjectForKey:VIDEO_DESC_LABEL_KEY]; |
|---|
| 573 | [allMeta removeObjectForKey:VIDEO2_DESC_LABEL_KEY]; |
|---|
| 574 | } |
|---|
| 575 | if(displayOnlyPlot) |
|---|
| 576 | { |
|---|
| 577 | [allMeta removeObjectForKey:META_FILE_SUBTITLES_KEY]; |
|---|
| 578 | [allMeta removeObjectForKey:META_FILE_SIZE_KEY]; |
|---|
| 579 | [allMeta removeObjectForKey:META_FILE_DURATION_KEY]; |
|---|
| 580 | |
|---|
| 581 | //TV |
|---|
| 582 | [allMeta removeObjectForKey:META_SHOW_AIR_DATE]; |
|---|
| 583 | [allMeta removeObjectForKey:BRLocalizedString(@"Season", @"Season in metadata display")]; |
|---|
| 584 | [allMeta removeObjectForKey:BRLocalizedString(@"Episode", @"Episode in metadata display")]; |
|---|
| 585 | [allMeta removeObjectForKey:BRLocalizedString(@"S/E", @"Season / Episode in metadata display")]; |
|---|
| 586 | |
|---|
| 587 | //Movie |
|---|
| 588 | [allMeta removeObjectForKey:META_MOVIE_MPAA_RATING_KEY]; |
|---|
| 589 | [allMeta removeObjectForKey:META_MOVIE_IMDB_RATING_KEY]; |
|---|
| 590 | [allMeta removeObjectForKey:META_MOVIE_RELEASE_DATE_KEY]; |
|---|
| 591 | [allMeta removeObjectForKey:META_MOVIE_IMDB_250_KEY]; |
|---|
| 592 | [allMeta removeObjectForKey:META_MOVIE_OSCAR_KEY]; |
|---|
| 593 | [allMeta removeObjectForKey:META_MOVIE_DIRECTOR_KEY]; |
|---|
| 594 | [allMeta removeObjectForKey:META_MOVIE_CAST_KEY]; |
|---|
| 595 | [allMeta removeObjectForKey:META_MOVIE_GENRES_KEY]; |
|---|
| 596 | [allMeta removeObjectForKey:META_MOVIE_IMDB_STATS_KEY]; |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | NSMutableArray *values = [NSMutableArray array]; |
|---|
| 600 | NSMutableArray *keys = [NSMutableArray array]; |
|---|
| 601 | |
|---|
| 602 | /*Put the metadata in order*/ |
|---|
| 603 | NSEnumerator *keyEnum = [order objectEnumerator]; |
|---|
| 604 | NSString *key = nil; |
|---|
| 605 | while((key = [keyEnum nextObject]) != nil) |
|---|
| 606 | { |
|---|
| 607 | NSString *value = [allMeta objectForKey:key]; |
|---|
| 608 | if(value != nil) |
|---|
| 609 | { |
|---|
| 610 | [values addObject:value]; |
|---|
| 611 | [keys addObject:[self keyForDisplay:key]]; |
|---|
| 612 | } |
|---|
| 613 | } |
|---|
| 614 | |
|---|
| 615 | /*And set it*/ |
|---|
| 616 | [metaLayer setMetadata:values withLabels:keys]; |
|---|
| 617 | } |
|---|
| 618 | |
|---|
| 619 | /*! |
|---|
| 620 | * @brief Override the info about whether it has metadata |
|---|
| 621 | * |
|---|
| 622 | * @return We always have metadata |
|---|
| 623 | */ |
|---|
| 624 | - (BOOL)_assetHasMetadata |
|---|
| 625 | { |
|---|
| 626 | return YES; |
|---|
| 627 | } |
|---|
| 628 | |
|---|
| 629 | @end |
|---|