diff --git a/AnimeRelations.h b/AnimeRelations.h index 3b4e9b7c..73d79a44 100644 --- a/AnimeRelations.h +++ b/AnimeRelations.h @@ -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 diff --git a/AnimeRelations.m b/AnimeRelations.m index 2b6796ac..8f4f458d 100644 --- a/AnimeRelations.m +++ b/AnimeRelations.m @@ -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]; diff --git a/Hachidori+AnimeRelations.h b/Hachidori+AnimeRelations.h index 3b137c61..16ca3164 100644 --- a/Hachidori+AnimeRelations.h +++ b/Hachidori+AnimeRelations.h @@ -9,4 +9,5 @@ @interface Hachidori (AnimeRelations) - (int)checkAnimeRelations:(int)titleid; +- (bool)checkAnimeRelationsForExisting:(int)titleid; @end diff --git a/Hachidori+AnimeRelations.m b/Hachidori+AnimeRelations.m index fb486667..c64f4071 100644 --- a/Hachidori+AnimeRelations.m +++ b/Hachidori+AnimeRelations.m @@ -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 diff --git a/Hachidori+Search.m b/Hachidori+Search.m index f9bb3b74..564bfe63 100644 --- a/Hachidori+Search.m +++ b/Hachidori+Search.m @@ -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; diff --git a/Hachidori.xcodeproj/project.pbxproj b/Hachidori.xcodeproj/project.pbxproj index 209aa11b..c07a7fc1 100644 --- a/Hachidori.xcodeproj/project.pbxproj +++ b/Hachidori.xcodeproj/project.pbxproj @@ -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 = ( @@ -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; @@ -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; @@ -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; diff --git a/Hachidori.xcodeproj/xcuserdata/chiyodamomo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Hachidori.xcodeproj/xcuserdata/chiyodamomo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 00000000..f7e4ea3b --- /dev/null +++ b/Hachidori.xcodeproj/xcuserdata/chiyodamomo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,6 @@ + + +