Implemented checking for newer version against GitHub
This commit is contained in:
9
pom.xml
9
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>de.b00tload.tools</groupId>
|
<groupId>de.b00tload.tools</groupId>
|
||||||
<artifactId>LastfmToSpotifyPlaylist</artifactId>
|
<artifactId>LastfmToSpotifyPlaylist</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.1-alpha</version>
|
||||||
|
|
||||||
<name>LastFM2SpotifyPlaylist</name>
|
<name>LastFM2SpotifyPlaylist</name>
|
||||||
<description>Creates a Spotify playlist from LastFM scrobble data.</description>
|
<description>Creates a Spotify playlist from LastFM scrobble data.</description>
|
||||||
@@ -80,6 +80,8 @@
|
|||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
<mainClass>de.b00tload.tools.lastfmtospotifyplaylist.LastFMToSpotify</mainClass>
|
<mainClass>de.b00tload.tools.lastfmtospotifyplaylist.LastFMToSpotify</mainClass>
|
||||||
|
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||||
|
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
|
||||||
</manifest>
|
</manifest>
|
||||||
</archive>
|
</archive>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -107,6 +109,11 @@
|
|||||||
<artifactId>slf4j-simple</artifactId>
|
<artifactId>slf4j-simple</artifactId>
|
||||||
<version>2.0.6</version>
|
<version>2.0.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>2.11.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -12,9 +12,7 @@ import de.umass.lastfm.User;
|
|||||||
import io.javalin.Javalin;
|
import io.javalin.Javalin;
|
||||||
import io.javalin.http.ContentType;
|
import io.javalin.http.ContentType;
|
||||||
import io.javalin.http.HttpStatus;
|
import io.javalin.http.HttpStatus;
|
||||||
import io.javalin.jetty.JettyUtil;
|
|
||||||
import io.javalin.util.JavalinLogger;
|
import io.javalin.util.JavalinLogger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import se.michaelthelin.spotify.SpotifyApi;
|
import se.michaelthelin.spotify.SpotifyApi;
|
||||||
import se.michaelthelin.spotify.model_objects.specification.Playlist;
|
import se.michaelthelin.spotify.model_objects.specification.Playlist;
|
||||||
|
|
||||||
@@ -79,6 +77,10 @@ public class LastFMToSpotify {
|
|||||||
System.setErr(new Logger.LogStream(System.err));
|
System.setErr(new Logger.LogStream(System.err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Integer.parseInt(configuration.get("logging.level")) !=0){
|
||||||
|
VersionChecker.checkVerion();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logLn("Authenticating with Spotify...", 1);
|
logLn("Authenticating with Spotify...", 1);
|
||||||
SpotifyApi.Builder build = SpotifyApi.builder();
|
SpotifyApi.Builder build = SpotifyApi.builder();
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package de.b00tload.tools.lastfmtospotifyplaylist.util;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class VersionChecker {
|
||||||
|
|
||||||
|
private static final String GITHUB_API_BASE_URL = "https://api.github.com/repos/B00tLoad/LastFMToSpotifyPlaylist";
|
||||||
|
|
||||||
|
|
||||||
|
public static void checkVerion() {
|
||||||
|
String currentVersion = VersionChecker.class.getPackage().getImplementationVersion();
|
||||||
|
String latestVersion = fetchLatestReleaseVersion();
|
||||||
|
if (currentVersion == null) {
|
||||||
|
System.out.println("Error: Failed to retrieve current version");
|
||||||
|
} else if (latestVersion == null) {
|
||||||
|
System.out.println("Error: Failed to retrieve latest release version");
|
||||||
|
} else if (currentVersion.compareTo(latestVersion) < 0) {
|
||||||
|
System.out.println("A new version is available: " + latestVersion);
|
||||||
|
} else {
|
||||||
|
System.out.println("You are running the latest version: " + currentVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String fetchLatestReleaseVersion() {
|
||||||
|
try (InputStream inputStream = (new URL(GITHUB_API_BASE_URL + "/releases/latest")).openStream()) {
|
||||||
|
String response = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
||||||
|
JsonObject release = JsonParser.parseString(response).getAsJsonObject();
|
||||||
|
return release.get("tag_name").getAsString().substring(1);
|
||||||
|
} catch (NullPointerException | IOException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user