diff --git a/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/LastFMToSpotify.java b/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/LastFMToSpotify.java
index c32d43e..c96ca36 100644
--- a/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/LastFMToSpotify.java
+++ b/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/LastFMToSpotify.java
@@ -38,9 +38,13 @@ public class LastFMToSpotify {
configuration.put("requests.useragent", "LastFMToSpotify/1.0-Snapshot (" + System.getProperty("os.name") + "; " + System.getProperty("os.arch") + ") Java/" + System.getProperty("java.version"));
configuration.put("playlist.name", "LastFMToSpotify@" + LocalDateTime.now(Clock.systemDefaultZone()).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
configuration.put("logging.level", "1");
+
+ //check whether all required arguments are set
if (!ArgumentHandler.checkArguments(args)) {
return;
}
+
+ //check whether multiple arguments from an exclusive set are used
if(!ArgumentHandler.checkExclusivity(args)){
return;
}
@@ -77,21 +81,29 @@ public class LastFMToSpotify {
SpotifyApi api = build.build();
AtomicBoolean waiting = new AtomicBoolean(true);
if (configuration.containsKey("cache.crypto") && TokenHelper.existsTokens()) {
+ logLn("Cached credentials have been found.", 2);
+ logLn("Fetching old credentials, refreshing them and saving to cache", 2);
AuthorizationCodeCredentials oldcred = TokenHelper.fetchTokens();
- AuthorizationCodeCredentials newcred = api.authorizationCodeRefresh(api.getClientId(), api.getClientSecret(), oldcred.getRefreshToken()).build().execute();
+ AuthorizationCodeCredentials newcred = api.authorizationCodeRefresh(api.getClientId(), api.getClientSecret(), oldcred.getRefreshToken()).setHeader("User-Agent", configuration.get("requests.useragent")).build().execute();
TokenHelper.saveTokens(newcred);
configuration.put("spotify.access", newcred.getAccessToken());
} else {
try (Javalin webserver = Javalin.create().start(9876)) {
+ if (configuration.containsKey("cache.crypto")) logLn("No cached credentials have been found.", 2);
+ logLn("Starting webserver to initiate web based authentication.", 2);
Runtime.getRuntime().addShutdownHook(new Thread(webserver::stop));
// webserver.exception(Exception.class, (exception, ctx) -> {
// ctx.result(exception.getMessage());
// });
webserver.get("/callback/spotify", ctx -> {
if(ctx.queryParamMap().containsKey("code")) {
- AuthorizationCodeCredentials cred = api.authorizationCode(ctx.queryParam("code")).build().execute();
+ logLn("Received spotify authentication code. Requesting credentials.", 2);
+ AuthorizationCodeCredentials cred = api.authorizationCode(ctx.queryParam("code")).setHeader("User-Agent", configuration.get("requests.useragent")).build().execute();
configuration.put("spotify.access", cred.getAccessToken());
- if(configuration.containsKey("cache.crypto")) TokenHelper.saveTokens(cred);
+ if(configuration.containsKey("cache.crypto")) {
+ logLn("Saving credentials to cache.", 2);
+ TokenHelper.saveTokens(cred);
+ }
ctx.result("success. ").contentType(ContentType.TEXT_HTML).status(HttpStatus.OK);
waiting.set(false);
} else {
@@ -111,12 +123,14 @@ public class LastFMToSpotify {
logLn("Reading from LastFM...", 1);
Collection