Morril #10

Merged
Morril-2300 merged 10 commits from morril into master 2023-01-24 15:13:21 +01:00
4 changed files with 40 additions and 1 deletions

3
.gitignore vendored
View File

@@ -1,4 +1,5 @@
# Project exclude paths # Project exclude paths
/target/ /target/
.idea/ .idea/
compile.bat compile.bat
.vscode/

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}

View File

@@ -5,6 +5,7 @@ import com.neovisionaries.i18n.CountryCode;
import de.b00tload.tools.lastfmtospotifyplaylist.arguments.ArgumentHandler; import de.b00tload.tools.lastfmtospotifyplaylist.arguments.ArgumentHandler;
import de.b00tload.tools.lastfmtospotifyplaylist.arguments.Arguments; import de.b00tload.tools.lastfmtospotifyplaylist.arguments.Arguments;
import de.b00tload.tools.lastfmtospotifyplaylist.util.PeriodHelper; import de.b00tload.tools.lastfmtospotifyplaylist.util.PeriodHelper;
import de.b00tload.tools.lastfmtospotifyplaylist.util.TimeHelper; import de.b00tload.tools.lastfmtospotifyplaylist.util.TimeHelper;
import de.b00tload.tools.lastfmtospotifyplaylist.util.TokenHelper; import de.b00tload.tools.lastfmtospotifyplaylist.util.TokenHelper;
import de.umass.lastfm.Caller; import de.umass.lastfm.Caller;
@@ -36,6 +37,11 @@ public class LastFMToSpotify {
configuration = new HashMap<>(); configuration = new HashMap<>();
configuration.put("requests.useragent", "LastFMToSpotify/1.0-Snapshot (" + System.getProperty("os.name") + "; " + System.getProperty("os.arch") + ") Java/" + System.getProperty("java.version")); 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("playlist.name", "LastFMToSpotify@" + LocalDateTime.now(Clock.systemDefaultZone()).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
configuration.put("log.level", "1");
if (!ArgumentHandler.checkArguments(args)) {
return;
}
// parse arguments // parse arguments
for (int a = 0; a < args.length; a++) { for (int a = 0; a < args.length; a++) {
Arguments arg; Arguments arg;
@@ -59,6 +65,7 @@ public class LastFMToSpotify {
} }
} }
try { try {
logLn("Authenticating with Spotify...", 1); logLn("Authenticating with Spotify...", 1);
SpotifyApi.Builder build = SpotifyApi.builder(); SpotifyApi.Builder build = SpotifyApi.builder();

View File

@@ -2,6 +2,7 @@ package de.b00tload.tools.lastfmtospotifyplaylist.arguments;
import de.b00tload.tools.lastfmtospotifyplaylist.util.FileHelper; import de.b00tload.tools.lastfmtospotifyplaylist.util.FileHelper;
import de.b00tload.tools.lastfmtospotifyplaylist.util.TimeHelper; import de.b00tload.tools.lastfmtospotifyplaylist.util.TimeHelper;
import de.umass.lastfm.Period; import de.umass.lastfm.Period;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -22,6 +23,10 @@ import static de.b00tload.tools.lastfmtospotifyplaylist.LastFMToSpotify.LINE_SEP
import static de.b00tload.tools.lastfmtospotifyplaylist.LastFMToSpotify.configuration; import static de.b00tload.tools.lastfmtospotifyplaylist.LastFMToSpotify.configuration;
import static de.b00tload.tools.lastfmtospotifyplaylist.util.Logger.logLn; import static de.b00tload.tools.lastfmtospotifyplaylist.util.Logger.logLn;
import java.util.List;
import javax.xml.crypto.Data;
public class ArgumentHandler { public class ArgumentHandler {
public static void handle(Arguments argument, @Nullable String value) { public static void handle(Arguments argument, @Nullable String value) {
@@ -48,6 +53,28 @@ public class ArgumentHandler {
handle(argument, null); handle(argument, null);
} }
public static boolean checkArguments(String[] args) {
// check if all required arguments are given
Arguments[] required = {Arguments.SECRET, Arguments.CLIENT, Arguments.TOKEN, Arguments.USER};
for (Arguments argument : required) {
boolean found = false;
// check all aliases
for (String alias : argument.getAliases()) {
// if one alias is found check next argument
if (List.of(args).contains(alias)) {
found = true;
break;
}
}
// else return false
if (!found) {
return false;
}
}
return true;
}
private static void help(String value) { private static void help(String value) {
if (value == null) { if (value == null) {
System.out.println("This is a list of all available commands. For more specific help on the argument run --help <argument>."); System.out.println("This is a list of all available commands. For more specific help on the argument run --help <argument>.");
@@ -130,6 +157,7 @@ public class ArgumentHandler {
private static void period(Period value) { private static void period(Period value) {
configuration.put("lastfm.period", value.getString()); configuration.put("lastfm.period", value.getString());
} }
private static void cover(String value) { private static void cover(String value) {