Use NSJSONSerialization instead of JSONKit
This commit is contained in:
1 parent
176f2ca6c8
commit
b321903333
2 files changed
+53
-42
No files matched your search
@@ -9,7 +9,6 @@
|
||||
#import <MP42Foundation/MP42Metadata.h>
|
||||
#import <MP42Foundation/MP42Ratings.h>
|
||||
#import <MP42Foundation/MP42Languages.h>
|
||||
#import <MP42Foundation/JSONKit.h>
|
||||
|
||||
#import "SBMetadataSearchController.h"
|
||||
|
||||
@@ -29,9 +28,10 @@
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/search/movie?api_key=%@&query=%@&language=%@", API_KEY, [MetadataImporter urlEncoded:aMovieTitle], lang]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
return [TheMovieDB3 metadataForResults:d];
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
return [TheMovieDB3 metadataForResults:d];
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
@@ -56,10 +56,9 @@
|
||||
NSArray *posters = [r valueForKeyPath:@"images.posters"];
|
||||
|
||||
if (jsonData && posters && [posters isKindOfClass:[NSArray class]]) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *config = [jsonDecoder objectWithData:jsonData];
|
||||
NSDictionary *config = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
|
||||
if ([config valueForKey:@"images"]) {
|
||||
if ([config isKindOfClass:[NSDictionary class]] && [config valueForKey:@"images"]) {
|
||||
NSString *imageBaseUrl = [[config valueForKey:@"images"] valueForKey:@"secure_base_url"];
|
||||
NSString *posterThumbnailSize = [[[config valueForKey:@"images"] valueForKey:@"poster_sizes"] objectAtIndex:0];
|
||||
NSString *backdropThumbnailSize = [[[config valueForKey:@"images"] valueForKey:@"backdrop_sizes"] objectAtIndex:0];
|
||||
@@ -102,13 +101,15 @@
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/movie/%@?api_key=%@&language=%@&append_to_response=casts,releases,images", theMovieDBID, API_KEY, lang]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
MP42Metadata *r = [TheMovieDB3 metadataForResult:d language:lang];
|
||||
if (r) {
|
||||
[aMetadata mergeMetadata:r];
|
||||
}
|
||||
aMetadata = [self artworksForResult:d metadata:aMetadata];
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
|
||||
MP42Metadata *r = [TheMovieDB3 metadataForResult:d language:lang];
|
||||
if (r) {
|
||||
[aMetadata mergeMetadata:r];
|
||||
}
|
||||
aMetadata = [self artworksForResult:d metadata:aMetadata];
|
||||
}
|
||||
}
|
||||
|
||||
return aMetadata;
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#import <MP42Foundation/MP42Metadata.h>
|
||||
#import <MP42Foundation/MP42Ratings.h>
|
||||
#import <MP42Foundation/JSONKit.h>
|
||||
|
||||
#import "iTunesStore.h"
|
||||
#import "SBMetadataSearchController.h"
|
||||
@@ -17,26 +16,40 @@
|
||||
|
||||
#pragma mark iTunes stores
|
||||
|
||||
- (NSArray *) languages {
|
||||
NSString* iTunesStoresJSON = [[NSBundle mainBundle] pathForResource:@"iTunesStores" ofType:@"json"];
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSArray *iTunesStores = [jsonDecoder objectWithData:[NSData dataWithContentsOfFile:iTunesStoresJSON]];
|
||||
NSMutableArray *results = [[NSMutableArray alloc] initWithCapacity:[iTunesStores count]];
|
||||
for (NSDictionary *store in iTunesStores) {
|
||||
[results addObject:[NSString stringWithFormat:@"%@ (%@)", [store valueForKey:@"country"], [store valueForKey:@"language"]]];
|
||||
}
|
||||
- (NSArray<NSString *> *)languages {
|
||||
NSString *iTunesStoresJSON = [[NSBundle mainBundle] pathForResource:@"iTunesStores" ofType:@"json"];
|
||||
NSData *data = [NSData dataWithContentsOfFile:iTunesStoresJSON];
|
||||
|
||||
NSMutableArray<NSString *> *results = [[NSMutableArray alloc] init];
|
||||
|
||||
if (data) {
|
||||
NSArray *iTunesStores = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
||||
|
||||
if ([iTunesStores isKindOfClass:[NSArray class]]) {
|
||||
for (NSDictionary *store in iTunesStores) {
|
||||
[results addObject:[NSString stringWithFormat:@"%@ (%@)", [store valueForKey:@"country"], [store valueForKey:@"language"]]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [results autorelease];
|
||||
}
|
||||
|
||||
+ (NSDictionary *) getStoreFor:(NSString *)aLanguageString {
|
||||
NSString* iTunesStoresJSON = [[NSBundle mainBundle] pathForResource:@"iTunesStores" ofType:@"json"];
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSArray *iTunesStores = [jsonDecoder objectWithData:[NSData dataWithContentsOfFile:iTunesStoresJSON]];
|
||||
for (NSDictionary *store in iTunesStores) {
|
||||
if (aLanguageString && [aLanguageString isEqualToString:[NSString stringWithFormat:@"%@ (%@)", [store valueForKey:@"country"], [store valueForKey:@"language"]]]) {
|
||||
return store;
|
||||
}
|
||||
}
|
||||
+ (NSDictionary *)getStoreFor:(NSString *)aLanguageString {
|
||||
NSString *iTunesStoresJSON = [[NSBundle mainBundle] pathForResource:@"iTunesStores" ofType:@"json"];
|
||||
NSData *data = [NSData dataWithContentsOfFile:iTunesStoresJSON];
|
||||
|
||||
if (data) {
|
||||
NSArray *iTunesStores = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
||||
|
||||
if ([iTunesStores isKindOfClass:[NSArray class]]) {
|
||||
for (NSDictionary *store in iTunesStores) {
|
||||
if (aLanguageString && [aLanguageString isEqualToString:[NSString stringWithFormat:@"%@ (%@)", [store valueForKey:@"country"], [store valueForKey:@"language"]]]) {
|
||||
return store;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -119,9 +132,10 @@ NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&attribute=showTerm&entity=tvEpisode&limit=200", country, [language lowercaseString], [MetadataImporter urlEncoded:aSeriesName]]];
|
||||
}
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
NSArray *results = [iTunesStore metadataForResults:d store:store];
|
||||
if (([results count] == 0) && ![aLanguage isEqualToString:@"USA (English)"]) {
|
||||
@@ -158,8 +172,7 @@ NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=tvEpisode", country, [language lowercaseString], [MetadataImporter urlEncoded:[NSString stringWithFormat:@"%@ %@", aSeriesName, aEpisodeTitle]]]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
NSArray *results = [iTunesStore metadataForResults:d store:store];
|
||||
return [results firstObject];
|
||||
@@ -178,8 +191,7 @@ NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=movie", country, language, [MetadataImporter urlEncoded:aMovieName]]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
NSArray *results = [iTunesStore metadataForResults:d store:store];
|
||||
return [results firstObject];
|
||||
@@ -203,8 +215,7 @@ NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=movie&limit=150", country, language, [MetadataImporter urlEncoded:aMovieTitle]]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
return [iTunesStore metadataForResults:d store:store];
|
||||
}
|
||||
@@ -224,8 +235,7 @@ NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/lookup?country=%@&lang=%@&id=%@", country, [language lowercaseString], [[aMetadata tagsDict] valueForKey:@"playlistID"]]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (jsonData) {
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
NSDictionary *d = [jsonDecoder objectWithData:jsonData];
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
NSArray *resultsArray = [d valueForKey:@"results"];
|
||||
if ([resultsArray count] > 0) {
|
||||
|
||||
Reference in new issue
Block a user