-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHachidori+AnimeRelations.m
103 lines (98 loc) · 4.66 KB
/
Hachidori+AnimeRelations.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// Hachidori+AnimeRelations.m
// Hachidori
//
// Created by 天々座理世 on 2018/05/23.
//
#import "Hachidori+AnimeRelations.h"
#import "AnimeRelations.h"
@implementation Hachidori (AnimeRelations)
- (int)checkAnimeRelations:(int)titleid {
int currentservice = (int)[Hachidori currentService];
NSArray *relations = [AnimeRelations retrieveRelationsEntriesForTitleID: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 targetid.intValue;
}
else if (self.detectedscrobble.DetectedTitleisEpisodeZero && iszeroepisode.boolValue) {
self.detectedscrobble.DetectedEpisode = targetfromepisode.stringValue;
return targetid.intValue;
}
else if (self.detectedscrobble.DetectedTitleisMovie && targetfromepisode.intValue == targettoepisode.intValue) {
self.detectedscrobble.DetectedEpisode = targetfromepisode.stringValue;
return targetid.intValue;
}
}
}
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