Remove null values from results.
This commit is contained in:
1 parent
951971bdbd
commit
aa7d9cdfbe
3 files changed
+39
-8
No files matched your search
@@ -60,7 +60,7 @@ extern NSString *const SBMetadataResultNetwork;
|
|||||||
- (void)setTag:(id)value forKey:(NSString *)key;
|
- (void)setTag:(id)value forKey:(NSString *)key;
|
||||||
|
|
||||||
- (nullable id)objectForKeyedSubscript:(NSString *)key;
|
- (nullable id)objectForKeyedSubscript:(NSString *)key;
|
||||||
- (void)setObject:(id)obj forKeyedSubscript:(NSString *)key;
|
- (void)setObject:(nullable id)obj forKeyedSubscript:(NSString *)key;
|
||||||
|
|
||||||
@property (nonatomic, readonly) NSMutableDictionary<NSString *, id> *tags;
|
@property (nonatomic, readonly) NSMutableDictionary<NSString *, id> *tags;
|
||||||
|
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ static NSDictionary<NSString *, NSString *> *localizedKeys;
|
|||||||
return _tags[key];
|
return _tags[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setObject:(id)obj forKeyedSubscript:(NSString *)key
|
- (void)setObject:(nullable id)obj forKeyedSubscript:(NSString *)key
|
||||||
{
|
{
|
||||||
if (obj == nil) {
|
if (obj == nil) {
|
||||||
[self removeTagForKey:key];
|
[self removeTagForKey:key];
|
||||||
|
|||||||
@@ -56,12 +56,12 @@
|
|||||||
// search for series id
|
// search for series id
|
||||||
NSSet<NSNumber *> *seriesIDs = [self searchSeriesID:seriesName language:language];
|
NSSet<NSNumber *> *seriesIDs = [self searchSeriesID:seriesName language:language];
|
||||||
|
|
||||||
// fallback to english if the no results are found
|
// fallback to English if no results are found
|
||||||
if (!seriesIDs.count) {
|
if (!seriesIDs.count) {
|
||||||
seriesIDs = [self searchSeriesID:seriesName language:@"en"];
|
seriesIDs = [self searchSeriesID:seriesName language:@"en"];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray *results = [[NSMutableArray alloc] init];
|
NSMutableArray<SBMetadataResult *> *results = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
for (NSDictionary *s in seriesIDs) {
|
for (NSDictionary *s in seriesIDs) {
|
||||||
|
|
||||||
@@ -85,12 +85,15 @@
|
|||||||
// Check for null values, it might happens if there isn't a localized version
|
// Check for null values, it might happens if there isn't a localized version
|
||||||
SBTheTVDBNullValues nullValues = [self checkForNull:localizedResults];
|
SBTheTVDBNullValues nullValues = [self checkForNull:localizedResults];
|
||||||
|
|
||||||
|
localizedResults = [localizedResults sortedArrayUsingFunction:sortSBMetadataResult context:NULL];
|
||||||
|
|
||||||
if (nullValues && ![language isEqualToString:@"en"]) {
|
if (nullValues && ![language isEqualToString:@"en"]) {
|
||||||
if (nullValues & SBTheTVDBNullValuesEpisodes) {
|
if (nullValues & SBTheTVDBNullValuesEpisodes) {
|
||||||
NSArray<SBMetadataResult *> *englishResults = [self loadTVEpisodes:seriesInfo actors:seriesActors
|
NSArray<SBMetadataResult *> *englishResults = [self loadTVEpisodes:seriesInfo actors:seriesActors
|
||||||
seasonNum:seasonNum episodeNum:episodeNum language:@"en"];
|
seasonNum:seasonNum episodeNum:episodeNum language:@"en"];
|
||||||
|
|
||||||
if (englishResults) {
|
if (englishResults.count) {
|
||||||
|
englishResults = [englishResults sortedArrayUsingFunction:sortSBMetadataResult context:NULL];
|
||||||
[self merge:localizedResults with:englishResults];
|
[self merge:localizedResults with:englishResults];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,11 +107,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[self removeNullValues:localizedResults];
|
||||||
|
|
||||||
[results addObjectsFromArray:localizedResults];
|
[results addObjectsFromArray:localizedResults];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSArray<SBMetadataResult *> *resultsSorted = [results sortedArrayUsingFunction:sortSBMetadataResult context:NULL];
|
return [results sortedArrayUsingFunction:sortSBMetadataResult context:NULL];
|
||||||
return resultsSorted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Sort
|
#pragma mark - Sort
|
||||||
@@ -140,6 +144,10 @@ static NSInteger sortSBMetadataResult(SBMetadataResult *ep1, SBMetadataResult *e
|
|||||||
|
|
||||||
- (BOOL)seriesResult:(NSDictionary *)s matchName:(NSString *)seriesName
|
- (BOOL)seriesResult:(NSDictionary *)s matchName:(NSString *)seriesName
|
||||||
{
|
{
|
||||||
|
NSString *resultName = s[@"seriesName"];
|
||||||
|
|
||||||
|
if (![resultName isKindOfClass:[NSString class]]) { return NO; }
|
||||||
|
|
||||||
if ([seriesName isEqualTo:s[@"seriesName"]]) {
|
if ([seriesName isEqualTo:s[@"seriesName"]]) {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
@@ -148,7 +156,7 @@ static NSInteger sortSBMetadataResult(SBMetadataResult *ep1, SBMetadataResult *e
|
|||||||
|
|
||||||
if ([aliases isKindOfClass:[NSArray class]]) {
|
if ([aliases isKindOfClass:[NSArray class]]) {
|
||||||
for (NSString *alias in aliases) {
|
for (NSString *alias in aliases) {
|
||||||
if ([seriesName isEqualTo:alias]) {
|
if ([alias isKindOfClass:[NSString class]] && [seriesName isEqualTo:alias]) {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,6 +221,29 @@ typedef NS_OPTIONS(NSUInteger, SBTheTVDBNullValues) {
|
|||||||
return nullValues;
|
return nullValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)removeNullValues:(NSArray<SBMetadataResult *> *)results
|
||||||
|
{
|
||||||
|
NSNull *null = [NSNull null];
|
||||||
|
|
||||||
|
for (SBMetadataResult *result in results) {
|
||||||
|
if ([result[SBMetadataResultSeriesName] isEqualTo:null]) {
|
||||||
|
result[SBMetadataResultSeriesName] = nil;
|
||||||
|
}
|
||||||
|
if ([result[SBMetadataResultName] isEqualTo:null]) {
|
||||||
|
result[SBMetadataResultName] = nil;
|
||||||
|
}
|
||||||
|
if ([result[SBMetadataResultLongDescription] isEqualTo:null]) {
|
||||||
|
result[SBMetadataResultLongDescription] = nil;
|
||||||
|
}
|
||||||
|
if ([result[SBMetadataResultDescription] isEqualTo:null]) {
|
||||||
|
result[SBMetadataResultDescription] = nil;
|
||||||
|
}
|
||||||
|
if ([result[SBMetadataResultSeriesDescription] isEqualTo:null]) {
|
||||||
|
result[SBMetadataResultSeriesDescription] = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)merge:(NSArray<SBMetadataResult *> *)array with:(NSArray<SBMetadataResult *> *)array2
|
- (void)merge:(NSArray<SBMetadataResult *> *)array with:(NSArray<SBMetadataResult *> *)array2
|
||||||
{
|
{
|
||||||
NSNull *null = [NSNull null];
|
NSNull *null = [NSNull null];
|
||||||
|
|||||||
Reference in new issue
Block a user