Skip to content

Commit

Permalink
3.3.3-beta 2 - Fix Anime Relations Feature
Browse files Browse the repository at this point in the history
Anime relation features is not functioning as attended due to it being skipped if the detected episode exceeds total. Now, it will check if the total exceeds and will also check target title id as well for a valid episode number.
  • Loading branch information
千代田桃 committed Mar 20, 2021
1 parent 76fbaab commit e88fd28
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 4 deletions.
1 change: 1 addition & 0 deletions AnimeRelations.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
@interface AnimeRelations : NSObject
+ (void)updateRelations;
+ (NSArray *)retrieveRelationsEntriesForTitleID:(int)titleid withService:(int)service;
+ (NSArray *)retrieveTargetRelationsEntriesForTitleID:(int)titleid withService:(int)servic;
+ (void)clearAnimeRelations;
@end
26 changes: 26 additions & 0 deletions AnimeRelations.m
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,32 @@ + (NSArray *)retrieveRelationsEntriesForTitleID:(int)titleid withService:(int)se
return relations;
}

+ (NSArray *)retrieveTargetRelationsEntriesForTitleID:(int)titleid withService:(int)service {
// Return relations for Kitsu ID
NSError *error;
NSManagedObjectContext *moc = [self mangaObjectContext];

NSPredicate *predicate;
switch (service) {
case 0:
predicate = [NSPredicate predicateWithFormat: @"(target_kitsuid == %i)", titleid];
break;
case 1:
predicate = [NSPredicate predicateWithFormat: @"(target_anilistid == %i)", titleid];
break;
case 2:
predicate = [NSPredicate predicateWithFormat: @"(target_malid == %i)", titleid];
break;
default:
break;
}
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
fetch.entity = [NSEntityDescription entityForName:@"AnimeRelations" inManagedObjectContext:moc];
fetch.predicate = predicate;
NSArray *relations = [moc executeFetchRequest:fetch error:&error];
return relations;
}

+ (void)clearAnimeRelations {
// Clears Anime Relations data
NSManagedObjectContext *moc = [self mangaObjectContext];
Expand Down
1 change: 1 addition & 0 deletions Hachidori+AnimeRelations.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

@interface Hachidori (AnimeRelations)
- (int)checkAnimeRelations:(int)titleid;
- (bool)checkAnimeRelationsForExisting:(int)titleid;
@end
46 changes: 46 additions & 0 deletions Hachidori+AnimeRelations.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,50 @@ - (int)checkAnimeRelations:(int)titleid {
}
return -1;
}

- (bool)checkAnimeRelationsForExisting:(int)titleid {
int currentservice = (int)[Hachidori currentService];
NSArray *relations = [AnimeRelations retrieveTargetRelationsEntriesForTitleID:titleid withService:currentservice];
for (NSManagedObject *relation in relations) {
@autoreleasepool {
NSNumber *sourcefromepisode = [relation valueForKey:@"source_ep_from"];
NSNumber *sourcetoepisode = [relation valueForKey:@"source_ep_to"];
NSNumber *targetfromepisode = [relation valueForKey:@"target_ep_from"];
NSNumber *targettoepisode = [relation valueForKey:@"target_ep_to"];
NSNumber *iszeroepisode = [relation valueForKey:@"is_zeroepisode"];
NSNumber *targetid;
switch (currentservice) {
case 0:
targetid = [relation valueForKey:@"target_kitsuid"];
break;
case 1:
targetid = [relation valueForKey:@"target_anilistid"];
break;
case 2:
targetid = [relation valueForKey:@"target_malid"];
break;
default:
break;
}

if (self.detectedscrobble.DetectedEpisode.intValue < sourcefromepisode.intValue && self.detectedscrobble.DetectedEpisode.intValue > sourcetoepisode.intValue) {
continue;
}
int tmpep = self.detectedscrobble.DetectedEpisode.intValue - (sourcefromepisode.intValue-1);
if (tmpep > 0 && tmpep <= targettoepisode.intValue) {
self.detectedscrobble.DetectedEpisode = @(tmpep).stringValue;
return YES;
}
else if (self.detectedscrobble.DetectedTitleisEpisodeZero && iszeroepisode.boolValue) {
self.detectedscrobble.DetectedEpisode = targetfromepisode.stringValue;
return YES;
}
else if (self.detectedscrobble.DetectedTitleisMovie && targetfromepisode.intValue == targettoepisode.intValue) {
self.detectedscrobble.DetectedEpisode = targetfromepisode.stringValue;
return YES;
}
}
}
return NO;
}
@end
19 changes: 19 additions & 0 deletions Hachidori+Search.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,25 @@ - (NSString *)findaniid:(id)responseObject searchterm:(NSString *) term {
return [self foundtitle:((NSNumber *)searchentry[@"id"]).stringValue info:searchentry];
}
}
else if ((episodes < self.detectedscrobble.DetectedEpisode.intValue) && self.detectedscrobble.DetectedEpisode.intValue > 0) {
// Check Relations
if ([NSUserDefaults.standardUserDefaults boolForKey:@"UseAnimeRelations"]) {
int newid = [self checkAnimeRelations:((NSNumber *)searchentry[@"id"]).intValue];
if (newid > 0) {
[self foundtitle:((NSNumber *)searchentry[@"id"]).stringValue info:searchentry];
return @(newid).stringValue;
}
else {
if ([self checkAnimeRelationsForExisting:((NSNumber *)searchentry[@"id"]).intValue]) {
[self foundtitle:((NSNumber *)searchentry[@"id"]).stringValue info:searchentry];
return @(newid).stringValue;
}
else {
continue;
}
}
}
}
else {
// Detected episodes exceed total episodes
continue;
Expand Down
8 changes: 4 additions & 4 deletions Hachidori.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 20210306;
CURRENT_PROJECT_VERSION = 20210320;
DEVELOPMENT_TEAM = 9HDZTER525;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -1693,7 +1693,7 @@
"$(PROJECT_DIR)",
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = "3.3.3-beta1";
MARKETING_VERSION = "3.3.3-beta2";
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "moe.ateliershiori.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Hachidori;
Expand All @@ -1716,7 +1716,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 20210306;
CURRENT_PROJECT_VERSION = 20210320;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 9HDZTER525;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -1741,7 +1741,7 @@
"$(PROJECT_DIR)",
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = "3.3.3-beta1";
MARKETING_VERSION = "3.3.3-beta2";
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "moe.ateliershiori.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Hachidori;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "D0098F79-FAB9-4AF0-A2C3-7E7729DDA321"
type = "1"
version = "2.0">
</Bucket>

0 comments on commit e88fd28

Please sign in to comment.