Implemented checking flags for exclusivity #12
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,4 +2,4 @@
|
|||||||
/target/
|
/target/
|
||||||
.idea/
|
.idea/
|
||||||
compile.bat
|
compile.bat
|
||||||
.vscode/
|
/.vscode/
|
||||||
|
|||||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"java.configuration.updateBuildConfiguration": "interactive"
|
|
||||||
}
|
|
||||||
@@ -37,10 +37,13 @@ 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");
|
configuration.put("logging.level", "1");
|
||||||
if (!ArgumentHandler.checkArguments(args)) {
|
if (!ArgumentHandler.checkArguments(args)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(!ArgumentHandler.checkExclusivity(args)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// parse arguments
|
// parse arguments
|
||||||
for (int a = 0; a < args.length; a++) {
|
for (int a = 0; a < args.length; a++) {
|
||||||
@@ -112,15 +115,11 @@ public class LastFMToSpotify {
|
|||||||
searchQuery.append(" album:").append(track.getAlbum());
|
searchQuery.append(" album:").append(track.getAlbum());
|
||||||
logLn("Search query: " + searchQuery, 3);
|
logLn("Search query: " + searchQuery, 3);
|
||||||
se.michaelthelin.spotify.model_objects.specification.Track[] add = api.searchTracks(searchQuery.toString()).market(CountryCode.DE).setHeader("User-Agent", configuration.get("requests.useragent")).build().execute().getItems();
|
se.michaelthelin.spotify.model_objects.specification.Track[] add = api.searchTracks(searchQuery.toString()).market(CountryCode.DE).setHeader("User-Agent", configuration.get("requests.useragent")).build().execute().getItems();
|
||||||
if(add.length!=0) {
|
for(se.michaelthelin.spotify.model_objects.specification.Track t : add){
|
||||||
// adders.add(add[0].getUri());
|
if(t.getName().equalsIgnoreCase(track.getName())){
|
||||||
// logLn("Added " + add[0].getName() + " to " + configuration.get("playlist.name"), 3);
|
adders.add(t.getUri());
|
||||||
for(se.michaelthelin.spotify.model_objects.specification.Track t : add){
|
logLn("Added " + add[0].getName() + " to " + configuration.get("playlist.name"), 3);
|
||||||
if(t.getName().equalsIgnoreCase(track.getName())){
|
break;
|
||||||
adders.add(t.getUri());
|
|
||||||
logLn("Added " + add[0].getName() + " to " + configuration.get("playlist.name"), 3);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import java.time.temporal.ChronoField;
|
|||||||
import java.time.temporal.IsoFields;
|
import java.time.temporal.IsoFields;
|
||||||
import java.time.temporal.TemporalField;
|
import java.time.temporal.TemporalField;
|
||||||
import java.time.temporal.WeekFields;
|
import java.time.temporal.WeekFields;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static de.b00tload.tools.lastfmtospotifyplaylist.LastFMToSpotify.LINE_SEPERATOR;
|
import static de.b00tload.tools.lastfmtospotifyplaylist.LastFMToSpotify.LINE_SEPERATOR;
|
||||||
@@ -58,20 +59,40 @@ public class ArgumentHandler {
|
|||||||
// check if all required arguments are given
|
// check if all required arguments are given
|
||||||
Arguments[] required = {Arguments.SECRET, Arguments.CLIENT, Arguments.TOKEN, Arguments.USER};
|
Arguments[] required = {Arguments.SECRET, Arguments.CLIENT, Arguments.TOKEN, Arguments.USER};
|
||||||
for (Arguments argument : required) {
|
for (Arguments argument : required) {
|
||||||
boolean found = false;
|
boolean found = List.of(args).contains("--" + argument.getName());
|
||||||
// check all aliases
|
// check all aliases
|
||||||
for (String alias : argument.getAliases()) {
|
for (String alias : argument.getAliases()) {
|
||||||
// if one alias is found check next argument
|
// if one alias is found check next argument
|
||||||
if (List.of(args).contains(alias)) {
|
if (List.of(args).contains("-"+alias)) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else return false
|
// else return false
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
logLn("Missing required argument " + argument.getName(), 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkExclusivity(String[] args){
|
||||||
|
Arguments[][] exclusive = {{Arguments.PUBLIC, Arguments.COLLABORATIVE}, {Arguments.WEEKLY, Arguments.MONTHLY, Arguments.QUARTERLY, Arguments.BIANNUALLY, Arguments.YEARLY}};
|
||||||
|
for(Arguments[] arguments : exclusive){
|
||||||
|
int count = 0;
|
||||||
|
for(Arguments argument : arguments){
|
||||||
|
if(List.of(args).contains("--"+argument.getName())) count++;
|
||||||
|
for(String alias : argument.getAliases()) {
|
||||||
|
if(List.of(args).contains("-"+alias)) count++;
|
||||||
|
}
|
||||||
|
if(count>1){
|
||||||
|
logLn("You may only use one flag out of every exclusive group." + LINE_SEPERATOR +
|
||||||
|
"This exclusive group contains of: " + Arrays.toString(arguments), 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,4 +91,15 @@ public enum Arguments {
|
|||||||
ret = getByAlias(v);
|
ret = getByAlias(v);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder args = new StringBuilder("--").append(this.name).append(" (");
|
||||||
|
for(String alias : this.getAliases()){
|
||||||
|
args.append("-").append(alias).append(", ");
|
||||||
|
}
|
||||||
|
args.delete(args.length()-2, args.length());
|
||||||
|
args.append(")");
|
||||||
|
return args.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user