Changeset 527

Show
Ignore:
Timestamp:
05/03/08 16:44:03 (8 months ago)
Author:
gbooker
Message:

Switched to getting the screenshot url out of the ep list. This is far faster, and actually more reliable now that tvrage is doing the preview movies on the ep page.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/SapphireFrappliance/SapphireTVShowImporter.m

    r509 r527  
    3131#define TVRAGE_EP_INFO @".//*[@class='b2']/*" 
    3232#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')]" 
    3434#define TVRAGE_SEARCH_XPATH @"//*[@class='b1']/a" 
    3535#define TVRAGE_UNKNOWN_XPATH @"//*[contains(text(), 'Unknown Page')]" 
     
    3737#define TRANSLATIONS_KEY                @"Translations" 
    3838#define LINK_KEY                                @"Link" 
     39#define IMG_URL                                 @"imgURL" 
    3940 
    4041/*Delegate class to download cover art*/ 
     
    128129 
    129130/*! 
    130  * @brief Fetches the screencap URL from a show's info URL 
    131  * 
    132  * @param epUrl The show's info URL 
    133  * @return The screencap URL if it exists, nil otherwise 
    134  */ 
    135 - (NSString *)getScreencapUrl:(NSString *)epUrl 
    136 { 
    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 /*! 
    153131 * @brief Add an episode's info into our cache dict 
    154132 * 
     
    161139 * @param epNumber The absolute episode number 
    162140 * @param airDate The episode's air date 
     141 * @param imgURL The episode's screenshot URL 
    163142 * @param dict The cache dictionary 
    164143 */ 
    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 *)dict 
     144- (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 
    166145{ 
    167146        /*Set the key by which to store this.  Either by season/ep or season/title*/ 
     
    203182        if(airDate != nil) 
    204183                [epDict setObject:airDate forKey:META_SHOW_AIR_DATE]; 
     184        if(imgURL != nil) 
     185                [epDict setObject:imgURL forKey:IMG_URL]; 
    205186} 
    206187 
     
    254235                NSMutableString *summary = nil; 
    255236                NSDate *airDate = nil; 
     237                NSString *imageURL = nil; 
    256238                 
    257239                /*Get the info pieces*/ 
     
    313295                                        summary = nil; 
    314296                        } 
     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                        } 
    315305                } 
    316306                epInfos = [epNode objectsForXQuery:TVRAGE_EP_TEXT error:&error]; 
     
    333323                } 
    334324                /*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]; 
    336326        } 
    337327        return ret; 
     
    621611        [[NSFileManager defaultManager] constructPath:previewArtPath]; 
    622612        /*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]; 
    625614        NSString *newPath = [previewArtPath stringByAppendingPathComponent:fileName]; 
    626615        NSString *imageDestination = [[newPath stringByDeletingPathExtension] stringByAppendingPathExtension:@"jpg"]; 
    627616        BOOL isDir = NO; 
    628617        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) 
    633619        { 
    634620                /*Download the screen cap*/ 
    635                 NSURL *imageURL = [NSURL URLWithString:image]; 
     621                NSURL *imageURL = [NSURL URLWithString:imgURL]; 
    636622                NSURLRequest *request = [NSURLRequest requestWithURL:imageURL]; 
    637623                SapphireTVShowDataMenuDownloadDelegate *myDelegate = [[SapphireTVShowDataMenuDownloadDelegate alloc] initWithDest:imageDestination];