Skip to content

Commit 321ccf3

Browse files
committed
Fix Spotify
Signed-off-by: Presti <dxssucuk@hotmail.com>
1 parent 24bd2c0 commit 321ccf3

File tree

2 files changed

+118
-83
lines changed

2 files changed

+118
-83
lines changed

src/main/java/de/presti/ree6/module/notifications/impl/SpotifySonic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public class SpotifySonic implements ISonic {
3232
ArrayList<SonicIdentifier> spotifyEntries = new ArrayList<>();
3333

34-
SimpleDateFormat spotifyTimestamp = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ssZ");
34+
SimpleDateFormat spotifyTimestamp = new SimpleDateFormat("yyyy-MM-dd");
3535

3636
@Override
3737
public void load(List<ChannelStats> channelStats) {

src/main/java/de/presti/ree6/utils/apis/Notifier.java

Lines changed: 117 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,18 @@ public Notifier() {
198198
log.error("Failed to create Twitch Client.", exception);
199199
}
200200

201-
log.info("Initializing Twitter Client...");
202-
twitterSonic = new TwitterSonic();
203201
try {
202+
log.info("Initializing Twitter Client...");
203+
twitterSonic = new TwitterSonic();
204204
twitterClient = new TwitterClient(TwitterCredentials.builder()
205205
.bearerToken(Main.getInstance().getConfig().getConfiguration().getString("twitter.bearer")).build());
206206
} catch (Exception exception) {
207207
log.error("Failed to create Twitter Client.", exception);
208208
}
209209

210-
log.info("Initializing Reddit Client...");
211-
redditSonic = new RedditSonic();
212210
try {
211+
log.info("Initializing Reddit Client...");
212+
redditSonic = new RedditSonic();
213213
redditClient = Reddit4J
214214
.rateLimited()
215215
.setClientId(Main.getInstance().getConfig().getConfiguration().getString("reddit.client.id"))
@@ -225,87 +225,122 @@ public Notifier() {
225225
Sentry.captureException(exception);
226226
}
227227
}
228+
try {
229+
log.info("Initializing Instagram Client...");
230+
instagramSonic = new InstagramSonic();
231+
// Callable that returns inputted code from System.in
232+
Callable<String> inputCode = () -> {
233+
Scanner scanner = new Scanner(System.in);
234+
log.error("Please input code: ");
235+
String code = scanner.nextLine();
236+
scanner.close();
237+
return code;
238+
};
239+
240+
// handler for challenge login
241+
IGClient.Builder.LoginHandler challengeHandler = (client, response) -> IGChallengeUtils.resolveChallenge(client, response, inputCode);
242+
243+
instagramClient = IGClient.builder()
244+
.username(Main.getInstance().getConfig().getConfiguration().getString("instagram.username"))
245+
.password(Main.getInstance().getConfig().getConfiguration().getString("instagram.password"))
246+
.onChallenge(challengeHandler).build();
247+
248+
instagramClient.sendLoginRequest().exceptionally(throwable -> {
249+
if (BotConfig.isDebug()) {
250+
log.error("Failed to login to Instagram API, you can ignore this if you don't use Instagram.", throwable);
251+
} else {
252+
log.error("Failed to login to Instagram API, you can ignore this if you don't use Instagram.");
253+
log.error("Error Message: {}", throwable.getMessage()
254+
.replace("com.github.instagram4j.instagram4j.exceptions.IGResponseException: ", "")
255+
.replace("&#039;", "'"));
256+
}
257+
return null;
258+
});
259+
} catch (Exception exception) {
260+
log.error("Failed to create Instagram Client.", exception);
261+
}
228262

229-
log.info("Initializing Instagram Client...");
230-
instagramSonic = new InstagramSonic();
231-
// Callable that returns inputted code from System.in
232-
Callable<String> inputCode = () -> {
233-
Scanner scanner = new Scanner(System.in);
234-
log.error("Please input code: ");
235-
String code = scanner.nextLine();
236-
scanner.close();
237-
return code;
238-
};
239-
240-
// handler for challenge login
241-
IGClient.Builder.LoginHandler challengeHandler = (client, response) -> IGChallengeUtils.resolveChallenge(client, response, inputCode);
242-
243-
instagramClient = IGClient.builder()
244-
.username(Main.getInstance().getConfig().getConfiguration().getString("instagram.username"))
245-
.password(Main.getInstance().getConfig().getConfiguration().getString("instagram.password"))
246-
.onChallenge(challengeHandler).build();
247-
248-
instagramClient.sendLoginRequest().exceptionally(throwable -> {
249-
if (BotConfig.isDebug()) {
250-
log.error("Failed to login to Instagram API, you can ignore this if you don't use Instagram.", throwable);
251-
} else {
252-
log.error("Failed to login to Instagram API, you can ignore this if you don't use Instagram.");
253-
log.error("Error Message: {}", throwable.getMessage()
254-
.replace("com.github.instagram4j.instagram4j.exceptions.IGResponseException: ", "")
255-
.replace("&#039;", "'"));
256-
}
257-
return null;
258-
});
259-
260-
log.info("Initializing Spotify Client...");
261-
spotifySonic = new SpotifySonic();
263+
try {
264+
log.info("Initializing Spotify Client...");
265+
spotifySonic = new SpotifySonic();
266+
} catch (Exception exception) {
267+
log.error("Failed to create Spotify Client.", exception);
268+
}
262269

263270
log.info("Initializing Streams...");
264271

265-
log.info("Creating YouTube Streams...");
266-
youTubeSonic = new YouTubeSonic();
267-
ThreadUtil.createThread(x -> youTubeSonic.run(), x -> {
268-
log.error("Failed to run YouTube Stream!", x);
269-
Sentry.captureException(x);
270-
}, Duration.ofMinutes(5), true, true);
271-
272-
log.info("Creating Twitter Streams...");
273-
ThreadUtil.createThread(x -> twitterSonic.run(), x -> {
274-
log.error("Failed to run Twitter Follower count checker!", x);
275-
Sentry.captureException(x);
276-
}, Duration.ofMinutes(5), true, true);
277-
278-
log.info("Creating RSS Streams...");
279-
rssSonic = new RSSSonic();
280-
ThreadUtil.createThread(x -> rssSonic.run(), x -> {
281-
log.error("Failed to run RSS Feed Stream!", x);
282-
Sentry.captureException(x);
283-
}, Duration.ofMinutes(3), true, true);
284-
285-
log.info("Creating TikTok Streams...");
286-
tikTokSonic = new TikTokSonic();
287-
ThreadUtil.createThread(x -> tikTokSonic.run(), x -> {
288-
log.error("Failed to run TikTok Stream!", x);
289-
Sentry.captureException(x);
290-
}, Duration.ofMinutes(5), true, true);
291-
292-
log.info("Creating Instagram Streams...");
293-
ThreadUtil.createThread(x -> instagramSonic.run(), x -> {
294-
log.error("Failed to run Instagram Stream!", x);
295-
Sentry.captureException(x);
296-
}, Duration.ofMinutes(5), true, true);
297-
298-
log.info("Creating Reddit Streams...");
299-
ThreadUtil.createThread(x -> redditSonic.run(), x -> {
300-
log.error("Failed to run Reddit Stream!", x);
301-
Sentry.captureException(x);
302-
}, Duration.ofMinutes(5), true, true);
303-
304-
// Use 1 day instead of minutes, because Spotify release date is at max precise to the day
305-
log.info("Creating Spotify Streams...");
306-
ThreadUtil.createThread(x -> spotifySonic.run(), x -> {
307-
log.error("Failed to run Spotify Stream!", x);
308-
Sentry.captureException(x);
309-
}, Duration.ofDays(1), true, true);
272+
try {
273+
log.info("Creating YouTube Streams...");
274+
youTubeSonic = new YouTubeSonic();
275+
ThreadUtil.createThread(x -> youTubeSonic.run(), x -> {
276+
log.error("Failed to run YouTube Stream!", x);
277+
Sentry.captureException(x);
278+
}, Duration.ofMinutes(5), true, true);
279+
} catch (Exception exception) {
280+
log.error("Failed to create YouTube Streams.", exception);
281+
}
282+
283+
try {
284+
log.info("Creating Twitter Streams...");
285+
ThreadUtil.createThread(x -> twitterSonic.run(), x -> {
286+
log.error("Failed to run Twitter Follower count checker!", x);
287+
Sentry.captureException(x);
288+
}, Duration.ofMinutes(5), true, true);
289+
} catch (Exception exception) {
290+
log.error("Failed to create Twitter Streams.", exception);
291+
}
292+
293+
try {
294+
log.info("Creating RSS Streams...");
295+
rssSonic = new RSSSonic();
296+
ThreadUtil.createThread(x -> rssSonic.run(), x -> {
297+
log.error("Failed to run RSS Feed Stream!", x);
298+
Sentry.captureException(x);
299+
}, Duration.ofMinutes(3), true, true);
300+
} catch (Exception exception) {
301+
log.error("Failed to create RSS Streams.", exception);
302+
}
303+
304+
try {
305+
log.info("Creating TikTok Streams...");
306+
tikTokSonic = new TikTokSonic();
307+
ThreadUtil.createThread(x -> tikTokSonic.run(), x -> {
308+
log.error("Failed to run TikTok Stream!", x);
309+
Sentry.captureException(x);
310+
}, Duration.ofMinutes(5), true, true);
311+
} catch (Exception exception) {
312+
log.error("Failed to create TikTok Streams.", exception);
313+
}
314+
315+
try {
316+
log.info("Creating Instagram Streams...");
317+
ThreadUtil.createThread(x -> instagramSonic.run(), x -> {
318+
log.error("Failed to run Instagram Stream!", x);
319+
Sentry.captureException(x);
320+
}, Duration.ofMinutes(5), true, true);
321+
} catch (Exception exception) {
322+
log.error("Failed to create Instagram Streams.", exception);
323+
}
324+
325+
try {
326+
log.info("Creating Reddit Streams...");
327+
ThreadUtil.createThread(x -> redditSonic.run(), x -> {
328+
log.error("Failed to run Reddit Stream!", x);
329+
Sentry.captureException(x);
330+
}, Duration.ofMinutes(5), true, true);
331+
} catch (Exception exception) {
332+
log.error("Failed to create Reddit Streams.", exception);
333+
}
334+
335+
try {
336+
// Use 1 day instead of minutes, because Spotify release date is at max precise to the day
337+
log.info("Creating Spotify Streams...");
338+
ThreadUtil.createThread(x -> spotifySonic.run(), x -> {
339+
log.error("Failed to run Spotify Stream!", x);
340+
Sentry.captureException(x);
341+
}, Duration.ofDays(1), true, true);
342+
} catch (Exception exception) {
343+
log.error("Failed to create Spotify Streams.", exception);
344+
}
310345
}
311346
}

0 commit comments

Comments
 (0)