Changeset 224
- Timestamp:
- 09/15/07 04:09:28 (1 year ago)
- Files:
-
- trunk/SapphireApplianceController.m (modified) (1 diff)
- trunk/SapphireMovieImporter.m (modified) (2 diffs)
- trunk/SapphireSettings.m (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/SapphireApplianceController.m
r218 r224 102 102 SapphireFileDataImporter *fileImp = [[SapphireFileDataImporter alloc] init]; 103 103 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"]]; 105 105 SapphireAllImporter *allImp = [[SapphireAllImporter alloc] initWithImporters:[NSArray arrayWithObjects:fileImp, tvImp, nil]]; 106 106 [fileImp release]; trunk/SapphireMovieImporter.m
r221 r224 123 123 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.IMDB.com%@",movieName]]; 124 124 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]; 125 127 /* Dump XML document to disk (Dev Only) */ 126 128 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 129 132 130 133 [ret setObject:movieTitle forKey:META_MOVIE_TITLE]; … … 163 166 - (NSArray *)searchResultsForMovie:(NSString *)searchStr 164 167 { 168 /* prep the search string */ 169 searchStr = [searchStr stringByDeletingPathExtension]; 165 170 searchStr = [searchStr stringByReplacingAllOccurancesOf:@"_" withString:@" "]; 166 171 searchStr = [searchStr stringByReplacingAllOccurancesOf:@"." withString:@" "]; 167 172 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]]]; 169 174 NSError *error = nil; 170 175 NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:url options:NSXMLDocumentTidyHTML error:&error]; 171 176 /* Dump XML document to disk (Dev Only) */ 172 177 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 175 180 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]) 185 192 { 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]] ; 189 201 190 if(resultURL == nil)191 continue;192 {193 [ret addObject:[NSDictionary dictionaryWithObjectsAndKeys:202 if(resultURL == nil) 203 continue; 204 { 205 [ret addObject:[NSDictionary dictionaryWithObjectsAndKeys: 194 206 [[result objectsForXQuery:IMDB_RESULT_NAME_XPATH error:&error] objectAtIndex:0], @"name", 195 207 [resultURL path], @"link", 196 208 nil]]; 209 } 197 210 } 211 return ret; 198 212 } 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 ; 200 222 } 201 223 /*No results found*/ trunk/SapphireSettings.m
r218 r224 443 443 else if(row == 2) 444 444 { 445 SapphireMovieImporter *importer = [[SapphireMovieImporter alloc] initWithSavedSetting:[[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:@" tvdata.plist"]];445 SapphireMovieImporter *importer = [[SapphireMovieImporter alloc] initWithSavedSetting:[[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"movieData.plist"]]; 446 446 SapphireImporterDataMenu *menu = [[SapphireImporterDataMenu alloc] initWithScene:[self scene] metaDataCollection:metaCollection importer:importer]; 447 447 [[self stack] pushController:menu];
