added todays scrobbles as button on main
This commit is contained in:
parent
1f5fd21304
commit
57d2ec312c
@ -11,6 +11,7 @@ import javax.swing.JOptionPane;
|
|||||||
import sarsoo.fmframework.music.Album;
|
import sarsoo.fmframework.music.Album;
|
||||||
import sarsoo.fmframework.music.Artist;
|
import sarsoo.fmframework.music.Artist;
|
||||||
import sarsoo.fmframework.music.Track;
|
import sarsoo.fmframework.music.Track;
|
||||||
|
import sarsoo.fmframework.net.Network;
|
||||||
import sarsoo.fmframework.util.Getter;
|
import sarsoo.fmframework.util.Getter;
|
||||||
import sarsoo.fmframework.util.Reference;
|
import sarsoo.fmframework.util.Reference;
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ public class MainMenu extends JFrame {
|
|||||||
JButton viewLastTrack = new JButton("View Last Track");
|
JButton viewLastTrack = new JButton("View Last Track");
|
||||||
JButton viewList = new JButton("View List");
|
JButton viewList = new JButton("View List");
|
||||||
JButton viewTag = new JButton("View Tags");
|
JButton viewTag = new JButton("View Tags");
|
||||||
|
JButton today = new JButton();
|
||||||
|
|
||||||
public MainMenu() {
|
public MainMenu() {
|
||||||
super("fmframework - " + Reference.getUserName());
|
super("fmframework - " + Reference.getUserName());
|
||||||
@ -71,11 +73,18 @@ public class MainMenu extends JFrame {
|
|||||||
view.setVisible(true);
|
view.setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
today.setText("Today: " + Integer.toString(Getter.getScrobblesToday(Reference.getUserName())));
|
||||||
|
today.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
|
Network.openURL(String.format("https://www.last.fm/user/%s/library?date_preset=LAST_30_DAYS", Reference.getUserName()));
|
||||||
|
}
|
||||||
|
});
|
||||||
add(viewLastTrack);
|
add(viewLastTrack);
|
||||||
add(viewList);
|
add(viewList);
|
||||||
add(viewTag);
|
add(viewTag);
|
||||||
add(getAlbum);
|
add(getAlbum);
|
||||||
add(getArtist);
|
add(getArtist);
|
||||||
|
add(today);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,12 @@ public class TagMenuView extends JFrame {
|
|||||||
public TagMenuView() {
|
public TagMenuView() {
|
||||||
super("View Tags");
|
super("View Tags");
|
||||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
setLayout(new GridLayout(3, 2));
|
|
||||||
|
ArrayList<Tag> tags = Getter.getUserTags(Reference.getUserName());
|
||||||
|
|
||||||
|
setLayout(new GridLayout(4, 4));
|
||||||
setSize(300, 300);
|
setSize(300, 300);
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
|
|
||||||
ArrayList<Tag> tags = Getter.getUserTags(Reference.getUserName());
|
|
||||||
|
|
||||||
int counter;
|
int counter;
|
||||||
for(counter = 0; counter < tags.size(); counter++) {
|
for(counter = 0; counter < tags.size(); counter++) {
|
||||||
|
@ -2,6 +2,8 @@ package sarsoo.fmframework.net;
|
|||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
public class URLBuilder {
|
public class URLBuilder {
|
||||||
|
|
||||||
@ -143,7 +145,42 @@ public class URLBuilder {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getTodayScrobbles(String username) {
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
|
String month;
|
||||||
|
if(now.getMonthValue() < 10) {
|
||||||
|
month = "0" + now.getMonthValue();
|
||||||
|
}else {
|
||||||
|
month = Integer.toString(now.getMonthValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
String day;
|
||||||
|
if(now.getMonthValue() < 10) {
|
||||||
|
day = "0" + now.getDayOfMonth();
|
||||||
|
}else {
|
||||||
|
day = Integer.toString(now.getDayOfMonth());
|
||||||
|
}
|
||||||
|
|
||||||
|
String date = String.format("%d-%s-%sT07:00:00.00Z", now.getYear(), month, day);
|
||||||
|
System.out.println(date);
|
||||||
|
// long midnight = Instant.parse("2018-04-05T07:00:00.00Z").getEpochSecond();
|
||||||
|
long midnight = Instant.parse(date).getEpochSecond();
|
||||||
|
|
||||||
|
String urlString;
|
||||||
|
try {
|
||||||
|
urlString = String.format("http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=%s&limit=200&from=%s&api_key=%s",
|
||||||
|
URLEncoder.encode(username, "UTF-8"),
|
||||||
|
URLEncoder.encode(Long.toString(midnight), "UTF-8"),
|
||||||
|
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||||
|
return urlString;
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// System.out.println(urlString);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// public static String getUserTopTags() {
|
// public static String getUserTopTags() {
|
||||||
//
|
//
|
||||||
|
@ -91,6 +91,7 @@ public class Parser {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Artist parseArtist(Document doc) {
|
public static Artist parseArtist(Document doc) {
|
||||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||||
|
@ -3,6 +3,7 @@ package sarsoo.fmframework.test;
|
|||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -18,6 +19,7 @@ import sarsoo.fmframework.net.URLBuilder;
|
|||||||
import sarsoo.fmframework.parser.AlbumParser;
|
import sarsoo.fmframework.parser.AlbumParser;
|
||||||
import sarsoo.fmframework.parser.Parser;
|
import sarsoo.fmframework.parser.Parser;
|
||||||
import sarsoo.fmframework.util.FMObjList;
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
|
import sarsoo.fmframework.util.Getter;
|
||||||
import sarsoo.fmframework.util.Reference;
|
import sarsoo.fmframework.util.Reference;
|
||||||
|
|
||||||
class NetworkTest {
|
class NetworkTest {
|
||||||
@ -53,18 +55,9 @@ class NetworkTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testTag() {
|
void testTag() {
|
||||||
Reference.setUserName("sarsoo");
|
|
||||||
String url = URLBuilder.getUserTopTags("sarsoo");
|
|
||||||
Document response = Network.getResponse(url);
|
|
||||||
ArrayList<Tag> list = Parser.parseUserTags(response);
|
|
||||||
|
|
||||||
|
|
||||||
// FMObjList list = Parser.parseTagList(response);
|
// System.out.println(Instant.parse("2018-04-05T07:00:00.00Z").getEpochSecond());
|
||||||
|
System.out.println(Getter.getScrobblesToday("sarsoo"));
|
||||||
int counter;
|
|
||||||
for(counter = 0; counter < list.size(); counter++) {
|
|
||||||
System.out.println(list.get(counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
// System.out.println(url);
|
// System.out.println(url);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import java.util.ArrayList;
|
|||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.NamedNodeMap;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
import sarsoo.fmframework.music.Album;
|
import sarsoo.fmframework.music.Album;
|
||||||
import sarsoo.fmframework.music.Artist;
|
import sarsoo.fmframework.music.Artist;
|
||||||
@ -64,6 +66,19 @@ public class Getter {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getScrobblesToday(String username) {
|
||||||
|
String url = URLBuilder.getTodayScrobbles(username);
|
||||||
|
Document doc = Network.getResponse(url);
|
||||||
|
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||||
|
Node node = doc.getChildNodes().item(0).getFirstChild();
|
||||||
|
NamedNodeMap var = node.getAttributes();
|
||||||
|
// System.out.println(var.getNamedItem("total").getNodeValue());
|
||||||
|
// if (scrobbles != null)
|
||||||
|
return Integer.parseInt(var.getNamedItem("total").getNodeValue());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static FMObjList getUserTag(String username, String tag) {
|
public static FMObjList getUserTag(String username, String tag) {
|
||||||
String url = URLBuilder.getUserPersonalTags(username, tag);
|
String url = URLBuilder.getUserPersonalTags(username, tag);
|
||||||
Document doc = Network.getResponse(url);
|
Document doc = Network.getResponse(url);
|
||||||
@ -72,7 +87,7 @@ public class Getter {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Tag> getUserTags(String username) {
|
public static ArrayList<Tag> getUserTags(String username) {
|
||||||
String url = URLBuilder.getUserTopTags(username);
|
String url = URLBuilder.getUserTopTags(username);
|
||||||
Document doc = Network.getResponse(url);
|
Document doc = Network.getResponse(url);
|
||||||
|
Loading…
Reference in New Issue
Block a user