From 978640ba105b3619a5b5595ab2d3197a6c3ef6a5 Mon Sep 17 00:00:00 2001 From: Alix von Schirp Date: Tue, 24 Jan 2023 04:59:40 +0100 Subject: [PATCH] Implemented public / collaborative flag closes #6 also stated flag exclusivity in argument descriptions --- .../lastfmtospotifyplaylist/LastFMToSpotify.java | 2 +- .../arguments/ArgumentHandler.java | 9 +++++++++ .../arguments/Arguments.java | 16 ++++++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/LastFMToSpotify.java b/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/LastFMToSpotify.java index ee5306f..b370226 100644 --- a/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/LastFMToSpotify.java +++ b/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/LastFMToSpotify.java @@ -93,7 +93,7 @@ public class LastFMToSpotify { Collection tracks = User.getTopTracks(configuration.get("lastfm.user"), PeriodHelper.getPeriodByString(configuration.get("lastfm.period")), configuration.get("lastfm.apikey")); logLn("Creating Playlist...", 1); api.setAccessToken(configuration.get("spotify.access")); - Playlist list = api.createPlaylist(api.getCurrentUsersProfile().build().execute().getId(), configuration.get("playlist.name")).public_(configuration.containsKey("playlist.public")||configuration.containsKey("playlist.collab")).collaborative(configuration.containsKey("playlist.collab")).setHeader("User-Agent", configuration.get("requests.useragent")).build().execute(); + Playlist list = api.createPlaylist(api.getCurrentUsersProfile().build().execute().getId(), configuration.get("playlist.name")).public_(configuration.containsKey("playlist.public")).collaborative(configuration.containsKey("playlist.collab")).setHeader("User-Agent", configuration.get("requests.useragent")).build().execute(); List adders = new LinkedList<>(); String charsToReplace = "[\"']"; //regex for " and ' for (Track track : tracks) { diff --git a/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/arguments/ArgumentHandler.java b/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/arguments/ArgumentHandler.java index 111f39f..c533f1f 100644 --- a/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/arguments/ArgumentHandler.java +++ b/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/arguments/ArgumentHandler.java @@ -39,6 +39,8 @@ public class ArgumentHandler { case YEARLY -> period(Period.TWELVE_MONTHS); case COVER -> cover(value); case NAME -> name(value); + case PUBLIC -> access("public"); + case COLLABORATIVE -> access("collaborative"); } } @@ -139,6 +141,13 @@ public class ArgumentHandler { configuration.put("playlist.cover", base64); } + private static void access(String value) { + switch (value) { + case "collaborative" -> configuration.put("playlist.collab", "collab"); + case "public" -> configuration.put("playlist.public", "public"); + } + } + private static void name(String value) { if (value == null || value.equalsIgnoreCase("")) { System.out.println("--playlistname must be provided with a playlist name. Check usage: " + Arguments.NAME.getUsage()); diff --git a/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/arguments/Arguments.java b/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/arguments/Arguments.java index 4e91046..f6009b2 100644 --- a/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/arguments/Arguments.java +++ b/src/main/java/de/b00tload/tools/lastfmtospotifyplaylist/arguments/Arguments.java @@ -24,20 +24,24 @@ public enum Arguments { + "Sets the LastFM API token.", "--lastfmtoken ", "lT", "lToken"), USER("lastfmuser", "[Required]" + LINE_SEPERATOR + "Sets the LastFM API token.", "--lastfmuser ", "lU", "lUser"), - WEEKLY("weekly", "[Optional]" + LINE_SEPERATOR + WEEKLY("weekly", "[Optional] [EXCLUSIVE: weekly, monthly, quarterly, biannually, annually]" + LINE_SEPERATOR + "Creates a playlist from your top tracks from last week.", "--weekly", "W"), - MONTHLY("monthly", "[Optional, Default]" + LINE_SEPERATOR + MONTHLY("monthly", "[Optional, Default] [EXCLUSIVE: weekly, monthly, quarterly, biannually, annually]" + LINE_SEPERATOR + "Creates a playlist from your top tracks from last month.", "--monthly", "M"), - QUARTERLY("quarterly", "[Optional]" + LINE_SEPERATOR + QUARTERLY("quarterly", "[Optional] [EXCLUSIVE: weekly, monthly, quarterly, biannually, annually]" + LINE_SEPERATOR + "Creates a playlist from your top tracks from last quarter.", "--quarterly", "Q"), - BIANNUALLY("biannually", "[Optional]" + LINE_SEPERATOR + BIANNUALLY("biannually", "[Optional] [EXCLUSIVE: weekly, monthly, quarterly, biannually, annually]" + LINE_SEPERATOR + "Creates a playlist from your top tracks from last half-year.", "--biannualy", "B"), - YEARLY("yearly", "[Optional]" + LINE_SEPERATOR + YEARLY("annually", "[Optional] [EXCLUSIVE: weekly, monthly, quarterly, biannually, annually]" + LINE_SEPERATOR + "Creates a playlist from your top tracks from last year.", "--anually", "A"), COVER("coverart", "[Optional]" + LINE_SEPERATOR + "Will set a cover art for the playlist. Must be jpeg/jpg.", "--coverart ", "ca", "cover"), NAME("playlistname", "[Optional]" + LINE_SEPERATOR - + "Sets the playlist name. Supports templating. Refer to https://github.com/B00tLoad/LastFMtoSpotifyPlaylist/wiki/Filename-Templating.", "--playlistname ", "pName", "pN"); + + "Sets the playlist name. Supports templating. Refer to https://github.com/B00tLoad/LastFMtoSpotifyPlaylist/wiki/Filename-Templating.", "--playlistname ", "pName", "pN"), + PUBLIC("public", "[Optional] [EXCLUSIVE: public, collaborative]" + LINE_SEPERATOR + + "Makes the playlist public.", "--public", "pP"), + COLLABORATIVE("collaborative", "[Optional] [EXCLUSIVE: public, collaborative]" + LINE_SEPERATOR + + "Makes the playlist collaborative.", "--collaborative", "pC"); private final String name; private final String description;