Changeset 224

Show
Ignore:
Timestamp:
09/15/07 04:09:28 (1 year ago)
Author:
pmerrill
Message:
  • Modified searchStr for movies to return better results
  • Fixed an issue for IMDB searches. IMDB returned a /title/ page when the searchStr was a unique value.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/SapphireApplianceController.m

    r218 r224  
    102102        SapphireFileDataImporter *fileImp = [[SapphireFileDataImporter alloc] init]; 
    103103        SapphireTVShowImporter *tvImp = [[SapphireTVShowImporter alloc] initWithSavedSetting:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/tvdata.plist"]]; 
    104          
     104//      SapphireMovieImporter *movImp = [[SapphireTVShowImporter alloc] initWithSavedSetting:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/movieData.plist"]]; 
    105105        SapphireAllImporter *allImp = [[SapphireAllImporter alloc] initWithImporters:[NSArray arrayWithObjects:fileImp, tvImp, nil]]; 
    106106        [fileImp release]; 
  • trunk/SapphireMovieImporter.m

    r221 r224  
    123123        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.IMDB.com%@",movieName]]; 
    124124        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]; 
    125127        /* Dump XML document to disk (Dev Only) */ 
    126128        NSString *documentPath =[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/XML"]; 
    127         [[document XMLDataWithOptions:NSXMLNodePrettyPrint] writeToFile:[NSString stringWithFormat:@"/%@%@_page.xml",documentPath,movieName] atomically:YES] ; 
    128         NSString *movieTitle= [[document objectsForXQuery:@"//div[@id='tn15title']/h1/replace(string(), '\n', '')" error:&error] objectAtIndex:0]; 
     129        [[document XMLDataWithOptions:NSXMLNodePrettyPrint] writeToFile:[NSString stringWithFormat:@"/%@/%@_title_result.xml",documentPath,movieTitle] atomically:YES] ; 
     130                 
     131 
    129132         
    130133        [ret setObject:movieTitle forKey:META_MOVIE_TITLE]; 
     
    163166- (NSArray *)searchResultsForMovie:(NSString *)searchStr 
    164167{ 
     168        /* prep the search string */ 
     169        searchStr = [searchStr stringByDeletingPathExtension]; 
    165170        searchStr = [searchStr stringByReplacingAllOccurancesOf:@"_" withString:@" "]; 
    166171        searchStr = [searchStr stringByReplacingAllOccurancesOf:@"." withString:@" "]; 
    167172        searchStr = [searchStr stringByReplacingAllOccurancesOf:@"-" withString:@" "]; 
    168         NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.imdb.com/Title?%@", [searchStr URLEncode]]]; 
     173        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.imdb.com/find?s=all&q=%@", [searchStr URLEncode]]]; 
    169174        NSError *error = nil; 
    170175        NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:url options:NSXMLDocumentTidyHTML error:&error]; 
    171176        /* Dump XML document to disk (Dev Only) */ 
    172177        NSString *documentPath =[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/XML"]; 
    173         [[document XMLDataWithOptions:NSXMLNodePrettyPrint] writeToFile:[NSString stringWithFormat:@"%@/%@.xml",documentPath,searchStr] atomically:YES] ; 
    174         /*Get the results list*/ 
     178        [[document XMLDataWithOptions:NSXMLNodePrettyPrint] writeToFile:[NSString stringWithFormat:@"%@/%@_search_result.xml",documentPath,searchStr] atomically:YES] ; 
     179         
    175180        NSXMLElement *root = [document rootElement]; 
    176         NSArray *results = [root objectsForXQuery:IMDB_SEARCH_XPATH error:&error]; 
    177         //Need to clean out (VG) entries <Video Game> 
    178         NSMutableArray *ret = [NSMutableArray arrayWithCapacity:[results count]]; 
    179         if([results count]) 
    180         { 
    181                 /*Get each result*/ 
    182                 NSEnumerator *resultEnum = [results objectEnumerator]; 
    183                 NSXMLElement *result = nil; 
    184                 while((result = [resultEnum nextObject]) != nil) 
     181         
     182        NSString *resultTitle=[[[root objectsForXQuery:@"//title" error:&error]objectAtIndex:0] stringValue]; 
     183         
     184        if([resultTitle isEqualToString:@"IMDb Search"])/*Make sure we didn't get back a unique result */ 
     185        { 
     186                /*Get the results list*/ 
     187                NSArray *results = [root objectsForXQuery:IMDB_SEARCH_XPATH error:&error]; 
     188 
     189                //Need to clean out (VG) entries <Video Game> 
     190                NSMutableArray *ret = [NSMutableArray arrayWithCapacity:[results count]]; 
     191                if([results count]) 
    185192                { 
    186                         /*Add the result to the list*/ 
    187                         //                      NSURL *resultURL = [NSURL URLWithString:[[result attributeForName:@"href"] stringValue]]; 
    188                         NSURL *resultURL = [NSURL URLWithString:[[[result objectsForXQuery:IMDB_RESULT_LINK_XPATH error:&error] objectAtIndex:0] stringValue]] ; 
     193                        /*Get each result*/ 
     194                        NSEnumerator *resultEnum = [results objectEnumerator]; 
     195                        NSXMLElement *result = nil; 
     196                        while((result = [resultEnum nextObject]) != nil) 
     197                        { 
     198                                /*Add the result to the list*/ 
     199 
     200                                NSURL *resultURL = [NSURL URLWithString:[[[result objectsForXQuery:IMDB_RESULT_LINK_XPATH error:&error] objectAtIndex:0] stringValue]] ; 
    189201                         
    190                         if(resultURL == nil) 
    191                                 continue; 
    192                        
    193                                 [ret addObject:[NSDictionary dictionaryWithObjectsAndKeys: 
     202                               if(resultURL == nil) 
     203                                       continue; 
     204                               
     205                                       [ret addObject:[NSDictionary dictionaryWithObjectsAndKeys: 
    194206                                        [[result objectsForXQuery:IMDB_RESULT_NAME_XPATH error:&error] objectAtIndex:0], @"name", 
    195207                                        [resultURL path], @"link", 
    196208                                        nil]]; 
     209                                } 
    197210                        } 
     211                        return ret; 
    198212                } 
    199                 return ret; 
     213        } 
     214        else /* IMDB directly linked to a unique movie title */ 
     215        { 
     216                NSMutableArray *ret = [NSMutableArray arrayWithCapacity:1]; 
     217                [ret addObject:[NSDictionary dictionaryWithObjectsAndKeys: 
     218                resultTitle, @"name", 
     219                [[url relativeString] stringByReplacingAllOccurancesOf:@"http://www.imdb.com" withString:@""], @"link", 
     220                nil]]; 
     221                return ret ; 
    200222        } 
    201223        /*No results found*/ 
  • trunk/SapphireSettings.m

    r218 r224  
    443443        else if(row == 2) 
    444444        { 
    445                 SapphireMovieImporter *importer = [[SapphireMovieImporter alloc] initWithSavedSetting:[[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"tvdata.plist"]]; 
     445                SapphireMovieImporter *importer = [[SapphireMovieImporter alloc] initWithSavedSetting:[[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"movieData.plist"]]; 
    446446                SapphireImporterDataMenu *menu = [[SapphireImporterDataMenu alloc] initWithScene:[self scene] metaDataCollection:metaCollection importer:importer]; 
    447447                [[self stack] pushController:menu];