initial commit

This commit is contained in:
aj 2019-05-26 18:30:35 +01:00
commit 63c5d0ef58
22 changed files with 1302 additions and 0 deletions

80
.gitignore vendored Normal file
View File

@ -0,0 +1,80 @@
# Directories #
/build/
/bin/
target/
# OS Files #
.DS_Store
*.class
# Package Files #
*.war
*.ear
*.db
######################
# Windows
######################
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini
######################
# OSX
######################
.DS_Store
.svn
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
######################
# Eclipse
######################
*.pydevproject
.project
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
/src/main/resources/rebel.xml
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
.gradle
/build/
/buildSrc/build
/buildSrc/subprojects/*/build
/subprojects/*/build
/subprojects/docs/src/samples/*/*/build
/subprojects/internal-android-performance-testing/build-android-libs

49
build.gradle Normal file
View File

@ -0,0 +1,49 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java Library project to get you started.
* For more details take a look at the Java Libraries chapter in the Gradle
* user guide available at https://docs.gradle.org/5.0/userguide/java_library_plugin.html
*/
plugins {
id 'java'
id 'application'
id 'eclipse'
id 'com.github.johnrengelman.shadow' version '5.0.0'
id 'org.openjfx.javafxplugin' version '0.0.7'
}
application {
mainClassName = 'sarsoo.spotframework.fx.SpotFramework'
}
javafx {
version = "12.0.1"
modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.graphics', 'javafx.web' ]
}
version = '0.1.0'
sourceCompatibility = 11
targetCompatibility = 11
repositories {
mavenCentral()
}
dependencies {
// The production code uses the SLF4J logging API at compile time
compileOnly 'org.slf4j:slf4j-api:1.7.25'
implementation 'com.mashape.unirest:unirest-java:1.4.9'
implementation 'org.json:json:20180813'
testImplementation('org.junit.jupiter:junit-jupiter-api:5.4.2')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.4.2')
}
test {
useJUnitPlatform()
}

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

172
gradlew vendored Executable file
View File

@ -0,0 +1,172 @@
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

84
gradlew.bat vendored Normal file
View File

@ -0,0 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

10
settings.gradle Normal file
View File

@ -0,0 +1,10 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user guide at https://docs.gradle.org/5.0/userguide/multi_project_builds.html
*/
rootProject.name = 'spotframework'

View File

@ -0,0 +1,26 @@
package sarsoo.spotframework.fx;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class SpotFramework extends Application{
@Override
public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/RootPane.fxml"));
Parent root = (Parent) loader.load();
Scene scene = new Scene(root, 1000, 800);
stage.setMinHeight(800);
stage.setMinWidth(960);
stage.setTitle("spotframework");
stage.setScene(scene);
stage.show();
}
}

View File

@ -0,0 +1,11 @@
package sarsoo.spotframework.fx.controller;
import javafx.fxml.FXML;
import javafx.scene.control.TabPane;
public class RootController {
@FXML
private TabPane tabPane;
}

View File

@ -0,0 +1,80 @@
package sarsoo.spotframework.model;
import java.util.ArrayList;
import java.util.stream.Collectors;
public class Album extends SpotifyObject {
private AlbumType type;
private ArrayList<Artist> artists;
private ArrayList<String> genres;
private ArrayList<Image> images;
private String label;
private ArrayList<Track> tracks;
public Album(String name, String id, String uri, String url, AlbumType type, ArrayList<Artist> artists) {
this.name = name;
this.id = id;
this.uri = uri;
this.url = url;
this.type = type;
this.artists = artists;
}
public AlbumType getType() {
return type;
}
public void setType(AlbumType type) {
this.type = type;
}
public ArrayList<Artist> getArtists() {
return artists;
}
public void setArtists(ArrayList<Artist> artists) {
this.artists = artists;
}
public ArrayList<String> getGenres() {
return genres;
}
public void setGenres(ArrayList<String> genres) {
this.genres = genres;
}
public ArrayList<Image> getImages() {
return images;
}
public void setImages(ArrayList<Image> images) {
this.images = images;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public ArrayList<Track> getTracks() {
return tracks;
}
public void setTracks(ArrayList<Track> tracks) {
this.tracks = tracks;
}
@Override
public String toString() {
return "album: " + name + " / " + String.join(", ", artists.stream().map(Artist::getName).collect(Collectors.toList()));
}
}

View File

@ -0,0 +1,9 @@
package sarsoo.spotframework.model;
public enum AlbumType {
ALBUM,
SINGLE,
COMPILATION
}

View File

@ -0,0 +1,38 @@
package sarsoo.spotframework.model;
import java.util.ArrayList;
public class Artist extends SpotifyObject {
private ArrayList<Image> images;
private ArrayList<String> genres;
public Artist(String name, String id, String uri, String url) {
this.name = name;
this.id = id;
this.uri = uri;
this.url = url;
}
public ArrayList<Image> getImages() {
return images;
}
public void setImages(ArrayList<Image> images) {
this.images = images;
}
public ArrayList<String> getGenres() {
return genres;
}
public void setGenres(ArrayList<String> genres) {
this.genres = genres;
}
@Override
public String toString() {
return "artist: " + name;
}
}

View File

@ -0,0 +1,27 @@
package sarsoo.spotframework.model;
public class Image {
private int height;
private String url;
private int width;
public Image(String url, int height, int width) {
this.url = url;
this.height = height;
this.width = width;
}
public int getHeight() {
return height;
}
public String getUrl() {
return url;
}
public int getWidth() {
return width;
}
}

View File

@ -0,0 +1,82 @@
package sarsoo.spotframework.model;
import java.util.ArrayList;
public class Playlist extends SpotifyObject {
private Boolean collaborative;
private Boolean isPublic;
private String description;
private User owner;
private ArrayList<Image> images;
private ArrayList<PlaylistTrack> tracks;
public Playlist(String name, String id, String uri, String url, Boolean collaborative, Boolean isPublic, User owner, ArrayList<Image> images) {
this.name = name;
this.id = id;
this.uri = uri;
this.url = url;
this.collaborative = collaborative;
this.isPublic = isPublic;
this.owner = owner;
this.images = images;
}
public Boolean getCollaborative() {
return collaborative;
}
public void setCollaborative(Boolean collaborative) {
this.collaborative = collaborative;
}
public Boolean getIsPublic() {
return isPublic;
}
public void setIsPublic(Boolean isPublic) {
this.isPublic = isPublic;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public User getOwner() {
return owner;
}
public void setOwner(User owner) {
this.owner = owner;
}
public ArrayList<Image> getImages() {
return images;
}
public void setImages(ArrayList<Image> images) {
this.images = images;
}
public ArrayList<PlaylistTrack> getTracks() {
return tracks;
}
public void setTracks(ArrayList<PlaylistTrack> tracks) {
this.tracks = tracks;
}
@Override
public String toString() {
return "playlist: " + name + " / " + owner.getName();
}
}

View File

@ -0,0 +1,43 @@
package sarsoo.spotframework.model;
import java.time.LocalDateTime;
import java.util.ArrayList;
public class PlaylistTrack extends Track {
private LocalDateTime addedAt;
private User addedBy;
private Boolean isLocal;
public PlaylistTrack(String name, String id, String uri, String url, Album album, LocalDateTime addedAt, User addedBy, Boolean isLocal,ArrayList<Artist> artists) {
super(name, id, uri, url, album, artists);
this.setAddedAt(addedAt);
this.setAddedBy(addedBy);
this.setIsLocal(isLocal);
}
public LocalDateTime getAddedAt() {
return addedAt;
}
public void setAddedAt(LocalDateTime addedAt) {
this.addedAt = addedAt;
}
public User getAddedBy() {
return addedBy;
}
public void setAddedBy(User addedBy) {
this.addedBy = addedBy;
}
public Boolean getIsLocal() {
return isLocal;
}
public void setIsLocal(Boolean isLocal) {
this.isLocal = isLocal;
}
}

View File

@ -0,0 +1,44 @@
package sarsoo.spotframework.model;
public class SpotifyObject {
protected String uri;
protected String id;
protected String url;
protected String name;
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}

View File

@ -0,0 +1,38 @@
package sarsoo.spotframework.model;
import java.util.ArrayList;
import java.util.stream.Collectors;
public class Track extends SpotifyObject {
private ArrayList<Artist> artists = new ArrayList<>();
private Album album;
public Track(String name, String id, String uri, String url, Album album, ArrayList<Artist> artists) {
this.name = name;
this.id = id;
this.uri = uri;
this.url = url;
this.album = album;
this.artists = artists;
}
public ArrayList<Artist> getArtists() {
return artists;
}
public void setArtists(ArrayList<Artist> artists) {
this.artists = artists;
}
public Album getAlbum() {
return album;
}
public void setAlbum(Album album) {
this.album = album;
}
@Override
public String toString() {
return "track: " + name + " / " + album.getName() + " / " + String.join(", ", artists.stream().map(Artist::getName).collect(Collectors.toList()));
}
}

View File

@ -0,0 +1,19 @@
package sarsoo.spotframework.model;
public class User extends SpotifyObject {
public User(String name, String id, String uri, String url) {
this.name = name;
this.id = id;
this.uri = uri;
this.url = url;
}
@Override
public String toString() {
return "user: " + name;
}
}

View File

@ -0,0 +1,247 @@
package sarsoo.spotframework.spotify;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.mashape.unirest.request.HttpRequest;
import sarsoo.spotframework.model.Album;
import sarsoo.spotframework.model.AlbumType;
import sarsoo.spotframework.model.Artist;
import sarsoo.spotframework.model.Image;
import sarsoo.spotframework.model.Playlist;
import sarsoo.spotframework.model.PlaylistTrack;
import sarsoo.spotframework.model.Track;
import sarsoo.spotframework.model.User;
public class SpotNetwork {
private String userName;
private String accessToken;
public SpotNetwork(String userName, String accessToken) {
this.userName = userName;
this.accessToken = accessToken;
}
public SpotNetwork(String accessToken) {
this.accessToken = accessToken;
}
public ArrayList<Playlist> getUserPlaylists() {
List<JSONObject> list = makePagedGetRequest("https://api.spotify.com/v1/me/playlists");
ArrayList<Playlist> playlists = new ArrayList<>();
list.stream().forEach(t -> playlists.add(parseSimplifiedPlaylist(t)));
return playlists;
}
public ArrayList<PlaylistTrack> getPlaylistTracks(String playlistId) {
List<JSONObject> list = makePagedGetRequest(String.format("https://api.spotify.com/v1/playlists/%s/tracks", playlistId));
ArrayList<PlaylistTrack> tracks = new ArrayList<>();
list.stream().forEach(t -> tracks.add(parsePlaylistTrack(t)));
return tracks;
}
private ArrayList<JSONObject> makePagedGetRequest(String url) {
HttpRequest request;
try {
request = Unirest.get(url).header("Accept", "application/json");
request.header("Authorization", "Bearer " + accessToken);
HttpResponse<JsonNode> response = request.asJson();
if (response.getStatus() >= 200 && response.getStatus() < 300) {
JSONObject obj = new JSONObject(response.getBody().toString());
ArrayList<JSONObject> list = new ArrayList<>();
for (Object jsonObj : obj.getJSONArray("items")) {
list.add((JSONObject) jsonObj);
}
try {
String next = obj.getString("next");
list.addAll(makePagedGetRequest(next));
} catch (JSONException e) {
System.out.println("end");
}
return list;
} else {
JSONObject obj = new JSONObject(response.getBody().toString());
System.out.println(obj);
// throw new ApiCallException(method, obj.getInt("error"), obj.getString("message"));
}
} catch (UnirestException e) {
e.printStackTrace();
}
return null;
}
private JSONObject makeGetRequest(String method, HashMap<String, String> parameters,
HashMap<String, String> headers) {
HttpRequest request;
try {
request = Unirest.get("https://api.spotify.com/v1/" + method).header("Accept", "application/json");
request.header("Authorization", accessToken);
if (headers != null) {
for (String key : headers.keySet()) {
request = request.header(key, headers.get(key));
}
}
if (parameters != null) {
for (String key : parameters.keySet()) {
request = request.queryString(key, parameters.get(key));
}
}
HttpResponse<JsonNode> response = request.asJson();
if (response.getStatus() >= 200 && response.getStatus() < 300) {
return new JSONObject(response.getBody().toString());
} else {
JSONObject obj = new JSONObject(response.getBody().toString());
// throw new ApiCallException(method, obj.getInt("error"), obj.getString("message"));
}
} catch (UnirestException e) {
e.printStackTrace();
}
return null;
}
private Playlist parseSimplifiedPlaylist(JSONObject object) {
JSONObject ownerObj = object.getJSONObject("owner");
User owner = new User(ownerObj.getString("display_name"), ownerObj.getString("id"), ownerObj.getString("uri"),
ownerObj.getString("href"));
JSONArray imageObj = object.getJSONArray("images");
ArrayList<Image> images = new ArrayList<>();
for (Object i : imageObj) {
JSONObject image = (JSONObject) i;
System.out.println(image.get("height"));
int height = 0;
int width = 0;
try {
height = image.getInt("height");
width = image.getInt("width");
} catch (JSONException e) {
System.out.println("null image dimensions");
}
images.add(new Image(image.getString("url"), height, width));
}
Playlist playlist = new Playlist(object.getString("name"), object.getString("id"), object.getString("uri"),
object.getString("href"), object.getBoolean("collaborative"), object.getBoolean("public"), owner,
images);
return playlist;
}
private Artist parseSimplifiedArtist(JSONObject object) {
return new Artist(object.getString("name"), object.getString("id"), object.getString("uri"),
object.getString("href"));
}
private Album parseSimplifiedAlbum(JSONObject object) {
AlbumType type = null;
switch (object.getString("album_type")) {
case "album":
type = AlbumType.ALBUM;
break;
case "single":
type = AlbumType.SINGLE;
break;
case "compilation":
type = AlbumType.COMPILATION;
break;
}
ArrayList<Artist> artists = new ArrayList<>();
JSONArray artistObj = object.getJSONArray("artists");
for (Object i : artistObj) {
JSONObject artist = (JSONObject) i;
artists.add(parseSimplifiedArtist(artist));
}
Album album = new Album(object.getString("name"), object.getString("id"), object.getString("uri"),
object.getString("href"), type, artists);
return album;
}
private User parseUser(JSONObject object) {
return new User(object.getString("id"), object.getString("id"), object.getString("uri"),
object.getString("href"));
}
private PlaylistTrack parsePlaylistTrack(JSONObject object) {
JSONObject trackObj = object.getJSONObject("track");
Album album = parseSimplifiedAlbum(trackObj.getJSONObject("album"));
ArrayList<Artist> artists = new ArrayList<>();
JSONArray artistObj = trackObj.getJSONArray("artists");
for (Object i : artistObj) {
JSONObject artist = (JSONObject) i;
artists.add(parseSimplifiedArtist(artist));
}
PlaylistTrack track = new PlaylistTrack(trackObj.getString("name"), trackObj.getString("id"),
trackObj.getString("uri"), trackObj.getString("href"), album,
LocalDateTime.ofInstant(Instant.parse(object.getString("added_at")), ZoneId.systemDefault()), parseUser(object.getJSONObject("added_by")),
trackObj.getBoolean("is_local"), artists);
return track;
}
}

View File

@ -0,0 +1,161 @@
.vBoxStats{
-fx-background-color: #001a44;
}
.gridPane{
-fx-background-color: #a2aec1;
}
.vBoxStatsLabel{
-fx-text-fill: white;
}
.pieChart{
-fx-start-angle: 90;
}
.chart-vertical-grid-lines {
-fx-stroke: #404040;
}
.chart-horizontal-grid-lines {
-fx-stroke: #404040;
}
.chart-bar {
-fx-background-color: #202124;
}
.chart-plot-background {
-fx-background-color: transparent;
}
.chart-pie-label {
-fx-fill: white;
}
.chart-legend {
-fx-background-color: transparent;
}
.chart-title {
-fx-text-fill: white;
}
.button {
-fx-background-color: #4D4D4D;
-fx-text-fill: white;
}
.text-field {
-fx-background-color: #4D4D4D;
-fx-text-fill: white;
}
.menu-button {
-fx-background-color: #4D4D4D;
-fx-text-fill: white;
}
.choice-box {
-fx-background-color: #4D4D4D;
-fx-text-fill: white;
}
.backGround {
-fx-background-color: #202124;
}
.titled-pane {
-fx-background-color: #202124;
}
.highlight {
-fx-background-color: #131313;
}
.split-pane {
-fx-background-color: #202124;
}
.split-pane:horizontal > .split-pane-divider {
-fx-background-color: #4D4D4D;
}
.split-pane:vertical > .split-pane-divider {
-fx-background-color: #4D4D4D;
}
.text-area {
-fx-background-color: #202124;
}
.menu-bar {
-fx-background-color: #202124;
}
.menu {
-fx-background-color: #202124;
}
.menu-item {
-fx-background-color: #202124;
}
.context-menu {
-fx-background-color: #202124;
}
.menu-item:focused {
-fx-background-color: #4D4D4D;
}
.check-box {
-fx-text-fill: white;
}
.label {
-fx-text-fill: white;
}
.tab-pane .tab-header-area .tab-header-background {
-fx-opacity: 0;
}
.tab-pane
{
-fx-tab-min-width:70px;
}
.tool-bar {
-fx-background-color: #131313;
}
.tab{
-fx-background-insets: 0 1 0 1,0,0;
}
.tab-pane .tab
{
-fx-background-color: #202124;
}
.tab-pane .tab:selected
{
-fx-background-color: #3c3c3c;
}
.tab .tab-label {
-fx-alignment: CENTER;
-fx-text-fill: #828282;
//-fx-font-size: 12px;
-fx-font-weight: bold;
}
.tab:selected .tab-label {
-fx-alignment: CENTER;
-fx-text-fill: white;
}

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.TilePane?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" stylesheets="@../styles/mainPane.css" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.spotframework.fx.controller.RootController">
<top>
<MenuBar fx:id="menuBar" BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<center>
<TabPane fx:id="tabPane" prefHeight="200.0" prefWidth="200.0" styleClass="highlight" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER">
<tabs>
<Tab fx:id="homeTab" closable="false" text="home">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<ScrollPane fx:id="scrollPane" prefHeight="338.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<TilePane fx:id="tilePane" />
</content>
</ScrollPane>
</children></AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</center>
</BorderPane>

View File

@ -0,0 +1,34 @@
package sarsoo.spotframework.spotify;
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import java.util.Scanner;
import org.junit.jupiter.api.Test;
import sarsoo.spotframework.model.Playlist;
import sarsoo.spotframework.model.PlaylistTrack;
class SpotNetworkTest {
@Test
void test() {
Scanner scan = new Scanner(System.in);
SpotNetwork net = new SpotNetwork(scan.nextLine());
ArrayList<Playlist> playlists = net.getUserPlaylists();
ArrayList<PlaylistTrack> tracks = net.getPlaylistTracks(playlists.get(0).getId());
tracks.stream().forEach(t -> System.out.println(t.getAddedAt()));
System.out.println(tracks.size());
// .stream().forEach(System.out::println);
scan.close();
assertTrue(true);
}
}