-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHachidori+Update.m
165 lines (163 loc) · 6.83 KB
/
Hachidori+Update.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//
// Hachidori+Update.m
// Hachidori
//
// Created by 高町なのは on 2015/02/11.
// Copyright 2009-2018 MAL Updater OS X Group and James Moy All rights reserved. Code licensed under New BSD License
//
#import "Hachidori+Update.h"
#import <AFNetworking/AFNetworking.h>
@implementation Hachidori (Update)
- (int)updatetitle:(NSString *)titleid {
if (!titleid || titleid.length == 0) {
NSLog(@"Internal Error. Title: %@, Episode: %@", self.detectedscrobble.DetectedTitle, self.detectedscrobble.DetectedEpisode);
return ScrobblerFailed;
}
if (!self.detectedscrobble.airing && !self.detectedscrobble.completedairing) {
// User attempting to update title that haven't been aired.
return ScrobblerInvalidScrobble;
}
else if ((self.detectedscrobble.DetectedEpisode).intValue == self.detectedscrobble.TotalEpisodes && self.detectedscrobble.airing && !self.detectedscrobble.completedairing) {
// User attempting to complete a title, which haven't finished airing
return ScrobblerInvalidScrobble;
}
NSLog(@"Updating Title");
if (self.detectedscrobble.LastScrobbledTitleNew && [[NSUserDefaults standardUserDefaults] boolForKey:@"ConfirmNewTitle"] && !self.detectedscrobble.confirmed && !self.correcting) {
// Confirm before updating title
[self storeLastScrobbled];
return ScrobblerConfirmNeeded;
}
if (self.detectedscrobble.DetectedEpisode.intValue <= self.detectedscrobble.DetectedCurrentEpisode && (![self.detectedscrobble.WatchStatus isEqualToString:@"completed"] || ![[NSUserDefaults standardUserDefaults] boolForKey:@"RewatchEnabled"])) {
// Already Watched, no need to scrobble
// Store Scrobbled Title and Episode
[self storeLastScrobbled];
[self sendDiscordPresence:self.lastscrobble];
self.detectedscrobble.confirmed = true;
[self multiscrobbleWithType:self.correcting ? MultiScrobbleTypeCorrection : MultiScrobbleTypeScrobble withTitleID:titleid];
return ScrobblerUpdateNotNeeded;
}
else if (self.detectedscrobble.DetectedEpisode.intValue == self.detectedscrobble.DetectedCurrentEpisode && self.detectedscrobble.DetectedCurrentEpisode == self.detectedscrobble.TotalEpisodes && self.detectedscrobble.TotalEpisodes > 1 && [self.detectedscrobble.WatchStatus isEqualToString:@"completed"]) {
//Do not set rewatch status for current episode equal to total episodes.
[self storeLastScrobbled];
[self sendDiscordPresence:self.lastscrobble];
self.detectedscrobble.confirmed = true;
[self multiscrobbleWithType:self.correcting ? MultiScrobbleTypeCorrection : MultiScrobbleTypeScrobble withTitleID:titleid];
return ScrobblerUpdateNotNeeded;
}
else if (!self.detectedscrobble.LastScrobbledTitleNew && [[NSUserDefaults standardUserDefaults] boolForKey:@"ConfirmUpdates"] && !self.detectedscrobble.confirmed && !self.correcting) {
// Confirm before updating title
[self storeLastScrobbled];
return ScrobblerConfirmNeeded;
}
else {
int status = [self performupdate:titleid withService:(int)[Hachidori currentService]];
if (status == ScrobblerAddTitleSuccessful || status == ScrobblerUpdateSuccessful) {
[self multiscrobbleWithType:self.correcting ? MultiScrobbleTypeCorrection : MultiScrobbleTypeScrobble withTitleID:titleid];
}
return status;
}
}
- (int)performupdate:(NSString *)titleid withService:(long)service {
int status;
switch (service) {
case 0:
status = [self.kitsumanager kitsuperformupdate:titleid];
break;
case 1:
status = [self.anilistmanager anilistperformupdate:titleid];
break;
case 2:
status = [self.malmanger malperformupdate:titleid];
break;
default:
return ScrobblerFailed;
}
if (service == [Hachidori currentService]) {
switch (status) {
case ScrobblerAddTitleSuccessful:
[self.twittermanager postaddanimetweet:self.lastscrobble];
break;
case ScrobblerUpdateSuccessful:
[self.twittermanager postupdateanimetweet:self.lastscrobble];
break;
default:
break;
}
[self sendDiscordPresence:self.lastscrobble];
}
return status;
}
- (void)updatestatus:(NSString *)titleid
episode:(NSString *)episode
score:(int)showscore
watchstatus:(NSString*)showwatchstatus
notes:(NSString*)note
isPrivate:(BOOL)privatevalue
completion:(void (^)(bool success))completionhandler
withService:(long)service
{
switch (service) {
case 0:
[self.kitsumanager kitsuupdatestatus:titleid episode:episode score:showscore watchstatus:showwatchstatus notes:note isPrivate:privatevalue completion:completionhandler];
break;
case 1:
[self.anilistmanager anilistupdatestatus:titleid episode:episode score:showscore watchstatus:showwatchstatus notes:note isPrivate:privatevalue completion:completionhandler];
break;
case 2:
[self.malmanger malupdatestatus:titleid episode:episode score:showscore watchstatus:showwatchstatus notes:note completion:completionhandler];
default:
completionhandler(false);
break;
}
}
- (BOOL)stopRewatching:(NSString *)titleid withService:(long)service {
int status;
switch (service) {
case 0:
status = [self.kitsumanager kitsustopRewatching:titleid];
break;
case 1:
status = [self.anilistmanager aniliststopRewatching:titleid];
break;
case 2:
status = [self.malmanger malstopRewatching:titleid];
break;
default:
return ScrobblerFailed;
}
if (status == 1) {
[self multiscrobbleWithType:MultiScrobbleTypeRevertRewatch withTitleID:titleid];
}
if (service == [Hachidori currentService]) {
[self sendDiscordPresence:self.lastscrobble];
}
return status;
}
- (bool)removetitle:(NSString *)titleid withService:(long)service {
switch (service) {
case 0:
return [self.kitsumanager kitsuremovetitle:titleid];
case 1:
return [self.anilistmanager anilistremovetitle:titleid];
case 2:
return [self.malmanger malremovetitle:titleid];
default:
return NO;
}
}
- (void)storeLastScrobbled {
switch ([Hachidori currentService]) {
case 0:
[self.kitsumanager kitsustoreLastScrobbled];
break;
case 1:
[self.anilistmanager aniliststoreLastScrobbled];
break;
case 2:
[self.malmanger malstoreLastScrobbled];
break;
default:
break;
}
}
@end