Implemented Playlist builder #9

Merged
B00tLoad merged 5 commits from SpotifyPlaylistBuilder into master 2023-01-24 15:02:13 +01:00
4 changed files with 45 additions and 2 deletions
Showing only changes of commit b7830190c6 - Show all commits

View File

@@ -110,7 +110,9 @@ public class LastFMToSpotify {
}
}
api.addItemsToPlaylist(list.getId(), adders.toArray(String[]::new)).build().execute();
if(configuration.containsKey(configuration.get("playlist.cover"))) api.uploadCustomPlaylistCoverImage(list.getId()).image_data(configuration.get("playlist.cover")).build().execute();
if(configuration.containsKey("playlist.cover")){
logLn("Check for \"null\" if setting cover was successful: " + api.uploadCustomPlaylistCoverImage(list.getId()).image_data(configuration.get("playlist.cover")).setHeader("User-Agent", configuration.get("requests.useragent")).build().execute(),3);
}
logLn("Done.", 1);
// } catch (IOException | ParseException | SpotifyWebApiException e) {
} catch (Exception e) {

View File

@@ -1,10 +1,16 @@
package de.b00tload.tools.lastfmtospotifyplaylist.arguments;
import de.b00tload.tools.lastfmtospotifyplaylist.util.FileHelper;
import de.umass.lastfm.Period;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import static de.b00tload.tools.lastfmtospotifyplaylist.LastFMToSpotify.LINE_SEPERATOR;
import static de.b00tload.tools.lastfmtospotifyplaylist.LastFMToSpotify.configuration;
import static de.b00tload.tools.lastfmtospotifyplaylist.util.Logger.logLn;
public class ArgumentHandler {
@@ -21,6 +27,7 @@ public class ArgumentHandler {
case QUARTERLY -> period(Period.THREE_MONTHS);
case BIANNUALLY -> period(Period.SIX_MONTHS);
case YEARLY -> period(Period.TWELVE_MONTHS);
case COVER -> cover(value);
}
}
@@ -111,4 +118,13 @@ public class ArgumentHandler {
private static void period(Period value) {
configuration.put("lastfm.period", value.getString());
}
private static void cover(String value) {
if (value == null || value.equalsIgnoreCase("") || !Files.exists(Path.of(value.replace("\\", "//")))) {
System.out.println("--coverart must be provided with a path to a png file. Check usage: " + Arguments.COVER.getUsage());
System.exit(500);
}
String base64 = FileHelper.encodeFileToBase64(new File(value.replace("\\", "//")));
configuration.put("playlist.cover", base64);
}
}

View File

@@ -33,7 +33,9 @@ public enum Arguments {
BIANNUALLY("biannually", "[Optional]" + LINE_SEPERATOR
+ "Creates a playlist from your top tracks from last half-year.", "--biannualy", "B"),
YEARLY("yearly", "[Optional]" + LINE_SEPERATOR
+ "Creates a playlist from your top tracks from last year.", "--anually", "A");;
+ "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 <path/to/coverart.jpg>", "ca", "cover");
private final String name;
private final String description;

View File

@@ -0,0 +1,23 @@
package de.b00tload.tools.lastfmtospotifyplaylist.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Base64;
public class FileHelper {
public static String encodeFileToBase64(File file){
String encodedfile = null;
try (FileInputStream fileInputStreamReader = new FileInputStream(file)){
byte[] bytes = new byte[(int)file.length()];
fileInputStreamReader.read(bytes);
encodedfile = Base64.getEncoder().encodeToString(bytes);
} catch (IOException e) {
e.printStackTrace();
}
return encodedfile;
}
}