Commit b8657b24 authored by Pierre's avatar Pierre

Various fixes.

parent 3f7d4746
......@@ -39,7 +39,7 @@ enum {
@interface CXMLDocument : CXMLNode {
NSMutableSet *nodePool;
}
@property (retain,readwrite) NSMutableSet *nodePool;
- (id)initWithData:(NSData *)inData options:(NSUInteger)inOptions error:(NSError **)outError;
- (id)initWithData:(NSData *)inData encoding:(NSStringEncoding)encoding options:(NSUInteger)inOptions error:(NSError **)outError;
- (id)initWithXMLString:(NSString *)inString options:(NSUInteger)inOptions error:(NSError **)outError;
......
......@@ -45,7 +45,7 @@
if ((self = [super init]) != NULL)
{
NSError *theError = NULL;
#if TOUCHXMLUSETIDY
if (inOptions & CXMLDocumentTidyHTML)
{
......@@ -56,7 +56,7 @@ if ((self = [super init]) != NULL)
inString = [[CTidy tidy] tidyString:inString inputFormat:TidyFormat_XML outputFormat:TidyFormat_XML diagnostics:NULL error:&theError];
}
#endif
xmlDocPtr theDoc = xmlParseDoc((xmlChar *)[inString UTF8String]);
if (theDoc != NULL)
{
......@@ -67,14 +67,14 @@ if ((self = [super init]) != NULL)
else
{
xmlErrorPtr theLastErrorPtr = xmlGetLastError();
NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithUTF8String:theLastErrorPtr->message], NSLocalizedDescriptionKey,
NULL];
theError = [NSError errorWithDomain:@"CXMLErrorDomain" code:1 userInfo:theUserInfo];
xmlResetLastError();
}
......@@ -92,7 +92,7 @@ return(self);
- (id)initWithData:(NSData *)inData options:(NSUInteger)inOptions error:(NSError **)outError
{
return [self initWithData:inData encoding:NSUTF8StringEncoding options:inOptions error:outError];
return [self initWithData:inData encoding:NSUTF8StringEncoding options:inOptions error:outError];
}
- (id)initWithData:(NSData *)inData encoding:(NSStringEncoding)encoding options:(NSUInteger)inOptions error:(NSError **)outError
......@@ -100,7 +100,7 @@ return(self);
if ((self = [super init]) != NULL)
{
NSError *theError = NULL;
#if TOUCHXMLUSETIDY
if (inOptions & CXMLDocumentTidyHTML)
{
......@@ -111,7 +111,7 @@ if ((self = [super init]) != NULL)
inData = [[CTidy tidy] tidyData:inData inputFormat:TidyFormat_XML outputFormat:TidyFormat_XML diagnostics:NULL error:&theError];
}
#endif
if (theError == NULL)
{
xmlDocPtr theDoc = NULL;
......@@ -122,7 +122,7 @@ if ((self = [super init]) != NULL)
const char *enc = CFStringGetCStringPtr(cfencstr, 0);
theDoc = xmlReadMemory([inData bytes], [inData length], NULL, enc, XML_PARSE_RECOVER | XML_PARSE_NOWARNING);
}
if (theDoc != NULL)
{
_node = (xmlNodePtr)theDoc;
......@@ -165,7 +165,7 @@ else
{
self = NULL;
}
return(self);
}
......@@ -197,7 +197,7 @@ _node = NULL;
- (CXMLElement *)rootElement
{
xmlNodePtr theLibXMLNode = xmlDocGetRootElement((xmlDocPtr)_node);
return([CXMLNode nodeWithLibXMLNode:theLibXMLNode freeOnDealloc:NO]);
}
......@@ -241,9 +241,33 @@ int buffersize;
xmlDocDumpFormatMemory((xmlDocPtr)(self->_node), &xmlbuff, &buffersize, 1);
NSString *dump = [[[NSString alloc] initWithBytes:xmlbuff length:buffersize encoding:NSUTF8StringEncoding] autorelease];
xmlFree(xmlbuff);
[result appendString:dump];
return result;
}
- (void)insertChild:(CXMLNode *)child atIndex:(NSUInteger)index
{
[self.nodePool addObject:child];
CXMLNode *theCurrentNode = [self.children objectAtIndex:index];
xmlAddPrevSibling(theCurrentNode->_node, child->_node);
}
- (void)addChild:(CXMLNode *)child
{
[self.nodePool addObject:child];
xmlAddChild(self->_node, child->_node);
}
- (NSMutableSet *)nodePool
{
if (nodePool == NULL)
{
nodePool = [[NSMutableSet alloc] init];
}
return(nodePool);
}
@end
......@@ -40,14 +40,6 @@ xmlParseDocument(inContext);
}
*/
- (NSMutableSet *)nodePool
{
if (nodePool == NULL)
{
nodePool = [[NSMutableSet alloc] init];
}
return(nodePool);
}
@end
......@@ -80,4 +80,11 @@ typedef enum {
- (NSString *)XMLStringWithOptions:(NSUInteger)options;
//- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments;
- (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error;
@property (readonly, nonatomic, assign) xmlNodePtr node;
- (id)initWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc;
+ (id)nodeWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc;
@end
......@@ -92,7 +92,7 @@ else
NSAssert(_node != NULL, @"CXMLNode does not have attached libxml2 _node.");
xmlChar *theXMLString;
BOOL theFreeReminderFlag = NO;
if (_node->type == XML_TEXT_NODE || _node->type == XML_CDATA_SECTION_NODE)
if (_node->type == XML_TEXT_NODE || _node->type == XML_CDATA_SECTION_NODE)
theXMLString = _node->content;
else
{
......@@ -175,7 +175,7 @@ while (theCurrentNode != NULL)
[theChildren addObject:theNode];
theCurrentNode = theCurrentNode->next;
}
return(theChildren);
return(theChildren);
}
- (CXMLNode *)childAtIndex:(NSUInteger)index
......@@ -305,7 +305,7 @@ else
xmlNodePtr theNode = theXPathObject->nodesetval->nodeTab[N];
[theArray addObject:[CXMLNode nodeWithLibXMLNode:theNode freeOnDealloc:NO]];
}
theResult = theArray;
}
......@@ -318,6 +318,89 @@ return(theResult);
//- (NSArray *)objectsForXQuery:(NSString *)xquery error:(NSError **)error;
@dynamic node;
- (id)initWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc
{
if ((self = [super init]) != NULL)
{
_node = inLibXMLNode;
_freeNodeOnRelease = infreeOnDealloc;
}
return(self);
}
+ (id)nodeWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc
{
// TODO more checking.
if (inLibXMLNode->_private)
return(inLibXMLNode->_private);
Class theClass = [CXMLNode class];
switch (inLibXMLNode->type)
{
case XML_ELEMENT_NODE:
theClass = [CXMLElement class];
break;
case XML_DOCUMENT_NODE:
theClass = [CXMLDocument class];
break;
case XML_ATTRIBUTE_NODE:
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_COMMENT_NODE:
break;
default:
NSAssert1(NO, @"TODO Unhandled type (%d).", inLibXMLNode->type);
return(NULL);
}
CXMLNode *theNode = [[[theClass alloc] initWithLibXMLNode:inLibXMLNode freeOnDealloc:infreeOnDealloc] autorelease];
if (inLibXMLNode->doc != NULL)
{
CXMLDocument *theXMLDocument = inLibXMLNode->doc->_private;
if (theXMLDocument != NULL)
{
NSAssert([theXMLDocument isKindOfClass:[CXMLDocument class]] == YES, @"TODO");
[[theXMLDocument nodePool] addObject:theNode];
theNode->_node->_private = theNode;
}
}
return(theNode);
}
- (NSString *)stringValueForXPath:(NSString *)string
{
NSArray *nodes = [self nodesForXPath:string error:nil];
if ([nodes count] == 0)
return nil;
return [[nodes objectAtIndex:0] stringValue];
}
- (NSNumber *)numberValueForXPath:(NSString *)string
{
NSArray *nodes = [self nodesForXPath:string error:nil];
if ([nodes count] == 0)
return nil;
NSScanner *scanner = [NSScanner scannerWithString:[[nodes objectAtIndex:0] stringValue]];
NSInteger i;
if ([scanner scanInteger:&i])
return [NSNumber numberWithInteger:i];
return nil;
}
- (xmlNodePtr)node
{
return(_node);
}
@end
static int MyXmlOutputWriteCallback(void * context, const char * buffer, int len)
......
......@@ -31,10 +31,4 @@
@interface CXMLNode (CXMLNode_PrivateExtensions)
@property (readonly, nonatomic, assign) xmlNodePtr node;
- (id)initWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc;
+ (id)nodeWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc;
@end
......@@ -32,68 +32,7 @@
#import "CXMLElement.h"
#import "CXMLDocument_PrivateExtensions.h"
@implementation CXMLNode (CXMLNode_PrivateExtensions)
@implementation CXMLNode (dd)
@dynamic node;
- (id)initWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc
{
if ((self = [super init]) != NULL)
{
_node = inLibXMLNode;
_freeNodeOnRelease = infreeOnDealloc;
}
return(self);
}
+ (id)nodeWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc
{
// TODO more checking.
if (inLibXMLNode->_private)
return(inLibXMLNode->_private);
Class theClass = [CXMLNode class];
switch (inLibXMLNode->type)
{
case XML_ELEMENT_NODE:
theClass = [CXMLElement class];
break;
case XML_DOCUMENT_NODE:
theClass = [CXMLDocument class];
break;
case XML_ATTRIBUTE_NODE:
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_COMMENT_NODE:
break;
default:
NSAssert1(NO, @"TODO Unhandled type (%d).", inLibXMLNode->type);
return(NULL);
}
CXMLNode *theNode = [[[theClass alloc] initWithLibXMLNode:inLibXMLNode freeOnDealloc:infreeOnDealloc] autorelease];
if (inLibXMLNode->doc != NULL)
{
CXMLDocument *theXMLDocument = inLibXMLNode->doc->_private;
if (theXMLDocument != NULL)
{
NSAssert([theXMLDocument isKindOfClass:[CXMLDocument class]] == YES, @"TODO");
[[theXMLDocument nodePool] addObject:theNode];
theNode->_node->_private = theNode;
}
}
return(theNode);
}
- (xmlNodePtr)node
{
return(_node);
}
@end
......@@ -33,21 +33,3 @@
#import "CXMLNode_PrivateExtensions.h"
#import "CXMLDocument_PrivateExtensions.h"
@implementation CXMLDocument (CXMLDocument_CreationExtensions)
- (void)insertChild:(CXMLNode *)child atIndex:(NSUInteger)index
{
[self.nodePool addObject:child];
CXMLNode *theCurrentNode = [self.children objectAtIndex:index];
xmlAddPrevSibling(theCurrentNode->_node, child->_node);
}
- (void)addChild:(CXMLNode *)child
{
[self.nodePool addObject:child];
xmlAddChild(self->_node, child->_node);
}
@end
......@@ -5,8 +5,8 @@
// Created by Pierre d'Herbemont on 7/14/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <CoreData/CoreData.h>
#import <CoreData/CoreData.h>
@interface MLMediaLibrary : NSObject {
NSManagedObjectContext *_managedObjectContext;
......
......@@ -9,14 +9,23 @@
#import "MLMediaLibrary.h"
#import "MLTitleDecrapifier.h"
#import "MLMovieInfoGrabber.h"
#import "MLTVShowInfoGrabber.h"
#import "MLTVShowEpisodesInfoGrabber.h"
#import "File.h"
#import "Label.h"
#import "ShowEpisode.h"
#import "Show.h"
// Pref key
static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
#if HAVE_BLOCK
@interface MLMediaLibrary ()
#else
@interface MLMediaLibrary () <MLMovieInfoGrabberDelegate, MLTVShowEpisodesInfoGrabberDelegate, MLTVShowInfoGrabberDelegate>
#endif
- (NSManagedObjectContext *)managedObjectContext;
- (void)startUpdateDB;
@end
@implementation MLMediaLibrary
......@@ -25,6 +34,7 @@
static id sharedMediaLibrary = nil;
if (!sharedMediaLibrary) {
sharedMediaLibrary = [[[self class] alloc] init];
NSLog(@"Initializing db in %@", [sharedMediaLibrary databaseFolderPath]);
[sharedMediaLibrary startUpdateDB];
}
return sharedMediaLibrary;
......@@ -35,6 +45,7 @@
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = [self managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:entity inManagedObjectContext:moc];
NSAssert(entityDescription, @"No entity");
[request setEntity:entityDescription];
return [request autorelease];
}
......@@ -55,10 +66,10 @@
return _managedObjectModel;
}
- (NSURL *)databaseFolder
- (NSString *)databaseFolderPath
{
// FIXME
return [NSURL fileURLWithPath:[@"~/Library" stringByExpandingTildeInPath]];
return [@"~/Library" stringByExpandingTildeInPath];
;
}
......@@ -67,9 +78,9 @@
if (_managedObjectContext)
return _managedObjectContext;
NSString *databaseFolder = [[self databaseFolder] absoluteString];
NSString *databaseFolderPath = [self databaseFolderPath];
NSURL *url = [NSURL fileURLWithPath:[databaseFolder stringByAppendingPathComponent: @"MediaLibrary.sqlite"]];
NSURL *url = [NSURL fileURLWithPath:[databaseFolderPath stringByAppendingPathComponent: @"MediaLibrary.sqlite"]];
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
......@@ -90,6 +101,7 @@
NSRunInformationalAlertPanel(@"Relaunch Lunettes now", @"We need to relaunch Lunettes to proceed", @"OK", nil, nil);
[NSApp terminate:nil];
#else
NSLog(@"%@: %@", url, error);
abort();
#endif
}
......@@ -179,6 +191,7 @@
*wasInserted = NO;
if (!show) {
*wasInserted = YES;
NSLog(@"Creating %@", showName);
show = [self createObjectForEntity:@"Show"];
show.name = showName;
}
......@@ -186,6 +199,67 @@
return [self showEpisodeWithShow:show episodeNumber:episodeNumber seasonNumber:seasonNumber];
}
#if !HAVE_BLOCK
- (void)tvShowEpisodesInfoGrabberDidFinishGrabbing:(MLTVShowEpisodesInfoGrabber *)grabber
{
Show *show = grabber.userData;
NSArray *results = grabber.episodesResults;
[show setValue:[grabber.results objectForKey:@"serieArtworkURL"] forKey:@"artworkURL"];
for (id result in results) {
if ([[result objectForKey:@"serie"] boolValue]) {
continue;
}
ShowEpisode *showEpisode = [self showEpisodeWithShow:show episodeNumber:[result objectForKey:@"episodeNumber"] seasonNumber:[result objectForKey:@"seasonNumber"]];
showEpisode.name = [result objectForKey:@"title"];
showEpisode.theTVDBID = [result objectForKey:@"id"];
showEpisode.shortSummary = [result objectForKey:@"shortSummary"];
showEpisode.artworkURL = [result objectForKey:@"artworkURL"];
showEpisode.lastSyncDate = [MLTVShowInfoGrabber serverTime];
}
show.lastSyncDate = [MLTVShowInfoGrabber serverTime];
}
- (void)tvShowInfoGrabberDidFinishGrabbing:(MLTVShowInfoGrabber *)grabber
{
Show *show = grabber.userData;
NSArray *results = grabber.results;
if ([results count] > 0) {
NSDictionary *result = [results objectAtIndex:0];
NSString *showId = [result objectForKey:@"id"];
show.theTVDBID = showId;
show.name = [result objectForKey:@"title"];
show.shortSummary = [result objectForKey:@"shortSummary"];
show.releaseYear = [result objectForKey:@"releaseYear"];
// Fetch episodes info
MLTVShowEpisodesInfoGrabber *grabber = [[[MLTVShowEpisodesInfoGrabber alloc] init] autorelease];
grabber.delegate = self;
grabber.userData = show;
[grabber lookUpForShowID:showId];
}
else {
// Not found.
show.lastSyncDate = [MLTVShowInfoGrabber serverTime];
}
}
- (void)tvShowInfoGrabberDidFetchServerTime:(MLTVShowInfoGrabber *)grabber
{
Show *show = grabber.userData;
[[NSUserDefaults standardUserDefaults] setInteger:[[MLTVShowInfoGrabber serverTime] integerValue] forKey:kLastTVDBUpdateServerTime];
// First fetch the Show ID
MLTVShowInfoGrabber *showInfoGrabber = [[[MLTVShowInfoGrabber alloc] init] autorelease];
showInfoGrabber.delegate = self;
showInfoGrabber.userData = show;
[showInfoGrabber lookUpForTitle:show.name];
}
#endif
- (void)fetchMetaDataForShow:(Show *)show
{
// First fetch the serverTime, so that we can update each entry.
......@@ -234,7 +308,10 @@
}];
}];
#else
abort();
MLTVShowInfoGrabber *grabber = [[[MLTVShowInfoGrabber alloc] init] autorelease];
grabber.delegate = self;
grabber.userData = show;
[grabber fetchServerTime];
#endif
}
......@@ -273,6 +350,24 @@
* File auto detection
*/
#if !HAVE_BLOCK
- (void)movieInfoGrabberDidFinishGrabbing:(MLMovieInfoGrabber *)grabber
{
NSNumber *yes = [NSNumber numberWithBool:YES];
NSArray *results = grabber.results;
File *file = grabber.userData;
if ([results count] > 0) {
NSDictionary *result = [results objectAtIndex:0];
file.artworkURL = [result objectForKey:@"artworkURL"];
file.title = [result objectForKey:@"title"];
file.shortSummary = [result objectForKey:@"shortSummary"];
file.releaseYear = [result objectForKey:@"releaseYear"];
}
file.hasFetchedInfo = yes;
}
#endif
- (void)fetchMetaDataForFile:(File *)file
{
NSNumber *yes = [NSNumber numberWithBool:YES];
......@@ -285,7 +380,11 @@
}
// Go online and fetch info.
// We don't care about keeping a reference to track the item during its life span
// because we are a singleton
MLMovieInfoGrabber *grabber = [[[MLMovieInfoGrabber alloc] init] autorelease];
#if HAVE_BLOCK
[grabber lookUpForTitle:file.title andExecuteBlock:^(NSError *err){
if (err)
......@@ -302,12 +401,15 @@
file.hasFetchedInfo = yes;
}];
#else
abort();
grabber.userData = file;
grabber.delegate = self;
[grabber lookUpForTitle:file.title];
#endif
}
- (void)addFilePath:(NSString *)filePath
{
NSLog(@"Adding %@", filePath);
NSString *url = [NSURL fileURLWithPath:filePath];
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
NSString *title = [filePath lastPathComponent];
......@@ -348,13 +450,11 @@
NSUInteger count = [filepaths count];
NSMutableArray *fetchPredicates = [NSMutableArray arrayWithCapacity:count];
NSMutableDictionary *urlToObject = [NSMutableDictionary dictionaryWithCapacity:count];
NSMutableArray *filePathsToAdd = [NSMutableArray arrayWithCapacity:count];
// Prepare a fetch request for all items
for (NSString *path in filepaths) {
NSURL *url = [NSURL fileURLWithPath:path];
NSString *urlDescription = [url description];
[filePathsToAdd addObject:urlDescription];
[fetchPredicates addObject:[NSPredicate predicateWithFormat:@"url == %@", urlDescription]];
[urlToObject setObject:url forKey:urlDescription];
}
......@@ -367,11 +467,12 @@
NSArray *dbResults = [[self managedObjectContext] executeFetchRequest:request error:nil];
NSLog(@"Done");
NSMutableArray *filePathsToAdd = [NSMutableArray arrayWithArray:filepaths];
// Remove objects that are already in db.
for (NSManagedObjectContext *dbResult in dbResults) {
NSString *url = [dbResult valueForKey:@"url"];
[filePathsToAdd removeObject:url];
[filePathsToAdd removeObject:[urlToObject objectForKey:url]];
}
// Add only the newly added items
......@@ -379,6 +480,17 @@
[self addFilePath:path];
}
#if !HAVE_BLOCK
- (void)tvShowInfoGrabber:(MLTVShowInfoGrabber *)grabber didFetchUpdates:(NSArray *)updates
{
NSFetchRequest *request = [self fetchRequestForEntity:@"Show"];
[request setPredicate:[NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"theTVDBID"] rightExpression:[NSExpression expressionForConstantValue:updates] modifier:NSDirectPredicateModifier type:NSInPredicateOperatorType options:0]];
NSArray *results = [[self managedObjectContext] executeFetchRequest:request error:nil];
for (Show *show in results)
[self fetchMetaDataForShow:show];
}
#endif
- (void)startUpdateDB
{
// FIXME
......@@ -396,15 +508,19 @@
for (Show *show in results)
[self fetchMetaDataForShow:show];
NSNumber *lastServerTime = [NSNumber numberWithInteger:[[NSUserDefaults standardUserDefaults] integerForKey:kLastTVDBUpdateServerTime]];
#if HAVE_BLOCK
NSInteger lastServerTime = [[NSUserDefaults standardUserDefaults] integerForKey:kLastTVDBUpdateServerTime];
[MLTVShowInfoGrabber fetchUpdatesSinceServerTime:[NSNumber numberWithInteger:lastServerTime] andExecuteBlock:^(NSArray *updates){
[MLTVShowInfoGrabber fetchUpdatesSinceServerTime:lastServerTime andExecuteBlock:^(NSArray *updates){
NSFetchRequest *request = [self fetchRequestForEntity:@"Show"];
[request setPredicate:[NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"theTVDBID"] rightExpression:[NSExpression expressionForConstantValue:updates] modifier:NSDirectPredicateModifier type:NSInPredicateOperatorType options:0]];
NSArray *results = [[self managedObjectContext] executeFetchRequest:request error:nil];
for (Show *show in results)
[self fetchMetaDataForShow:show];
}];
#else
MLTVShowInfoGrabber *grabber = [[[MLTVShowInfoGrabber alloc] init] autorelease];
grabber.delegate = self;
[grabber fetchUpdatesSinceServerTime:lastServerTime];
#endif
/* Update every hour - FIXME: Preferences key */
[self performSelector:@selector(startUpdateDB) withObject:nil afterDelay:60 * 60];
......
......@@ -15,10 +15,15 @@
id<MLMovieInfoGrabberDelegate> _delegate;
#if HAVE_BLOCK
void (^_block)(NSError *);
#else
id _userData;
#endif
}
@property (readwrite, assign) id<MLMovieInfoGrabberDelegate> delegate;
#if !HAVE_BLOCK
@property (readwrite, retain) id userData;
#endif
@property (readonly, retain) NSArray *results;
- (void)lookUpForTitle:(NSString *)title;
......
......@@ -28,8 +28,14 @@
@implementation MLMovieInfoGrabber
@synthesize delegate=_delegate;
@synthesize results=_results;
#if !HAVE_BLOCK
@synthesize userData=_userData;
#endif
- (void)dealloc
{
#if !HAVE_BLOCK
[_userData release];
#endif
[_data release];
[_connection release];
[_results release];
......@@ -44,7 +50,6 @@
{
NSString *escapedString = [title stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:TMDB_QUERY_SEARCH, TMDB_HOSTNAME, escapedString, TMDB_API_KEY]];
NSLog(@"Accessing %@", url);
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15];
[_connection cancel];
[_connection release];
......@@ -108,12 +113,15 @@
continue;
NSString *title = [node stringValueForXPath:@"./title"];
NSString *release = [node stringValueForXPath:@"./release"];
NSDateFormatter *inputFormatter = [[[NSDateFormatter alloc] init] autorelease];
[inputFormatter setDateFormat:@"yyyy-MM-dd"];
NSDateFormatter *outputFormatter = [[[NSDateFormatter alloc] init] autorelease];
[outputFormatter setDateFormat:@"yyyy"];
NSDate *releaseDate = [inputFormatter dateFromString:release];
NSString *releaseYear = releaseDate ? [outputFormatter stringFromDate:releaseDate] : nil;
NSString *releaseYear = nil;
if (release) {
NSDateFormatter *inputFormatter = [[[NSDateFormatter alloc] init] autorelease];
[inputFormatter setDateFormat:@"yyyy-MM-dd"];
NSDateFormatter *outputFormatter = [[[NSDateFormatter alloc] init] autorelease];
[outputFormatter setDateFormat:@"yyyy"];
NSDate *releaseDate = [inputFormatter dateFromString:release];