Changeset 527
- Timestamp:
- 05/03/08 16:44:03 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/SapphireFrappliance/SapphireTVShowImporter.m
r509 r527 31 31 #define TVRAGE_EP_INFO @".//*[@class='b2']/*" 32 32 #define TVRAGE_EP_TEXT @".//*[@class='b2']/text()" 33 #define TVRAGE_SCREEN_CAP_XPATH @" //img[contains(@src, 'screencap')]"33 #define TVRAGE_SCREEN_CAP_XPATH @".//img[contains(@src, 'screencap')]" 34 34 #define TVRAGE_SEARCH_XPATH @"//*[@class='b1']/a" 35 35 #define TVRAGE_UNKNOWN_XPATH @"//*[contains(text(), 'Unknown Page')]" … … 37 37 #define TRANSLATIONS_KEY @"Translations" 38 38 #define LINK_KEY @"Link" 39 #define IMG_URL @"imgURL" 39 40 40 41 /*Delegate class to download cover art*/ … … 128 129 129 130 /*! 130 * @brief Fetches the screencap URL from a show's info URL131 *132 * @param epUrl The show's info URL133 * @return The screencap URL if it exists, nil otherwise134 */135 - (NSString *)getScreencapUrl:(NSString *)epUrl136 {137 /*Get the HTML document*/138 NSURL *url = [NSURL URLWithString:epUrl];139 NSError *error = nil;140 NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:url options:NSXMLDocumentTidyHTML error:&error];141 142 /*Search for a screencap*/143 NSXMLElement *html = [document rootElement];144 NSArray *caps = [html objectsForXQuery:TVRAGE_SCREEN_CAP_XPATH error:&error];145 if([caps count])146 /*Found one; return it*/147 return [[(NSXMLElement *)[caps objectAtIndex:0] attributeForName:@"src"] stringValue];148 /*None found*/149 return nil;150 }151 152 /*!153 131 * @brief Add an episode's info into our cache dict 154 132 * … … 161 139 * @param epNumber The absolute episode number 162 140 * @param airDate The episode's air date 141 * @param imgURL The episode's screenshot URL 163 142 * @param dict The cache dictionary 164 143 */ 165 - (void)addEp:(NSString *)showName title:(NSString *)epTitle season:(int)season epNum:(int)ep summary:(NSString *)summary link:(NSString *)epLink absEpNum:(int)epNumber airDate:(NSDate *)airDate showID:(NSString *)showID toDict:(NSMutableDictionary *)dict144 - (void)addEp:(NSString *)showName title:(NSString *)epTitle season:(int)season epNum:(int)ep summary:(NSString *)summary link:(NSString *)epLink absEpNum:(int)epNumber airDate:(NSDate *)airDate showID:(NSString *)showID imgURL:(NSString *)imgURL toDict:(NSMutableDictionary *)dict 166 145 { 167 146 /*Set the key by which to store this. Either by season/ep or season/title*/ … … 203 182 if(airDate != nil) 204 183 [epDict setObject:airDate forKey:META_SHOW_AIR_DATE]; 184 if(imgURL != nil) 185 [epDict setObject:imgURL forKey:IMG_URL]; 205 186 } 206 187 … … 254 235 NSMutableString *summary = nil; 255 236 NSDate *airDate = nil; 237 NSString *imageURL = nil; 256 238 257 239 /*Get the info pieces*/ … … 313 295 summary = nil; 314 296 } 297 else if(imageURL == nil) 298 { 299 NSArray *images = [epInfo objectsForXQuery:TVRAGE_SCREEN_CAP_XPATH error:&error]; 300 if([images count]) 301 { 302 imageURL = [[(NSXMLElement *)[images objectAtIndex:0] attributeForName:@"src"] stringValue]; 303 } 304 } 315 305 } 316 306 epInfos = [epNode objectsForXQuery:TVRAGE_EP_TEXT error:&error]; … … 333 323 } 334 324 /*Add to cache*/ 335 [self addEp:showName title:epTitle season:seasonNum epNum:ep summary:summary link:link absEpNum:epNumber airDate:airDate showID:seriesName toDict:ret];325 [self addEp:showName title:epTitle season:seasonNum epNum:ep summary:summary link:link absEpNum:epNumber airDate:airDate showID:seriesName imgURL:imageURL toDict:ret]; 336 326 } 337 327 return ret; … … 621 611 [[NSFileManager defaultManager] constructPath:previewArtPath]; 622 612 /*Check for screen cap locally and on server*/ 623 NSString *showInfoUrl = [info objectForKey:LINK_KEY]; 624 NSString *image = nil; 613 NSString *imgURL = [info objectForKey:IMG_URL]; 625 614 NSString *newPath = [previewArtPath stringByAppendingPathComponent:fileName]; 626 615 NSString *imageDestination = [[newPath stringByDeletingPathExtension] stringByAppendingPathExtension:@"jpg"]; 627 616 BOOL isDir = NO; 628 617 BOOL imageExists = [[NSFileManager defaultManager] fileExistsAtPath:imageDestination isDirectory:&isDir] && !isDir; 629 if(showInfoUrl && !imageExists) 630 /*Get the screen cap*/ 631 image = [self getScreencapUrl:showInfoUrl]; 632 if(image) 618 if(imgURL && !imageExists) 633 619 { 634 620 /*Download the screen cap*/ 635 NSURL *imageURL = [NSURL URLWithString:im age];621 NSURL *imageURL = [NSURL URLWithString:imgURL]; 636 622 NSURLRequest *request = [NSURLRequest requestWithURL:imageURL]; 637 623 SapphireTVShowDataMenuDownloadDelegate *myDelegate = [[SapphireTVShowDataMenuDownloadDelegate alloc] initWithDest:imageDestination];
