added logging
This commit is contained in:
parent
f4f2fbf4e6
commit
d80ba0c3ce
@ -1,5 +1,11 @@
|
|||||||
package sarsoo.fmframework.fm;
|
package sarsoo.fmframework.fm;
|
||||||
|
|
||||||
|
import sarsoo.fmframework.log.Log;
|
||||||
|
import sarsoo.fmframework.log.Logger;
|
||||||
|
import sarsoo.fmframework.log.console.ConsoleHandler;
|
||||||
|
import sarsoo.fmframework.log.entry.ErrorEntry;
|
||||||
|
import sarsoo.fmframework.log.entry.InfoEntry;
|
||||||
|
import sarsoo.fmframework.log.entry.LogEntry;
|
||||||
import sarsoo.fmframework.music.Album;
|
import sarsoo.fmframework.music.Album;
|
||||||
import sarsoo.fmframework.music.Album.AlbumBuilder;
|
import sarsoo.fmframework.music.Album.AlbumBuilder;
|
||||||
import sarsoo.fmframework.music.Artist;
|
import sarsoo.fmframework.music.Artist;
|
||||||
@ -8,7 +14,6 @@ import sarsoo.fmframework.music.FMObj;
|
|||||||
import sarsoo.fmframework.music.Track;
|
import sarsoo.fmframework.music.Track;
|
||||||
import sarsoo.fmframework.music.Track.TrackBuilder;
|
import sarsoo.fmframework.music.Track.TrackBuilder;
|
||||||
import sarsoo.fmframework.music.Wiki;
|
import sarsoo.fmframework.music.Wiki;
|
||||||
import sarsoo.fmframework.util.ConsoleHandler;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@ -49,8 +54,9 @@ public class FmNetwork {
|
|||||||
* @return Album
|
* @return Album
|
||||||
*/
|
*/
|
||||||
public Album getAlbum(String name, String artist) {
|
public Album getAlbum(String name, String artist) {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>getAlbum: " + name + " " + artist);
|
Log log = Logger.getLog();
|
||||||
|
log.log(new LogEntry("getAlbum").addArg(name).addArg(artist));
|
||||||
|
|
||||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||||
|
|
||||||
@ -77,43 +83,32 @@ public class FmNetwork {
|
|||||||
try {
|
try {
|
||||||
builder.setMbid(albumJson.getString("mbid"));
|
builder.setMbid(albumJson.getString("mbid"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getAlbum").addArg("no mbid for").addArg(nameIn).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No MBID for " + nameIn + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No MBID for " + nameIn + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder.setUrl(albumJson.getString("url"));
|
builder.setUrl(albumJson.getString("url"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getAlbum").addArg("no url for").addArg(nameIn).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No Url for " + nameIn + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No Url for " + nameIn + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder.setListeners(albumJson.getInt("listeners"));
|
builder.setListeners(albumJson.getInt("listeners"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getAlbum").addArg("no listeners for").addArg(nameIn).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No listeners for " + nameIn + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No listeners for " + nameIn + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder.setPlayCount(albumJson.getInt("playcount"));
|
builder.setPlayCount(albumJson.getInt("playcount"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getAlbum").addArg("no play count for").addArg(nameIn).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No play count for " + nameIn + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No play count for " + nameIn + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder.setUserPlayCount(albumJson.getInt("userplaycount"));
|
builder.setUserPlayCount(albumJson.getInt("userplaycount"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
log.log(new InfoEntry("getAlbum").addArg("no user play count for").addArg(nameIn)
|
||||||
|
.addArg(e.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -125,19 +120,13 @@ public class FmNetwork {
|
|||||||
builder.setWiki(wiki);
|
builder.setWiki(wiki);
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getAlbum").addArg("no wiki for").addArg(nameIn).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No wiki for " + nameIn + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No wiki for " + nameIn + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getAlbum").addArg("album name not found").addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: Album Name Not Found, " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: Album Name Not Found, " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -151,8 +140,9 @@ public class FmNetwork {
|
|||||||
* @return Artist
|
* @return Artist
|
||||||
*/
|
*/
|
||||||
public Artist getArtist(String name) {
|
public Artist getArtist(String name) {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>getArtist: " + name);
|
Log log = Logger.getLog();
|
||||||
|
log.log(new LogEntry("getArtist").addArg(name));
|
||||||
|
|
||||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||||
|
|
||||||
@ -176,44 +166,34 @@ public class FmNetwork {
|
|||||||
try {
|
try {
|
||||||
builder.setMbid(artistJson.getString("mbid"));
|
builder.setMbid(artistJson.getString("mbid"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getArtist").addArg("no mbid for").addArg(artistName).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No MBID for " + artistName + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No MBID for " + artistName + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder.setUrl(artistJson.getString("url"));
|
builder.setUrl(artistJson.getString("url"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getArtist").addArg("no url for").addArg(artistName).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No Url for " + artistName + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No Url for " + artistName + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder.setListeners(artistJson.getJSONObject("stats").getInt("listeners"));
|
builder.setListeners(artistJson.getJSONObject("stats").getInt("listeners"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getArtist").addArg("no listeners for").addArg(artistName)
|
||||||
ConsoleHandler.getConsole().write("ERROR: No listeners for " + artistName + " , " + e.getMessage());
|
.addArg(e.getMessage()));
|
||||||
else
|
|
||||||
System.err.println("ERROR: No listeners for " + artistName + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder.setPlayCount(artistJson.getJSONObject("stats").getInt("playcount"));
|
builder.setPlayCount(artistJson.getJSONObject("stats").getInt("playcount"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getArtist").addArg("no play count for").addArg(artistName)
|
||||||
ConsoleHandler.getConsole()
|
.addArg(e.getMessage()));
|
||||||
.write("ERROR: No play count for " + artistName + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No play count for " + artistName + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder.setUserPlayCount(artistJson.getJSONObject("stats").getInt("userplaycount"));
|
builder.setUserPlayCount(artistJson.getJSONObject("stats").getInt("userplaycount"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
log.log(new InfoEntry("getArtist").addArg("no user play count for").addArg(artistName)
|
||||||
|
.addArg(e.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -225,19 +205,13 @@ public class FmNetwork {
|
|||||||
builder.setWiki(wiki);
|
builder.setWiki(wiki);
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getArtist").addArg("no wiki for").addArg(artistName).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No wiki for " + artistName + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No wiki for " + artistName + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getArtist").addArg("artist name not found").addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: Arist Name Not Found, " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: Arist Name Not Found, " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -252,8 +226,9 @@ public class FmNetwork {
|
|||||||
* @return Track
|
* @return Track
|
||||||
*/
|
*/
|
||||||
public Track getTrack(String name, String artist) {
|
public Track getTrack(String name, String artist) {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>getTrack: " + name + " " + artist);
|
Log log = Logger.getLog();
|
||||||
|
log.log(new LogEntry("getTrack").addArg(name).addArg(artist));
|
||||||
|
|
||||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||||
|
|
||||||
@ -280,43 +255,32 @@ public class FmNetwork {
|
|||||||
try {
|
try {
|
||||||
builder.setMbid(trackJson.getString("mbid"));
|
builder.setMbid(trackJson.getString("mbid"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getTrack").addArg("no mbid for").addArg(nameIn).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No MBID for " + nameIn + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No MBID for " + nameIn + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder.setUrl(trackJson.getString("url"));
|
builder.setUrl(trackJson.getString("url"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getTrack").addArg("no url for").addArg(nameIn).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No Url for " + nameIn + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No Url for " + nameIn + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder.setListeners(trackJson.getInt("listeners"));
|
builder.setListeners(trackJson.getInt("listeners"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getTrack").addArg("no listeners for").addArg(nameIn).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No listeners for " + nameIn + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No listeners for " + nameIn + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder.setPlayCount(trackJson.getInt("playcount"));
|
builder.setPlayCount(trackJson.getInt("playcount"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getTrack").addArg("no play count for").addArg(nameIn).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No play count for " + nameIn + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No play count for " + nameIn + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder.setUserPlayCount(trackJson.getInt("userplaycount"));
|
builder.setUserPlayCount(trackJson.getInt("userplaycount"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
log.log(new InfoEntry("getTrack").addArg("no user play count for").addArg(nameIn)
|
||||||
|
.addArg(e.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -328,19 +292,13 @@ public class FmNetwork {
|
|||||||
builder.setWiki(wiki);
|
builder.setWiki(wiki);
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getTrack").addArg("no wiki for").addArg(nameIn).addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: No wiki for " + nameIn + " , " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: No wiki for " + nameIn + " , " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (ConsoleHandler.isVerbose())
|
log.log(new InfoEntry("getTrack").addArg("track name not found").addArg(e.getMessage()));
|
||||||
ConsoleHandler.getConsole().write("ERROR: Album Name Not Found, " + e.getMessage());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR: Album Name Not Found, " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -353,8 +311,8 @@ public class FmNetwork {
|
|||||||
* @return Refreshed Album
|
* @return Refreshed Album
|
||||||
*/
|
*/
|
||||||
public Album refresh(Album album) {
|
public Album refresh(Album album) {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>refreshAlbum: " + album.getName() + " " + album.getArtist().getName());
|
Logger.getLog().log(new LogEntry("refreshAlbum").addArg(album.getName()).addArg(album.getArtist().getName()));
|
||||||
|
|
||||||
return getAlbum(album.getName(), album.getArtist().getName());
|
return getAlbum(album.getName(), album.getArtist().getName());
|
||||||
}
|
}
|
||||||
@ -366,8 +324,8 @@ public class FmNetwork {
|
|||||||
* @return Refreshed Artist
|
* @return Refreshed Artist
|
||||||
*/
|
*/
|
||||||
public Artist refresh(Artist artist) {
|
public Artist refresh(Artist artist) {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>refreshArtist: " + artist.getName());
|
Logger.getLog().log(new LogEntry("refreshArtist").addArg(artist.getName()));
|
||||||
|
|
||||||
return getArtist(artist.getName());
|
return getArtist(artist.getName());
|
||||||
}
|
}
|
||||||
@ -379,8 +337,8 @@ public class FmNetwork {
|
|||||||
* @return Refreshed Track
|
* @return Refreshed Track
|
||||||
*/
|
*/
|
||||||
public Track refresh(Track track) {
|
public Track refresh(Track track) {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>refreshTrack: " + track.getName() + " " + track.getArtist().getName());
|
Logger.getLog().log(new LogEntry("refreshTrack").addArg(track.getName()).addArg(track.getArtist().getName()));
|
||||||
|
|
||||||
Track refreshedTrack = getTrack(track.getName(), track.getArtist().getName());
|
Track refreshedTrack = getTrack(track.getName(), track.getArtist().getName());
|
||||||
|
|
||||||
@ -440,11 +398,7 @@ public class FmNetwork {
|
|||||||
return new JSONObject(response.getBody().toString());
|
return new JSONObject(response.getBody().toString());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.out.println(response.getBody());
|
Logger.getLog().logError(new ErrorEntry("HTTP Get").setErrorCode(response.getStatus()));
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write("ERROR : HTTP Request Error " + response.getStatus());
|
|
||||||
else
|
|
||||||
System.err.println("ERROR : HTTP Request Error " + response.getStatus());
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (UnirestException e) {
|
} catch (UnirestException e) {
|
||||||
@ -453,15 +407,4 @@ public class FmNetwork {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class RequestParam {
|
|
||||||
|
|
||||||
int intparam;
|
|
||||||
String strparam;
|
|
||||||
|
|
||||||
public RequestParam(int param) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,14 @@ import java.util.HashMap;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import sarsoo.fmframework.log.Log;
|
||||||
|
import sarsoo.fmframework.log.Logger;
|
||||||
|
import sarsoo.fmframework.log.console.ConsoleHandler;
|
||||||
|
import sarsoo.fmframework.log.entry.InfoEntry;
|
||||||
|
import sarsoo.fmframework.log.entry.LogEntry;
|
||||||
import sarsoo.fmframework.music.Artist;
|
import sarsoo.fmframework.music.Artist;
|
||||||
import sarsoo.fmframework.music.Tag;
|
import sarsoo.fmframework.music.Tag;
|
||||||
import sarsoo.fmframework.music.Track;
|
import sarsoo.fmframework.music.Track;
|
||||||
import sarsoo.fmframework.util.ConsoleHandler;
|
|
||||||
import sarsoo.fmframework.util.FMObjList;
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
|
|
||||||
public class FmUserNetwork extends FmNetwork {
|
public class FmUserNetwork extends FmNetwork {
|
||||||
@ -63,8 +67,8 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
* @return User
|
* @return User
|
||||||
*/
|
*/
|
||||||
public User getUser() {
|
public User getUser() {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>getUser");
|
Logger.getLog().log(new LogEntry("getUser"));
|
||||||
|
|
||||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||||
|
|
||||||
@ -84,8 +88,8 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
* @return User real name
|
* @return User real name
|
||||||
*/
|
*/
|
||||||
public String getUserRealName() {
|
public String getUserRealName() {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>getUserRealname");
|
Logger.getLog().log(new LogEntry("getUserRealName"));
|
||||||
|
|
||||||
return getUser().getRealName();
|
return getUser().getRealName();
|
||||||
}
|
}
|
||||||
@ -96,8 +100,8 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
* @return Total scrobble count
|
* @return Total scrobble count
|
||||||
*/
|
*/
|
||||||
public int getUserScrobbleCount() {
|
public int getUserScrobbleCount() {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>getUserScrobbleCount");
|
Logger.getLog().log(new LogEntry("getUserScrobbleCount"));
|
||||||
|
|
||||||
return getUser().getScrobbleCount();
|
return getUser().getScrobbleCount();
|
||||||
}
|
}
|
||||||
@ -108,8 +112,8 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
* @return Last track
|
* @return Last track
|
||||||
*/
|
*/
|
||||||
public Track getLastTrack() {
|
public Track getLastTrack() {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>getLastTrack");
|
Logger.getLog().log(new LogEntry("getLastTrack"));
|
||||||
|
|
||||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||||
|
|
||||||
@ -135,8 +139,8 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
* @return Scrobble count today
|
* @return Scrobble count today
|
||||||
*/
|
*/
|
||||||
public int getScrobblesToday() {
|
public int getScrobblesToday() {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>getScrobblesToday");
|
Logger.getLog().log(new LogEntry("getScrobblesToday"));
|
||||||
|
|
||||||
LocalDate local = LocalDate.now();
|
LocalDate local = LocalDate.now();
|
||||||
|
|
||||||
@ -166,8 +170,9 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
* @return Scrobble count
|
* @return Scrobble count
|
||||||
*/
|
*/
|
||||||
public int getScrobbleCountByDate(int day, int month, int year) {
|
public int getScrobbleCountByDate(int day, int month, int year) {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>getScrobblesByDate " + day + "." + month + "." + year);
|
Logger.getLog().log(new LogEntry("getScrobblesByDate").addArg(Integer.toString(day))
|
||||||
|
.addArg(Integer.toString(month)).addArg(Integer.toString(year)));
|
||||||
|
|
||||||
LocalDate startDate = LocalDate.of(year, month, day);
|
LocalDate startDate = LocalDate.of(year, month, day);
|
||||||
|
|
||||||
@ -197,8 +202,8 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
* @return Scrobble count
|
* @return Scrobble count
|
||||||
*/
|
*/
|
||||||
public int getScrobbleCountByDeltaDay(int day) {
|
public int getScrobbleCountByDeltaDay(int day) {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>getScrobblesByDeltaDay " + day);
|
Logger.getLog().log(new LogEntry("getScrobblesByDeltaDay").addArg(Integer.toString(day)));
|
||||||
|
|
||||||
LocalDate local = LocalDate.now();
|
LocalDate local = LocalDate.now();
|
||||||
|
|
||||||
@ -228,8 +233,8 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
* @return List of tags
|
* @return List of tags
|
||||||
*/
|
*/
|
||||||
public ArrayList<Tag> getTags() {
|
public ArrayList<Tag> getTags() {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>getTags");
|
Logger.getLog().log(new LogEntry("getTags"));
|
||||||
|
|
||||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||||
|
|
||||||
@ -265,8 +270,8 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
* @return FMObjList of artists
|
* @return FMObjList of artists
|
||||||
*/
|
*/
|
||||||
public FMObjList getTag(String tagName) {
|
public FMObjList getTag(String tagName) {
|
||||||
if (ConsoleHandler.isVerbose())
|
|
||||||
ConsoleHandler.getConsole().write(">>getTag: " + tagName);
|
Logger.getLog().log(new LogEntry("getTag").addArg(tagName));
|
||||||
|
|
||||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||||
|
|
||||||
@ -277,8 +282,7 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
|
|
||||||
JSONObject obj = makeGetRequest("user.getpersonaltags", parameters);
|
JSONObject obj = makeGetRequest("user.getpersonaltags", parameters);
|
||||||
|
|
||||||
JSONArray tagJsonArray = obj.getJSONObject("taggings")
|
JSONArray tagJsonArray = obj.getJSONObject("taggings").getJSONObject("artists").getJSONArray("artist");
|
||||||
.getJSONObject("artists").getJSONArray("artist");
|
|
||||||
|
|
||||||
JSONObject artistJson;
|
JSONObject artistJson;
|
||||||
|
|
||||||
@ -293,8 +297,7 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
|
|
||||||
Artist artist = getArtist(artistJson.getString("name"));
|
Artist artist = getArtist(artistJson.getString("name"));
|
||||||
|
|
||||||
if (ConsoleHandler.isVerbose())
|
Logger.getLog().log(new InfoEntry("Tag").addArg(tagName).addArg(artist.getName()));
|
||||||
ConsoleHandler.getConsole().write(">Tag: " + tagName + ", " + artist.getName());
|
|
||||||
|
|
||||||
list.add(artist);
|
list.add(artist);
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package sarsoo.fmframework.fx;
|
|||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
import sarsoo.fmframework.util.Console;
|
import sarsoo.fmframework.log.console.Console;
|
||||||
|
|
||||||
public class TextAreaConsole implements Console{
|
public class TextAreaConsole implements Console{
|
||||||
|
|
||||||
|
@ -28,13 +28,15 @@ import sarsoo.fmframework.fx.tab.FMObjListEditTab;
|
|||||||
import sarsoo.fmframework.fx.tab.FMObjListTab;
|
import sarsoo.fmframework.fx.tab.FMObjListTab;
|
||||||
import sarsoo.fmframework.fx.tab.ScrobbleChartTab;
|
import sarsoo.fmframework.fx.tab.ScrobbleChartTab;
|
||||||
import sarsoo.fmframework.fx.tab.TrackTab;
|
import sarsoo.fmframework.fx.tab.TrackTab;
|
||||||
|
import sarsoo.fmframework.log.Log;
|
||||||
|
import sarsoo.fmframework.log.Logger;
|
||||||
|
import sarsoo.fmframework.log.console.ConsoleHandler;
|
||||||
import sarsoo.fmframework.fx.FmFramework;
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.music.Album;
|
import sarsoo.fmframework.music.Album;
|
||||||
import sarsoo.fmframework.music.Artist;
|
import sarsoo.fmframework.music.Artist;
|
||||||
import sarsoo.fmframework.music.Tag;
|
import sarsoo.fmframework.music.Tag;
|
||||||
import sarsoo.fmframework.music.Track;
|
import sarsoo.fmframework.music.Track;
|
||||||
import sarsoo.fmframework.net.Key;
|
import sarsoo.fmframework.net.Key;
|
||||||
import sarsoo.fmframework.util.ConsoleHandler;
|
|
||||||
import sarsoo.fmframework.util.FMObjList;
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
import sarsoo.fmframework.util.Reference;
|
import sarsoo.fmframework.util.Reference;
|
||||||
import sarsoo.fmframework.util.tagpool.TagPool;
|
import sarsoo.fmframework.util.tagpool.TagPool;
|
||||||
@ -54,7 +56,8 @@ public class RootController {
|
|||||||
public void initialize() {
|
public void initialize() {
|
||||||
// Reference.setUserName("sarsoo");
|
// Reference.setUserName("sarsoo");
|
||||||
|
|
||||||
ConsoleHandler.setVerbose(TextAreaConsole.getInstance());
|
Logger.setLog(new Log(TextAreaConsole.getInstance(), false));
|
||||||
|
// ConsoleHandler.setVerbose(TextAreaConsole.getInstance());
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
68
src/main/java/sarsoo/fmframework/log/Log.java
Normal file
68
src/main/java/sarsoo/fmframework/log/Log.java
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package sarsoo.fmframework.log;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import sarsoo.fmframework.log.console.Console;
|
||||||
|
import sarsoo.fmframework.log.entry.ErrorEntry;
|
||||||
|
import sarsoo.fmframework.log.entry.InfoEntry;
|
||||||
|
import sarsoo.fmframework.log.entry.LogEntry;
|
||||||
|
|
||||||
|
public class Log {
|
||||||
|
|
||||||
|
private ArrayList<Console> consoles = new ArrayList<Console>();
|
||||||
|
|
||||||
|
private Boolean writeToSTDOut;
|
||||||
|
|
||||||
|
private ArrayList<LogEntry> logList = new ArrayList<LogEntry>();
|
||||||
|
private ArrayList<InfoEntry> infoList = new ArrayList<InfoEntry>();
|
||||||
|
private ArrayList<ErrorEntry> errorList = new ArrayList<ErrorEntry>();
|
||||||
|
|
||||||
|
public Log() {
|
||||||
|
writeToSTDOut = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Log(Console console, Boolean toSTD) {
|
||||||
|
|
||||||
|
consoles.add(console);
|
||||||
|
|
||||||
|
writeToSTDOut = toSTD;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearConsoles() {
|
||||||
|
consoles.clear();
|
||||||
|
writeToSTDOut = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void log(LogEntry entry) {
|
||||||
|
logList.add(entry);
|
||||||
|
writeLog(entry.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logInfo(InfoEntry entry) {
|
||||||
|
infoList.add(entry);
|
||||||
|
writeLog(entry.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logError(ErrorEntry entry) {
|
||||||
|
errorList.add(entry);
|
||||||
|
writeLog(entry.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void writeLog(String logString) {
|
||||||
|
|
||||||
|
if (consoles.size() > 0) {
|
||||||
|
for (Console i : consoles) {
|
||||||
|
i.write(logString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (writeToSTDOut == true) {
|
||||||
|
System.out.println(logString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
src/main/java/sarsoo/fmframework/log/Logger.java
Normal file
15
src/main/java/sarsoo/fmframework/log/Logger.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package sarsoo.fmframework.log;
|
||||||
|
|
||||||
|
public class Logger {
|
||||||
|
|
||||||
|
private static Log log = new Log();
|
||||||
|
|
||||||
|
public static Log getLog() {
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLog(Log logIn) {
|
||||||
|
log = logIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package sarsoo.fmframework.util;
|
package sarsoo.fmframework.log.console;
|
||||||
|
|
||||||
public interface Console {
|
public interface Console {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package sarsoo.fmframework.util;
|
package sarsoo.fmframework.log.console;
|
||||||
|
|
||||||
public class ConsoleHandler {
|
public class ConsoleHandler {
|
||||||
|
|
38
src/main/java/sarsoo/fmframework/log/entry/ErrorEntry.java
Normal file
38
src/main/java/sarsoo/fmframework/log/entry/ErrorEntry.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package sarsoo.fmframework.log.entry;
|
||||||
|
|
||||||
|
public class ErrorEntry extends LogEntry {
|
||||||
|
|
||||||
|
protected int errorCode;
|
||||||
|
|
||||||
|
public ErrorEntry(String methodIn) {
|
||||||
|
super(methodIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorEntry setErrorCode(int error) {
|
||||||
|
errorCode = error;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
String logString = String.format("%s !!%s", timestamp, method);
|
||||||
|
|
||||||
|
if (errorCode != 0) {
|
||||||
|
logString += String.format(" (%i)", errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args != null) {
|
||||||
|
if (args.size() > 0) {
|
||||||
|
|
||||||
|
logString += ":";
|
||||||
|
|
||||||
|
for (String i : args) {
|
||||||
|
logString += " " + i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return logString;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
27
src/main/java/sarsoo/fmframework/log/entry/InfoEntry.java
Normal file
27
src/main/java/sarsoo/fmframework/log/entry/InfoEntry.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package sarsoo.fmframework.log.entry;
|
||||||
|
|
||||||
|
public class InfoEntry extends LogEntry {
|
||||||
|
|
||||||
|
public InfoEntry(String methodIn) {
|
||||||
|
super(methodIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
String logString = String.format("%s \t>%s", timestamp, method);
|
||||||
|
|
||||||
|
if (args != null) {
|
||||||
|
if (args.size() > 0) {
|
||||||
|
|
||||||
|
logString += ":";
|
||||||
|
|
||||||
|
for (String i : args) {
|
||||||
|
logString += " " + i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return logString;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
src/main/java/sarsoo/fmframework/log/entry/LogEntry.java
Normal file
60
src/main/java/sarsoo/fmframework/log/entry/LogEntry.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package sarsoo.fmframework.log.entry;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class LogEntry {
|
||||||
|
|
||||||
|
protected String method;
|
||||||
|
protected ArrayList<String> args;
|
||||||
|
protected LocalDateTime timestamp;
|
||||||
|
|
||||||
|
public LogEntry(String methodIn) {
|
||||||
|
method = methodIn;
|
||||||
|
timestamp = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethod() {
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getArgs() {
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LogEntry setArgs(ArrayList<String> argsIn) {
|
||||||
|
args = argsIn;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getTimeStamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LogEntry addArg(String arg) {
|
||||||
|
if (args == null) {
|
||||||
|
args = new ArrayList<String>();
|
||||||
|
}
|
||||||
|
args.add(arg);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
String logString = String.format("%s >>%s", timestamp, method);
|
||||||
|
|
||||||
|
if (args != null) {
|
||||||
|
if (args.size() > 0) {
|
||||||
|
|
||||||
|
logString += ":";
|
||||||
|
|
||||||
|
for (String i : args) {
|
||||||
|
logString += " " + i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return logString;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,7 @@ package sarsoo.fmframework.util;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import sarsoo.fmframework.log.console.Console;
|
||||||
import sarsoo.fmframework.music.Album;
|
import sarsoo.fmframework.music.Album;
|
||||||
import sarsoo.fmframework.music.Artist;
|
import sarsoo.fmframework.music.Artist;
|
||||||
|
|
||||||
|
@ -12,4 +12,9 @@ public class FmUserNetworkTest {
|
|||||||
public void testNetworkInstantiate() {
|
public void testNetworkInstantiate() {
|
||||||
assertNotNull(new FmUserNetwork(Key.getKey(), "sarsoo"));
|
assertNotNull(new FmUserNetwork(Key.getKey(), "sarsoo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetLastTrack() {
|
||||||
|
assertNotNull(new FmUserNetwork(Key.getKey(), "sarsoo").getLastTrack());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user