Changeset 226
- Timestamp:
- 09/18/07 23:35:28 (1 year ago)
- Files:
-
- trunk/SapphireBrowser.m (modified) (3 diffs)
- trunk/SapphireMediaPreview.m (modified) (2 diffs)
- trunk/SapphireMetaData.h (modified) (3 diffs)
- trunk/SapphireMetaData.m (modified) (4 diffs)
- trunk/SapphireMovieImporter.m (modified) (8 diffs)
- trunk/SapphireTVShowImporter.m (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/SapphireBrowser.m
r214 r226 409 409 */ 410 410 NSString * displayName=nil ; 411 int fileCls=0 ; 411 412 /*Check for no items*/ 412 413 int nameCount = [_names count]; … … 445 446 if(meta != nil) 446 447 { 447 /*Display episode number if availble*/ 448 int eps= [meta episodeNumber] ; 449 displayName=[meta episodeTitle] ; 450 if(eps>0) 451 [[result textItem] setRightJustifiedText:[NSString stringWithFormat:@" %02d",eps]]; 452 else 453 /*Fallback to size*/ 454 [[result textItem] setRightJustifiedText:[meta sizeString]]; 448 fileCls=[meta fileClass] ; 449 if(fileCls==FILE_CLASS_TV_SHOW) 450 { 451 /*Display episode number if availble*/ 452 int eps= [meta episodeNumber] ; 453 displayName=[meta episodeTitle] ; 454 if(eps>0) 455 [[result textItem] setRightJustifiedText:[NSString stringWithFormat:@" %02d",eps]]; 456 else 457 /*Fallback to size*/ 458 [[result textItem] setRightJustifiedText:[meta sizeString]]; 459 } 460 if(fileCls==FILE_CLASS_MOVIE) 461 { 462 int duration = [meta duration]; 463 int secs = duration % 60; 464 int mins = (duration /60) % 60; 465 int hours = duration / 3600; 466 NSString *durationStr = nil; 467 if(hours != 0) 468 durationStr = [NSString stringWithFormat:@"%d:%02d:%02d", hours, mins, secs]; 469 else if (mins != 0) 470 durationStr = [NSString stringWithFormat:@"%d:%02d", mins, secs]; 471 else 472 durationStr = [NSString stringWithFormat:@"%ds", secs]; 473 displayName=[meta movieTitle] ; 474 [[result textItem] setRightJustifiedText:[NSString stringWithFormat:@" %@",durationStr]]; 475 } 455 476 watched = [meta watched]; 456 477 favorite = [meta favorite] ; … … 468 489 else if(!watched) [result setLeftIcon:[theme gem:BLUE_GEM_KEY]]; 469 490 else if(favorite)[result setLeftIcon:[theme gem:YELLOW_GEM_KEY]]; 491 else if(fileCls==FILE_CLASS_AUDIO)[result setLeftIcon:[theme gem:GREEN_GEM_KEY]]; 470 492 else [result setLeftIcon:[theme gem:RED_GEM_KEY]]; 471 493 trunk/SapphireMediaPreview.m
r204 r226 183 183 } 184 184 185 /*! 186 * @brief Override the populating of metadata 185 186 187 /*! 188 * @brief populate metadata for TV Shows 187 189 */ 188 190 - (void)_populateMetadata … … 197 199 NSMutableDictionary *allMeta = [meta getDisplayedMetaDataInOrder:&order]; 198 200 /*Pull out the special ones*/ 199 /*Get the title*/ 200 NSString *value = [allMeta objectForKey:META_TITLE_KEY]; 201 if(value != nil) 202 { 203 /*If there is an air date, put it in the title*/ 204 NSDate *airDate = [allMeta objectForKey:META_SHOW_AIR_DATE]; 205 if(airDate != nil) 201 202 203 // int fileCls = nil ; 204 // fileCls =[allMeta objectForKey:FILE_CLASS_KEY]; 205 /* 206 // Movie Preview Handeling 207 if(fileCls==FILE_CLASS_MOVIE) 208 { 209 NSString *value = [allMeta objectForKey:META_TITLE_KEY]; 210 [_metadataLayer setTitle:value]; 211 212 } 213 */ 214 215 /* TV Show Preview Handeling */ 216 // if(fileCls==FILE_CLASS_TV_SHOW) 217 // { 218 /*Get the title*/ 219 NSString *value = [allMeta objectForKey:META_TITLE_KEY]; 220 if(value != nil) 206 221 { 207 NSDateFormatter *format = [[NSDateFormatter alloc] init]; 208 [format setDateStyle:NSDateFormatterShortStyle]; 209 [format setTimeZone:NSDateFormatterNoStyle]; 210 value = [[format stringFromDate:airDate]stringByAppendingFormat:@" - %@", value]; 222 /*If there is an air date, put it in the title*/ 223 NSDate *airDate = [allMeta objectForKey:META_SHOW_AIR_DATE]; 224 if(airDate != nil) 225 { 226 NSDateFormatter *format = [[NSDateFormatter alloc] init]; 227 [format setDateStyle:NSDateFormatterShortStyle]; 228 [format setTimeZone:NSDateFormatterNoStyle]; 229 value = [[format stringFromDate:airDate]stringByAppendingFormat:@" - %@", value]; 230 } 231 [_metadataLayer setTitle:value]; 211 232 } 212 [_metadataLayer setTitle:value]; 213 }214 215 /*Get the rating*/216 value = [allMeta objectForKey:META_RATING_KEY];217 if(value != nil) 218 [_metadataLayer setRating:value];219 220 /*Get the description*/221 value = [allMeta objectForKey:META_DESCRIPTION_KEY];222 if(value != nil)223 if([[SapphireSettings sharedSettings] displaySpoilers]) 224 [_metadataLayer setSummary:value];225 226 /*Get the copyright*/227 value = [allMeta objectForKey:META_COPYRIGHT_KEY];228 if(value != nil)229 [_metadataLayer setCopyright:value];230 231 /*Get the season and epsiodes*/232 value = [allMeta objectForKey:META_EPISODE_AND_SEASON_KEY];233 if(value != nil)234 {235 /*Remove the individuals so we don't display them*/236 [allMeta removeObjectForKey:META_EPISODE_NUMBER_KEY];237 [allMeta removeObjectForKey:META_SEASON_NUMBER_KEY]; 238 }233 234 /*Get the rating*/ 235 value = [allMeta objectForKey:META_RATING_KEY]; 236 if(value != nil) 237 [_metadataLayer setRating:value]; 238 239 /*Get the description*/ 240 value = [allMeta objectForKey:META_DESCRIPTION_KEY]; 241 if(value != nil) 242 if([[SapphireSettings sharedSettings] displaySpoilers]) 243 [_metadataLayer setSummary:value]; 244 245 /*Get the copyright*/ 246 value = [allMeta objectForKey:META_COPYRIGHT_KEY]; 247 if(value != nil) 248 [_metadataLayer setCopyright:value]; 249 250 /*Get the season and epsiodes*/ 251 value = [allMeta objectForKey:META_EPISODE_AND_SEASON_KEY]; 252 if(value != nil) 253 { 254 /*Remove the individuals so we don't display them*/ 255 [allMeta removeObjectForKey:META_EPISODE_NUMBER_KEY]; 256 [allMeta removeObjectForKey:META_SEASON_NUMBER_KEY]; 257 } 258 // } 259 239 260 240 261 NSMutableArray *values = [NSMutableArray array]; trunk/SapphireMetaData.h
r222 r226 35 35 36 36 //IMDB Type Info 37 #define META_MOVIE_TITLE @"Title" 37 #define META_MOVIE_TITLE_KEY @"Title" 38 #define META_MOVIE_RELEASE_DATE @"Released" 38 39 39 40 //Special Display Only Info … … 46 47 #define META_DATA_FILE_INFO_KIND @"MetaDataFileInfoKind" 47 48 49 #define FILE_CLASS_KEY @"File Class" 48 50 typedef enum { 49 51 FILE_CLASS_UNKNOWN = 0, … … 181 183 - (int)seasonNumber; 182 184 - (NSString *)episodeTitle; 185 - (NSString *)movieTitle; 183 186 - (NSString *)showID; 184 187 - (NSString *)showName ; trunk/SapphireMetaData.m
r223 r226 36 36 #define VIDEO_DESC_KEY @"Video Description" 37 37 #define AUDIO_FORMAT_KEY @"Audio Format" 38 #define FILE_CLASS_KEY @"File Class"38 //#define FILE_CLASS_KEY @"File Class" 39 39 40 40 @implementation NSString (episodeSorting) … … 1376 1376 META_COPYRIGHT_KEY, 1377 1377 META_TITLE_KEY, 1378 META_MOVIE_TITLE_KEY, 1378 1379 META_SHOW_AIR_DATE, 1379 1380 //These are displayed as line items … … 1722 1723 NSMutableDictionary *ret = [metaData mutableCopy]; 1723 1724 [ret addEntriesFromDictionary:[ret objectForKey:META_TVRAGE_IMPORT_KEY]]; 1725 [ret addEntriesFromDictionary:[ret objectForKey:META_IMDB_IMPORT_KEY]]; 1724 1726 [ret addEntriesFromDictionary:[ret objectForKey:META_XML_IMPORT_KEY]]; 1725 1727 combinedInfo = ret; … … 1765 1767 [self constructCombinedData]; 1766 1768 return [combinedInfo objectForKey:META_TITLE_KEY] ; 1769 } 1770 1771 /*! 1772 * @brief Returns the title of the file 1773 * 1774 * @return The title of the file 1775 */ 1776 - (NSString *)movieTitle 1777 { 1778 [self constructCombinedData]; 1779 return [combinedInfo objectForKey:META_MOVIE_TITLE_KEY] ; 1767 1780 } 1768 1781 trunk/SapphireMovieImporter.m
r225 r226 13 13 14 14 /* IMDB XPATHS */ 15 #define IMDB_SEARCH_XPATH @"//td[starts-with(a/@href,'/title')]" 16 #define IMDB_RESULT_LINK_XPATH @"a/@href" 17 #define IMDB_RESULT_NAME_XPATH @"normalize-space(string())" 15 #define IMDB_SEARCH_XPATH @"//td[starts-with(a/@href,'/title')]" 16 #define IMDB_RESULT_LINK_XPATH @"a/@href" 17 #define IMDB_RESULT_NAME_XPATH @"normalize-space(string())" 18 #define IMDB_RESULT_TITLE_YEAR_XPATH @"//div[@id='tn15title']/h1/replace(string(), '\n', '')" 18 19 19 20 … … 25 26 { 26 27 NSString *destination; 27 } 28 - (id)initWithDest:(NSString *)dest; 28 NSArray *requestList ; 29 30 } 31 - (id)initWithRequest:(NSArray*)reqList withDestination:(NSString *)dest; 32 -(void)getCoverArt ; 29 33 @end 30 34 … … 33 37 * @brief Initialize a cover art downloader 34 38 * 39 * @param reqList The list of url requests to try 35 40 * @param dest The path to save the file 36 41 */ 37 - (id)initWith Dest:(NSString *)dest42 - (id)initWithRequest:(NSArray*)reqList withDestination:(NSString *)dest; 38 43 { 39 44 self = [super init]; … … 42 47 43 48 destination = [dest retain]; 49 requestList = [reqList retain]; 44 50 45 51 return self; 46 } 52 53 } 54 55 /*! 56 * @brief Fire the delegate to start downloading 57 * 58 */ 59 -(void)getCoverArt 60 { 61 NSEnumerator *reqEnum= [requestList objectEnumerator] ; 62 NSURLRequest *req=nil ; 63 while((req=[reqEnum nextObject]) !=nil) 64 { 65 NSURLDownload *currentDownload=[[NSURLDownload alloc] initWithRequest:req delegate:self] ; 66 [currentDownload release] ; 67 // if(currentDownload)break;/*The download is going, no need to try another URL */ 68 } 69 70 } 71 47 72 48 73 - (void)dealloc 49 74 { 50 75 [destination release]; 76 [requestList release]; 51 77 [super dealloc]; 52 78 } … … 61 87 - (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename 62 88 { 63 [download setDestination:destination allowOverwrite:YES]; 64 } 89 90 [download setDestination:destination allowOverwrite:NO]; 91 92 } 93 94 - (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error 95 { 96 [download release]; 97 // NSString *failed=[[error userInfo] objectForKey:NSErrorFailingURLStringKey] ; 98 } 99 65 100 @end 66 101 … … 116 151 * @return A cached dictionary of the movie info 117 152 */ 118 - (NSMutableDictionary *)getMetaForMovie:(NSString *)movieName 153 - (NSMutableDictionary *)getMetaForMovie:(NSString *)movieName withPath:(NSString*)moviePath 119 154 { 120 155 NSError *error = nil; … … 123 158 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.IMDB.com%@",movieName]]; 124 159 NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:url options:NSXMLDocumentTidyHTML error:&error]; 125 126 NSString *movieTitle= [[document objectsForXQuery:@"//div[@id='tn15title']/h1/replace(string(), '\n', '')" error:&error] objectAtIndex:0]; 160 161 /* Get the movie title */ 162 NSString *movieTitle= [[document objectsForXQuery:IMDB_RESULT_TITLE_YEAR_XPATH error:&error] objectAtIndex:0]; 163 int titleYear= 0 ; 164 NSString *shortenedMovieTitle=nil ; 165 NSString *coverArtLinkA=nil ; 166 NSString *coverArtLinkB=nil ; 167 NSString *coverArtSavePath=nil ; 168 NSCharacterSet *decimalSet = [NSCharacterSet decimalDigitCharacterSet]; 169 NSCharacterSet *skipSet = [NSCharacterSet characterSetWithCharactersInString:@"("]; 170 NSScanner *titleScan= [NSScanner scannerWithString:movieTitle] ; 171 172 /* Cover Art Processing */ 173 [titleScan scanUpToCharactersFromSet:skipSet intoString:&shortenedMovieTitle]; 174 [titleScan scanUpToCharactersFromSet:decimalSet intoString:nil]; 175 [titleScan scanInt:&titleYear]; 176 177 /* Remove punctuation */ 178 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@":" withString:@""]; 179 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"'" withString:@""]; 180 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"," withString:@""]; 181 shortenedMovieTitle=[[shortenedMovieTitle stringByReplacingAllOccurancesOf:@" " withString:@"_"] lowercaseString]; 182 183 /*Convert roman to verbage*/ 184 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_i_" withString:@"_one_"] ; 185 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_ii_" withString:@"_two_"] ; 186 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_iii_" withString:@"_three_"] ; 187 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_iv_" withString:@"_four_"] ; 188 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_v_" withString:@"_five_"] ; 189 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_1_" withString:@"_one_"] ; 190 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_2_" withString:@"_two_"] ; 191 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_3_" withString:@"_three_"] ; 192 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_4_" withString:@"_four_"] ; 193 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_5_" withString:@"_five_"] ; 194 195 /* Symbol Replacements */ 196 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"&" withString:@"_and_"] ; 197 shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"®" withString:@"ae"] ; 198 199 /* Remove leading 'the' and 'a' */ 200 if([shortenedMovieTitle hasPrefix:@"the_"])shortenedMovieTitle=[shortenedMovieTitle substringFromIndex:4]; 201 else if([shortenedMovieTitle hasPrefix:@"a_"])shortenedMovieTitle=[shortenedMovieTitle substringFromIndex:2]; 202 coverArtLinkA=[NSString stringWithFormat:@"http://www.impawards.com/%d/posters/%@ver1.jpg",titleYear,shortenedMovieTitle] ; 203 coverArtLinkB=[coverArtLinkA stringByReplacingAllOccurancesOf:@"_ver1" withString:@""]; 204 coverArtSavePath=[[[moviePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Cover Art"] stringByAppendingPathComponent:[[[moviePath lastPathComponent] stringByDeletingPathExtension] stringByAppendingPathExtension:@"jpg"]]; 205 error = nil; 206 BOOL isDir = NO; 207 BOOL imageExists = [[NSFileManager defaultManager] fileExistsAtPath:coverArtSavePath isDirectory:&isDir] && !isDir; 208 if(!imageExists)/*Get the screen cap*/ 209 { 210 NSArray *requestURLList=[[NSArray alloc] initWithObjects: 211 [NSURLRequest requestWithURL:[NSURL URLWithString:coverArtLinkA] 212 cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0], 213 [NSURLRequest requestWithURL:[NSURL URLWithString:coverArtLinkB] 214 cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0], 215 nil]; 216 217 218 // SapphireMovieDataMenuDownloadDelegate *myDelegate= [[SapphireMovieDataMenuDownloadDelegate alloc] initWithRequest:requestURLList withDestination:coverArtSavePath]; 219 // [[NSFileManager defaultManager] createDirectoryAtPath:[coverArtSavePath stringByDeletingLastPathComponent] attributes:nil]; 220 // [myDelegate getCoverArt]; 221 // [[NSURLDownload alloc] initWithRequest:[requestURLList objectAtIndex:0] delegate:myDelegate]; 222 // [myDelegate release]; 223 } 224 127 225 /* Dump XML document to disk (Dev Only) */ 128 //NSString *documentPath =[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/XML"]; 129 //[[document XMLDataWithOptions:NSXMLNodePrettyPrint] writeToFile:[NSString stringWithFormat:@"/%@/%@_title_result.xml",documentPath,movieTitle] atomically:YES] ; 130 131 132 133 [ret setObject:movieTitle forKey:META_MOVIE_TITLE]; 226 // NSString *documentPath =[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/XML"]; 227 // [[document XMLDataWithOptions:NSXMLNodePrettyPrint] writeToFile:[NSString stringWithFormat:@"/%@/%@_title_result.xml",documentPath,movieTitle] atomically:YES] ; 228 229 230 231 /* populate metadata to return */ 232 [ret setObject:movieTitle forKey:META_MOVIE_TITLE_KEY]; 134 233 return ret; 135 234 } 136 235 137 /*! 138 * @brief Fetches the screencap URL from a show's info URL 139 * 140 * @param epUrl The show's info URL 141 * @return The screencap URL if it exists, nil otherwise 142 */ 143 - (NSString *)getScreencapUrl:(NSString *)epUrl 144 { 145 /*Get the HTML document*/ 146 // NSURL *url = [NSURL URLWithString:epUrl]; 147 // NSError *error = nil; 148 // NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:url options:NSXMLDocumentTidyHTML error:&error]; 149 150 /*Search for a screencap*/ 151 // NSXMLElement *html = [document rootElement]; 152 // NSArray *caps = [html objectsForXQuery:TVRAGE_SCREEN_CAP_XPATH error:&error]; 153 // if([caps count]) 154 /*Found one; return it*/ 155 // return [[(NSXMLElement *)[caps objectAtIndex:0] attributeForName:@"src"] stringValue]; 156 /*None found*/ 157 return nil; 158 } 236 159 237 160 238 /*! … … 295 373 } 296 374 297 /*Get The Release Date*/ 298 299 300 301 302 375 /*Import the info*/ 303 376 NSMutableDictionary *info = nil; 304 info = [self getMetaForMovie:movie ];377 info = [self getMetaForMovie:movie withPath:path]; 305 378 if(!info) 306 return NO; 307 308 309 /*Import the info*/ 379 return NO; 310 380 [info removeObjectForKey:LINK_KEY]; 311 381 [metaData importInfo:info fromSource:META_IMDB_IMPORT_KEY withTime:[[NSDate date] timeIntervalSince1970]]; trunk/SapphireTVShowImporter.m
r218 r226 20 20 #define TVRAGE_SEARCH_XPATH @"//*[@class='b1']/a" 21 21 #define TVRAGE_UNKNOWN_XPATH @"//*[contains(text(), 'Unknown Page')]" 22 23 /* IMDB XPATHS */24 #define IMDB_SEARCH_XPATH @"//td[starts-with(a/@href,'/title')]"25 #define IMDB_RESULT_LINK_XPATH @"a/@href"26 #define IMDB_RESULT_NAME_XPATH @"normalize-space(string())"27 22 28 23 #define TRANSLATIONS_KEY @"Translations"
