Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
IMDB id fetching fix
Browse files Browse the repository at this point in the history
  • Loading branch information
johan committed Aug 4, 2013
1 parent 197ba4f commit e84df23
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 40 deletions.
16 changes: 8 additions & 8 deletions Traktable.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@
046C9BD916C168880003AD64 /* FMDatabaseQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 046C9BC816C166AE0003AD64 /* FMDatabaseQueue.m */; };
046C9BDB16C168880003AD64 /* FMResultSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 046C9BCB16C166AE0003AD64 /* FMResultSet.m */; };
046C9BDC16C16F490003AD64 /* iTraktor.db in Resources */ = {isa = PBXBuildFile; fileRef = 046C9BCF16C167B80003AD64 /* iTraktor.db */; };
04714E2316D2BF2900A308F7 /* config.plist in Resources */ = {isa = PBXBuildFile; fileRef = 04714E2216D2BF2900A308F7 /* config.plist */; };
04714E2516D2BFBB00A308F7 /* config-example.plist in Resources */ = {isa = PBXBuildFile; fileRef = 04714E2416D2BFBB00A308F7 /* config-example.plist */; };
04714E2816D2C59900A308F7 /* ITConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 04714E2716D2C59900A308F7 /* ITConfig.m */; };
04714E6216D2D6D500A308F7 /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 04714E6116D2D6D500A308F7 /* dsa_pub.pem */; };
04714E8116D2DEC500A308F7 /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 04714E7F16D2DEC000A308F7 /* Sparkle.framework */; };
0481386A16CA8C6000E682A0 /* PrefIndexViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0481386916CA8C6000E682A0 /* PrefIndexViewController.m */; };
0481386B16CA8DA100E682A0 /* MASPreferencesWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0481386616CA8BF400E682A0 /* MASPreferencesWindowController.m */; };
Expand All @@ -73,6 +71,8 @@
048DF20A16DFFF17004B064A /* sync.png in Resources */ = {isa = PBXBuildFile; fileRef = 048DF20916DFFF17004B064A /* sync.png */; };
049ACB0916C2AD43007F103C /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 049ACB0816C2AD43007F103C /* CFNetwork.framework */; };
049C48BE16C0223B00CC9A0E /* ITMovie.m in Sources */ = {isa = PBXBuildFile; fileRef = 049C48BD16C0223B00CC9A0E /* ITMovie.m */; };
04B284A717AE62E2005F9197 /* config.plist in Resources */ = {isa = PBXBuildFile; fileRef = 04B284A517AE62E2005F9197 /* config.plist */; };
04B284A817AE62E2005F9197 /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 04B284A617AE62E2005F9197 /* dsa_pub.pem */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -174,11 +174,9 @@
046C9BCB16C166AE0003AD64 /* FMResultSet.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FMResultSet.m; sourceTree = "<group>"; };
046C9BCF16C167B80003AD64 /* iTraktor.db */ = {isa = PBXFileReference; lastKnownFileType = file; path = iTraktor.db; sourceTree = "<group>"; };
046C9BD016C1685B0003AD64 /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; };
04714E2216D2BF2900A308F7 /* config.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = config.plist; sourceTree = "<group>"; };
04714E2416D2BFBB00A308F7 /* config-example.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "config-example.plist"; sourceTree = "<group>"; };
04714E2616D2C59900A308F7 /* ITConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ITConfig.h; sourceTree = "<group>"; };
04714E2716D2C59900A308F7 /* ITConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ITConfig.m; sourceTree = "<group>"; };
04714E6116D2D6D500A308F7 /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsa_pub.pem; sourceTree = "<group>"; };
04714E7F16D2DEC000A308F7 /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Sparkle.framework; sourceTree = "<group>"; };
0481386316CA8BF400E682A0 /* MASPreferencesViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASPreferencesViewController.h; sourceTree = "<group>"; };
0481386416CA8BF400E682A0 /* MASPreferencesWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MASPreferencesWindow.xib; sourceTree = "<group>"; };
Expand All @@ -201,6 +199,8 @@
049ACB0816C2AD43007F103C /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
049C48BC16C0223B00CC9A0E /* ITMovie.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ITMovie.h; sourceTree = "<group>"; };
049C48BD16C0223B00CC9A0E /* ITMovie.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ITMovie.m; sourceTree = "<group>"; };
04B284A517AE62E2005F9197 /* config.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = config.plist; path = "../../Traktable-NonGit/config.plist"; sourceTree = "<group>"; };
04B284A617AE62E2005F9197 /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = dsa_pub.pem; path = "../../Traktable-NonGit/dsa_pub.pem"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -327,9 +327,9 @@
042F07E916BC19DB00A0CE9E /* Supporting Files */ = {
isa = PBXGroup;
children = (
04B284A517AE62E2005F9197 /* config.plist */,
04B284A617AE62E2005F9197 /* dsa_pub.pem */,
048DF20916DFFF17004B064A /* sync.png */,
04714E6116D2D6D500A308F7 /* dsa_pub.pem */,
04714E2216D2BF2900A308F7 /* config.plist */,
04714E2416D2BFBB00A308F7 /* config-example.plist */,
0437204216CEF823003B8AB6 /* menuicon.png */,
046C9BCF16C167B80003AD64 /* iTraktor.db */,
Expand Down Expand Up @@ -499,14 +499,14 @@
0469CC1916CBF19F006863B7 /* README.md in Resources */,
0437203316CEF3ED003B8AB6 /* icon.icns in Resources */,
0437204316CEF823003B8AB6 /* menuicon.png in Resources */,
04714E2316D2BF2900A308F7 /* config.plist in Resources */,
04714E2516D2BFBB00A308F7 /* config-example.plist in Resources */,
04714E6216D2D6D500A308F7 /* dsa_pub.pem in Resources */,
048DF1F816DEC3ED004B064A /* PrefSyncViewController.xib in Resources */,
048DF1FA16DECC6B004B064A /* PrefUpdateViewController.h in Resources */,
048DF1FE16DECD14004B064A /* PrefUpdateViewController.xib in Resources */,
048DF20616DFF6DD004B064A /* Growl Registration Ticket.growlRegDict in Resources */,
048DF20A16DFFF17004B064A /* sync.png in Resources */,
04B284A717AE62E2005F9197 /* config.plist in Resources */,
04B284A817AE62E2005F9197 /* dsa_pub.pem in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
31 changes: 23 additions & 8 deletions Traktable/IMDB.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ @implementation IMDB
+ (NSString * )callAPI:(NSString *)title year:(NSString *)aYear {

NSString *requestUrl = [NSString stringWithFormat:@"http://www.omdbapi.com/?t=%@&y=%@", [title stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding], aYear];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:requestUrl]];
[request setHTTPMethod: @"GET"];

Expand All @@ -34,18 +35,32 @@ + (NSString * )callAPI:(NSString *)title year:(NSString *)aYear {
if(data == nil)
return @"";

NSDictionary *responseDict = [[SBJsonParser alloc] objectWithData:data];
id responseDict;


responseDict = [[SBJsonParser alloc] objectWithData:data];

Class hasNSJSON = NSClassFromString(@"NSJSONSerialization");

if(hasNSJSON != nil) {
responseDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
}

if([[responseDict objectForKey:@"Response"] isEqualToString:@"False"]) {
return @"";
} else {
NSString *responseD = [responseDict objectForKey:@"imdbID"];
if([responseDict isKindOfClass:[NSDictionary class]]) {

if(responseD == nil)
if([[responseDict objectForKey:@"Response"] isEqualToString:@"False"]) {
return @"";

return responseD;
} else {
NSString *responseD = [responseDict objectForKey:@"imdbID"];

if(responseD == nil)
return @"";

return responseD;
}
}

return @"";
}

+ (NSString * )getImdbIdByTitle:(NSString *)title year:(NSString *)aYear {
Expand Down
13 changes: 6 additions & 7 deletions Traktable/objc/SBJsonStreamParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,19 @@ typedef enum {
- object -> NSMutableDictionary
- true -> NSNumber's -numberWithBool:YES
- false -> NSNumber's -numberWithBool:NO
- integer up to 19 digits -> NSNumber's -numberWithLongLong:
- all other numbers -> NSDecimalNumber
- number -> NSNumber
Since Objective-C doesn't have a dedicated class for boolean values,
these turns into NSNumber instances. However, since these are
initialised with the -initWithBool: method they round-trip back to JSON
properly. In other words, they won't silently suddenly become 0 or 1;
they'll be represented as 'true' and 'false' again.
As an optimisation integers up to 19 digits in length (the max length
for signed long long integers) turn into NSNumber instances, while
complex ones turn into NSDecimalNumber instances. We can thus avoid any
loss of precision as JSON allows ridiculously large numbers.
Integers are parsed into either a `long long` or `unsigned long long`
type if they fit, else a `double` is used. All real & exponential numbers
are represented using a `double`. Previous versions of this library used
an NSDecimalNumber in some cases, but this is no longer the case.
See also SBJsonStreamParserAdapter for more information.
*/
Expand Down
18 changes: 12 additions & 6 deletions Traktable/objc/SBJsonStreamParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,21 @@ - (SBJsonStreamParserStatus)parse:(NSData *)data_ {
break;

case sbjson_token_integer: {
NSString *string = [[NSString alloc] initWithBytes:token length:token_len encoding:NSUTF8StringEncoding];
[delegate parser:self foundNumber:[NSDecimalNumber decimalNumberWithString:string]];
[state parser:self shouldTransitionTo:tok];
break;
const int UNSIGNED_LONG_LONG_MAX_DIGITS = 20;
if (token_len <= UNSIGNED_LONG_LONG_MAX_DIGITS) {
if (*token == '-')
[delegate parser:self foundNumber: @(strtoll(token, NULL, 10))];
else
[delegate parser:self foundNumber: @(strtoull(token, NULL, 10))];

[state parser:self shouldTransitionTo:tok];
break;
}
}
// FALLTHROUGH

case sbjson_token_real: {
NSString *string = [[NSString alloc] initWithBytes:token length:token_len encoding:NSUTF8StringEncoding];
[delegate parser:self foundNumber:[NSDecimalNumber decimalNumberWithString:string]];
[delegate parser:self foundNumber: @(strtod(token, NULL))];
[state parser:self shouldTransitionTo:tok];
break;
}
Expand Down
15 changes: 4 additions & 11 deletions Traktable/objc/SBJsonStreamWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#import "SBJsonStreamWriter.h"
#import "SBJsonStreamWriterState.h"

static NSNumber *kNotANumber;
static NSNumber *kTrue;
static NSNumber *kFalse;
static NSNumber *kPositiveInfinity;
Expand All @@ -55,7 +54,6 @@ @implementation SBJsonStreamWriter
@synthesize sortKeysComparator;

+ (void)initialize {
kNotANumber = [NSDecimalNumber notANumber];
kPositiveInfinity = [NSNumber numberWithDouble:+HUGE_VAL];
kNegativeInfinity = [NSNumber numberWithDouble:-HUGE_VAL];
kTrue = [NSNumber numberWithBool:YES];
Expand Down Expand Up @@ -340,7 +338,7 @@ - (BOOL)writeNumber:(NSNumber*)number {
self.error = @"-Infinity is not a valid number in JSON";
return NO;

} else if ([kNotANumber isEqualToNumber:number]) {
} else if (isnan([number doubleValue])) {
self.error = @"NaN is not a valid number in JSON";
return NO;
}
Expand All @@ -356,15 +354,10 @@ - (BOOL)writeNumber:(NSNumber*)number {
case 'C': case 'I': case 'S': case 'L': case 'Q':
len = snprintf(num, sizeof num, "%llu", [number unsignedLongLongValue]);
break;
case 'f': case 'd': default:
if ([number isKindOfClass:[NSDecimalNumber class]]) {
char const *utf8 = [[number stringValue] UTF8String];
[delegate writer:self appendBytes:utf8 length: strlen(utf8)];
[state transitionState:self];
return YES;
}
len = snprintf(num, sizeof num, "%.17g", [number doubleValue]);
case 'f': case 'd': default: {
len = snprintf(num, sizeof num, "%.17g", [number doubleValue]);
break;
}
}
[delegate writer:self appendBytes:num length: len];
[state transitionState:self];
Expand Down

0 comments on commit e84df23

Please sign in to comment.