Rename SBCachePolicy values make it easier to use them in Swift.
This commit is contained in:
1 parent
bad1e46c6b
commit
b23ba4bda3
8 files changed
+23
-23
No files matched your search
@@ -14,9 +14,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@interface SBMetadataHelper : NSObject
|
@interface SBMetadataHelper : NSObject
|
||||||
|
|
||||||
typedef NS_ENUM(NSUInteger, SBCachePolicy) {
|
typedef NS_ENUM(NSUInteger, SBCachePolicy) {
|
||||||
SBDefaultPolicy,
|
SBCachePolicyDefault,
|
||||||
SBReturnCacheElseLoad,
|
SBCachePolicyReturnCacheElseLoad,
|
||||||
SBReloadIgnoringLocalCacheData,
|
SBCachePolicyReloadIgnoringLocalCacheData,
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma mark Helper routines
|
#pragma mark Helper routines
|
||||||
|
|||||||
@@ -163,13 +163,13 @@ static id<MP42Logging> _logger;
|
|||||||
|
|
||||||
NSURLRequestCachePolicy cachePolicy;
|
NSURLRequestCachePolicy cachePolicy;
|
||||||
switch (policy) {
|
switch (policy) {
|
||||||
case SBReturnCacheElseLoad:
|
case SBCachePolicyReturnCacheElseLoad:
|
||||||
cachePolicy = NSURLRequestReturnCacheDataElseLoad;
|
cachePolicy = NSURLRequestReturnCacheDataElseLoad;
|
||||||
break;
|
break;
|
||||||
case SBReloadIgnoringLocalCacheData:
|
case SBCachePolicyReloadIgnoringLocalCacheData:
|
||||||
cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
|
cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
|
||||||
break;
|
break;
|
||||||
case SBDefaultPolicy:
|
case SBCachePolicyDefault:
|
||||||
default:
|
default:
|
||||||
cachePolicy = NSURLRequestUseProtocolCachePolicy;
|
cachePolicy = NSURLRequestUseProtocolCachePolicy;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/search/movie?api_key=%@&query=%@&language=%@",
|
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/search/movie?api_key=%@&query=%@&language=%@",
|
||||||
API_KEY, [SBMetadataHelper urlEncoded:aMovieTitle], lang]];
|
API_KEY, [SBMetadataHelper urlEncoded:aMovieTitle], lang]];
|
||||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBDefaultPolicy];
|
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBCachePolicyDefault];
|
||||||
|
|
||||||
if (jsonData) {
|
if (jsonData) {
|
||||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
|
|
||||||
// load image variables from configuration
|
// load image variables from configuration
|
||||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/configuration?api_key=%@", API_KEY]];
|
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/configuration?api_key=%@", API_KEY]];
|
||||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBDefaultPolicy];
|
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBCachePolicyDefault];
|
||||||
NSArray *posters = r[@"images"][@"posters"];
|
NSArray *posters = r[@"images"][@"posters"];
|
||||||
|
|
||||||
if (jsonData && posters && [posters isKindOfClass:[NSArray class]]) {
|
if (jsonData && posters && [posters isKindOfClass:[NSArray class]]) {
|
||||||
@@ -103,7 +103,7 @@
|
|||||||
|
|
||||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/movie/%@?api_key=%@&language=%@&append_to_response=casts,releases,images",
|
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]];
|
theMovieDBID, API_KEY, lang]];
|
||||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBDefaultPolicy];
|
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBCachePolicyDefault];
|
||||||
|
|
||||||
if (jsonData) {
|
if (jsonData) {
|
||||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
@"Accept" : @"application/json"};
|
@"Accept" : @"application/json"};
|
||||||
|
|
||||||
NSURL *url = [NSURL URLWithString:@"https://api.thetvdb.com/login"];
|
NSURL *url = [NSURL URLWithString:@"https://api.thetvdb.com/login"];
|
||||||
NSData *data = [SBMetadataHelper downloadDataFromURL:url HTTPMethod:@"POST" HTTPBody:jsonApiKey headerOptions:headerOptions cachePolicy:SBDefaultPolicy];
|
NSData *data = [SBMetadataHelper downloadDataFromURL:url HTTPMethod:@"POST" HTTPBody:jsonApiKey headerOptions:headerOptions cachePolicy:SBCachePolicyDefault];
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
id response = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
|
id response = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
|
||||||
@@ -171,7 +171,7 @@
|
|||||||
@"Content-Type" : @"application/json",
|
@"Content-Type" : @"application/json",
|
||||||
@"Accept" : @"application/json",
|
@"Accept" : @"application/json",
|
||||||
@"Accept-Language" : language};
|
@"Accept-Language" : language};
|
||||||
NSData *data = [SBMetadataHelper downloadDataFromURL:url HTTPMethod:@"GET" HTTPBody:nil headerOptions:headerOptions cachePolicy:SBDefaultPolicy];
|
NSData *data = [SBMetadataHelper downloadDataFromURL:url HTTPMethod:@"GET" HTTPBody:nil headerOptions:headerOptions cachePolicy:SBCachePolicyDefault];
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
NSString *country = store[@"country2"];
|
NSString *country = store[@"country2"];
|
||||||
NSString *language = store[@"language2"];
|
NSString *language = store[@"language2"];
|
||||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=tvEpisode", country, language.lowercaseString, [SBMetadataHelper urlEncoded:[NSString stringWithFormat:@"%@ %@", aSeriesName, aEpisodeTitle]]]];
|
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=tvEpisode", country, language.lowercaseString, [SBMetadataHelper urlEncoded:[NSString stringWithFormat:@"%@ %@", aSeriesName, aEpisodeTitle]]]];
|
||||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBDefaultPolicy];
|
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBCachePolicyDefault];
|
||||||
if (jsonData) {
|
if (jsonData) {
|
||||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||||
@@ -90,7 +90,7 @@
|
|||||||
NSString *country = store[@"country2"];
|
NSString *country = store[@"country2"];
|
||||||
NSString *language = store[@"language2"];
|
NSString *language = store[@"language2"];
|
||||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=movie", country, language, [SBMetadataHelper urlEncoded:aMovieName]]];
|
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=movie", country, language, [SBMetadataHelper urlEncoded:aMovieName]]];
|
||||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBDefaultPolicy];
|
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBCachePolicyDefault];
|
||||||
if (jsonData) {
|
if (jsonData) {
|
||||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||||
@@ -191,7 +191,7 @@ static NSInteger sortSBMetadataResult(id ep1, id ep2, void *context)
|
|||||||
country, language.lowercaseString, [SBMetadataHelper urlEncoded:aSeriesName]]];
|
country, language.lowercaseString, [SBMetadataHelper urlEncoded:aSeriesName]]];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBDefaultPolicy];
|
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBCachePolicyDefault];
|
||||||
|
|
||||||
if (jsonData) {
|
if (jsonData) {
|
||||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||||
@@ -232,7 +232,7 @@ static NSInteger sortSBMetadataResult(id ep1, id ep2, void *context)
|
|||||||
lookupUrl = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/lookup?country=%@&id=%ld&entity=tvEpisode&limit=200",
|
lookupUrl = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/lookup?country=%@&id=%ld&entity=tvEpisode&limit=200",
|
||||||
country, (long)iTunesID]];
|
country, (long)iTunesID]];
|
||||||
|
|
||||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:lookupUrl cachePolicy:SBDefaultPolicy];
|
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:lookupUrl cachePolicy:SBCachePolicyDefault];
|
||||||
|
|
||||||
if (jsonData) {
|
if (jsonData) {
|
||||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||||
@@ -282,7 +282,7 @@ static NSInteger sortSBMetadataResult(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, [SBMetadataHelper urlEncoded:aMovieTitle]]];
|
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=movie&limit=150", country, language, [SBMetadataHelper urlEncoded:aMovieTitle]]];
|
||||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBDefaultPolicy];
|
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBCachePolicyDefault];
|
||||||
|
|
||||||
if (jsonData) {
|
if (jsonData) {
|
||||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||||
@@ -305,7 +305,7 @@ static NSInteger sortSBMetadataResult(id ep1, id ep2, void *context)
|
|||||||
NSString *language2 = store[@"language2"];
|
NSString *language2 = store[@"language2"];
|
||||||
|
|
||||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/lookup?country=%@&lang=%@&id=%@", country, language2.lowercaseString, metadata[SBMetadataResultPlaylistID]]];
|
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/lookup?country=%@&lang=%@&id=%@", country, language2.lowercaseString, metadata[SBMetadataResultPlaylistID]]];
|
||||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBDefaultPolicy];
|
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBCachePolicyDefault];
|
||||||
|
|
||||||
if (jsonData) {
|
if (jsonData) {
|
||||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||||
@@ -322,7 +322,7 @@ static NSInteger sortSBMetadataResult(id ep1, id ep2, void *context)
|
|||||||
|
|
||||||
- (SBMetadataResult *)loadMovieMetadata:(SBMetadataResult *)metadata language:(NSString *)language
|
- (SBMetadataResult *)loadMovieMetadata:(SBMetadataResult *)metadata language:(NSString *)language
|
||||||
{
|
{
|
||||||
NSData *xmlData = [SBMetadataHelper downloadDataFromURL:[NSURL URLWithString:metadata[SBMetadataResultITunesURL]] cachePolicy:SBDefaultPolicy];
|
NSData *xmlData = [SBMetadataHelper downloadDataFromURL:[NSURL URLWithString:metadata[SBMetadataResultITunesURL]] cachePolicy:SBCachePolicyDefault];
|
||||||
if (xmlData) {
|
if (xmlData) {
|
||||||
NSDictionary *store = [SBiTunesStore getStoreFor:language];
|
NSDictionary *store = [SBiTunesStore getStoreFor:language];
|
||||||
NSXMLDocument *xml = [[NSXMLDocument alloc] initWithData:xmlData options:NSXMLDocumentTidyHTML error:NULL];
|
NSXMLDocument *xml = [[NSXMLDocument alloc] initWithData:xmlData options:NSXMLDocumentTidyHTML error:NULL];
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
// Get the data outside the main thread
|
// Get the data outside the main thread
|
||||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||||
if (!self.isCancelled) {
|
if (!self.isCancelled) {
|
||||||
self.data = [SBMetadataHelper downloadDataFromURL:self.url cachePolicy:SBDefaultPolicy];
|
self.data = [SBMetadataHelper downloadDataFromURL:self.url cachePolicy:SBCachePolicyDefault];
|
||||||
self.version = 2;
|
self.version = 2;
|
||||||
// We got the data, tell the controller to update the view
|
// We got the data, tell the controller to update the view
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
|||||||
@@ -427,18 +427,18 @@
|
|||||||
|
|
||||||
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
|
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
|
||||||
SBRemoteImage *remoteImage = remoteImages[idx];
|
SBRemoteImage *remoteImage = remoteImages[idx];
|
||||||
NSData *artworkData = [SBMetadataHelper downloadDataFromURL:remoteImage.URL cachePolicy:SBDefaultPolicy];
|
NSData *artworkData = [SBMetadataHelper downloadDataFromURL:remoteImage.URL cachePolicy:SBCachePolicyDefault];
|
||||||
|
|
||||||
// Hack, download smaller iTunes version if big iTunes version is not available
|
// Hack, download smaller iTunes version if big iTunes version is not available
|
||||||
if (!artworkData) {
|
if (!artworkData) {
|
||||||
if ([remoteImage.providerName isEqualToString:@"iTunes"]) {
|
if ([remoteImage.providerName isEqualToString:@"iTunes"]) {
|
||||||
NSURL *url = remoteImages[idx].URL;
|
NSURL *url = remoteImages[idx].URL;
|
||||||
url = [url.URLByDeletingPathExtension URLByAppendingPathExtension:@"600x600bb.jpg"];
|
url = [url.URLByDeletingPathExtension URLByAppendingPathExtension:@"600x600bb.jpg"];
|
||||||
artworkData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBDefaultPolicy];
|
artworkData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBCachePolicyDefault];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Try again
|
// Try again
|
||||||
artworkData = [SBMetadataHelper downloadDataFromURL:remoteImage.URL cachePolicy:SBDefaultPolicy];
|
artworkData = [SBMetadataHelper downloadDataFromURL:remoteImage.URL cachePolicy:SBCachePolicyDefault];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@
|
|||||||
|
|
||||||
|
|
||||||
- (MP42Image *)loadArtwork:(nonnull NSURL *)url {
|
- (MP42Image *)loadArtwork:(nonnull NSURL *)url {
|
||||||
NSData *artworkData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBDefaultPolicy];
|
NSData *artworkData = [SBMetadataHelper downloadDataFromURL:url cachePolicy:SBCachePolicyDefault];
|
||||||
if (artworkData && artworkData.length) {
|
if (artworkData && artworkData.length) {
|
||||||
MP42Image *artwork = [[MP42Image alloc] initWithData:artworkData type:MP42_ART_JPEG];
|
MP42Image *artwork = [[MP42Image alloc] initWithData:artworkData type:MP42_ART_JPEG];
|
||||||
if (artwork != nil) {
|
if (artwork != nil) {
|
||||||
|
|||||||
Reference in new issue
Block a user