cleared unused imports, added rym handling
moved link handling from object classes to network class, objects now return assembled url strings fmobj now abstract to add musicbeanz url returning added artist to track from parser
This commit is contained in:
parent
6ceb77393c
commit
99325cd5f9
@ -1,7 +1,5 @@
|
||||
package sarsoo.fmframework.drive;
|
||||
|
||||
import sarsoo.fmframework.gui.AlbumView;
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.util.GetObject;
|
||||
|
||||
public class Driver {
|
||||
@ -10,6 +8,8 @@ public class Driver {
|
||||
|
||||
GetObject.getAlbum().view();
|
||||
|
||||
//Network.getRecentTracaksUrl("sarsoo");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,50 +1,58 @@
|
||||
package sarsoo.fmframework.gui;
|
||||
|
||||
import java.awt.Desktop;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.net.URI;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.FMObj;
|
||||
import sarsoo.fmframework.net.Network;
|
||||
|
||||
public class AlbumView extends JFrame{
|
||||
JPanel info = new JPanel();
|
||||
JPanel buttons = new JPanel();
|
||||
JPanel buttons2 = new JPanel();
|
||||
JLabel name = new JLabel();
|
||||
JLabel artist = new JLabel();
|
||||
JLabel listeners = new JLabel();
|
||||
JLabel playCount = new JLabel();
|
||||
JLabel userPlayCount = new JLabel();
|
||||
JButton open = new JButton("View Online");
|
||||
JButton viewArtist = new JButton("View Artist");
|
||||
JButton musicBeanz = new JButton("Open MusicBeanz");
|
||||
JButton rym = new JButton("Open RYM");
|
||||
|
||||
public AlbumView(Album album) {
|
||||
super(album.toString());
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setLayout(new GridLayout(5,0));
|
||||
setSize(300, 200);
|
||||
super(album.getName());
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setLayout(new GridLayout(7,0));
|
||||
setSize(300, 300);
|
||||
setResizable(false);
|
||||
info.setLayout(new GridLayout());
|
||||
buttons.setLayout(new FlowLayout());
|
||||
buttons2.setLayout(new FlowLayout());
|
||||
// info.add(name);
|
||||
// info.add(listeners);
|
||||
// info.add(playCount);
|
||||
// info.add(userPlayCount);
|
||||
buttons.add(open);
|
||||
buttons.add(viewArtist);
|
||||
buttons2.add(musicBeanz);
|
||||
buttons2.add(rym);
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
|
||||
name.setText(album.getName());
|
||||
name.setHorizontalTextPosition(JLabel.CENTER);
|
||||
artist.setText(album.getArtist().getName());
|
||||
listeners.setText(numberFormat.format(album.getListeners()) + " Listeners");
|
||||
playCount.setText(numberFormat.format(album.getPlayCount()) + " Scrobbles");
|
||||
userPlayCount.setText(numberFormat.format(album.getUserPlayCount()) + " Your Scrobbles");
|
||||
@ -52,20 +60,31 @@ public class AlbumView extends JFrame{
|
||||
|
||||
open.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
try {
|
||||
Desktop desktop = java.awt.Desktop.getDesktop();
|
||||
URI oURL = new URI(album.getUrl());
|
||||
desktop.browse(oURL);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Network.openURL(album.getUrl());
|
||||
}
|
||||
});
|
||||
viewArtist.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
album.getArtist().view();
|
||||
}
|
||||
});
|
||||
musicBeanz.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(album.getMusicBeanzURL());;
|
||||
}
|
||||
});
|
||||
rym.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(album.getRymURL());;
|
||||
}
|
||||
});
|
||||
add(name);
|
||||
add(artist);
|
||||
add(listeners);
|
||||
add(playCount);
|
||||
add(userPlayCount);
|
||||
// add(info);
|
||||
add(buttons);
|
||||
add(buttons2);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,9 @@
|
||||
package sarsoo.fmframework.gui;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.net.URI;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
@ -15,6 +13,7 @@ import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import sarsoo.fmframework.music.FMObj;
|
||||
import sarsoo.fmframework.net.Network;
|
||||
|
||||
public class FMObjView extends JFrame{
|
||||
JPanel info = new JPanel();
|
||||
@ -24,12 +23,13 @@ public class FMObjView extends JFrame{
|
||||
JLabel playCount = new JLabel();
|
||||
JLabel userPlayCount = new JLabel();
|
||||
JButton open = new JButton("View Online");
|
||||
JButton musicBeanz = new JButton("Open MusicBeanz");
|
||||
|
||||
public FMObjView(FMObj obj) {
|
||||
super(obj.toString());
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setLayout(new GridLayout(5,0));
|
||||
setSize(300, 200);
|
||||
setSize(300, 300);
|
||||
setResizable(false);
|
||||
info.setLayout(new GridLayout());
|
||||
buttons.setLayout(new FlowLayout());
|
||||
@ -38,6 +38,7 @@ public class FMObjView extends JFrame{
|
||||
// info.add(playCount);
|
||||
// info.add(userPlayCount);
|
||||
buttons.add(open);
|
||||
buttons.add(musicBeanz);
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
|
||||
@ -50,13 +51,12 @@ public class FMObjView extends JFrame{
|
||||
|
||||
open.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
try {
|
||||
Desktop desktop = java.awt.Desktop.getDesktop();
|
||||
URI oURL = new URI(obj.getUrl());
|
||||
desktop.browse(oURL);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Network.openURL(obj.getUrl());
|
||||
}
|
||||
});
|
||||
musicBeanz.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
Network.openURL(obj.getMusicBeanzURL());;
|
||||
}
|
||||
});
|
||||
add(name);
|
||||
|
@ -63,9 +63,19 @@ public class Album extends FMObj{
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getRymURL() {
|
||||
return "https://rateyourmusic.com/release/album/" + getArtist().getName().replaceAll(" ", "_").toLowerCase() + "/" + getName().replaceAll(" ", "_").toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void view() {
|
||||
AlbumView view = new AlbumView(this);
|
||||
view.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMusicBeanzURL() {
|
||||
return "https://musicbrainz.org/release/" + mbid;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -55,4 +55,16 @@ public class Artist extends FMObj{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMusicBeanzURL() {
|
||||
return "https://musicbrainz.org/artist/" + mbid;
|
||||
|
||||
}
|
||||
|
||||
public String getRymURL() {
|
||||
return "https://rateyourmusic.com/artist/" + getName().replaceAll(" ", "_").toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package sarsoo.fmframework.music;
|
||||
|
||||
import sarsoo.fmframework.gui.FMObjView;
|
||||
|
||||
public class FMObj {
|
||||
public abstract class FMObj {
|
||||
|
||||
protected String name;
|
||||
protected String url;
|
||||
@ -60,5 +60,7 @@ public class FMObj {
|
||||
public Wiki getWiki() {
|
||||
return wiki;
|
||||
}
|
||||
|
||||
abstract public String getMusicBeanzURL();
|
||||
|
||||
}
|
||||
|
@ -21,8 +21,9 @@ public class Track extends FMObj{
|
||||
this.artist = new Artist(artist);
|
||||
}
|
||||
|
||||
public Track(String name, String url, String mbid, int listeners, int playCount, int userPlayCount, Wiki wiki) {
|
||||
public Track(String name, String url, String mbid, Artist artist, int listeners, int playCount, int userPlayCount, Wiki wiki) {
|
||||
super(name, url, mbid, listeners, playCount, userPlayCount, wiki);
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
public static Track getTrack(String name, String artist, String username) {
|
||||
@ -50,5 +51,10 @@ public class Track extends FMObj{
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMusicBeanzURL() {
|
||||
return "https://musicbrainz.org/artist/" + mbid;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package sarsoo.fmframework.net;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
@ -64,25 +66,54 @@ public class Network {
|
||||
}
|
||||
|
||||
public static String getArtistInfoUrl(String artist, String username) {
|
||||
String urlString = String.format(
|
||||
"http://ws.audioscrobbler.com/2.0/?method=artist.getInfo&artist=%s&autocorrect=1&username=%s&api_key=%s",
|
||||
artist, username, Key.getKey());
|
||||
return urlString;
|
||||
|
||||
|
||||
String urlString = String.format(
|
||||
"http://ws.audioscrobbler.com/2.0/?method=artist.getInfo&artist=%s&autocorrect=1&username=%s&api_key=%s",
|
||||
artist, username, Key.getKey());
|
||||
return urlString;
|
||||
|
||||
}
|
||||
|
||||
public static String getAlbumInfoUrl(String album, String artist, String username) {
|
||||
String urlString = String.format(
|
||||
"http://ws.audioscrobbler.com/2.0/?method=album.getInfo&album=%s&artist=%s&autocorrect=1&username=%s&api_key=%s",
|
||||
album, artist, username, Key.getKey());
|
||||
return urlString;
|
||||
public static String getAlbumInfoUrl(String album, String artist, String username) {
|
||||
String urlString = String.format(
|
||||
"http://ws.audioscrobbler.com/2.0/?method=album.getInfo&album=%s&artist=%s&autocorrect=1&username=%s&api_key=%s",
|
||||
album, artist, username, Key.getKey());
|
||||
return urlString;
|
||||
}
|
||||
|
||||
public static String getTrackInfoUrl(String name, String artist, String username) {
|
||||
|
||||
public static String getTrackInfoUrl(String name, String artist, String username) {
|
||||
String urlString = String.format(
|
||||
"http://ws.audioscrobbler.com/2.0/?method=track.getInfo&track=%s&artist=%s&autocorrect=1&username=%s&api_key=%s",
|
||||
name, artist, username, Key.getKey());
|
||||
name, artist, username, Key.getKey());
|
||||
return urlString;
|
||||
}
|
||||
}
|
||||
|
||||
public static void openURL(String url) {
|
||||
try {
|
||||
Desktop desktop = java.awt.Desktop.getDesktop();
|
||||
URI oURL = new URI(url);
|
||||
desktop.browse(oURL);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// public static String getRecentTracaksUrl(String username) {
|
||||
//// Date date = new Date();
|
||||
//// Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
//// Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
////
|
||||
//// cal.set(cal.YEAR, cal.MONTH, cal.DATE);
|
||||
//// System.out.println(cal.getTime());
|
||||
// //System.out.println(cal2.getTime());
|
||||
//
|
||||
// String urlString = String.format(
|
||||
// "http://ws.audioscrobbler.com/2.0/"
|
||||
// + "?method=user.getRecentTracks&"
|
||||
// + "user=%s&"
|
||||
// + "limit = 200&"
|
||||
// + "from=%d&"
|
||||
// + "api_key=%s",
|
||||
// username, Key.getKey());
|
||||
// return urlString;
|
||||
// }
|
||||
}
|
||||
|
@ -1,18 +1,9 @@
|
||||
package sarsoo.fmframework.parser;
|
||||
|
||||
import javax.xml.parsers.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
||||
public class AlbumParser {
|
||||
|
@ -1,8 +1,6 @@
|
||||
package sarsoo.fmframework.parser;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
@ -40,10 +38,10 @@ public class Parser {
|
||||
// }
|
||||
// }
|
||||
|
||||
Node wikiNode = doc.getElementsByTagName("wiki").item(0);
|
||||
String published = wikiNode.getFirstChild().getTextContent();
|
||||
String summary = wikiNode.getFirstChild().getNextSibling().getTextContent();
|
||||
String content = wikiNode.getFirstChild().getNextSibling().getNextSibling().getTextContent();
|
||||
// Node wikiNode = doc.getElementsByTagName("wiki").item(0);
|
||||
// String published = wikiNode.getFirstChild().getTextContent();
|
||||
// String summary = wikiNode.getFirstChild().getNextSibling().getTextContent();
|
||||
// String content = wikiNode.getFirstChild().getNextSibling().getNextSibling().getTextContent();
|
||||
|
||||
// System.out.println(published);
|
||||
// System.out.println(summary);
|
||||
@ -62,7 +60,7 @@ public class Parser {
|
||||
String name = doc.getElementsByTagName("name").item(0).getTextContent();
|
||||
String mbid = doc.getElementsByTagName("mbid").item(0).getTextContent();
|
||||
String url = doc.getElementsByTagName("url").item(0).getTextContent();
|
||||
String streamable = doc.getElementsByTagName("streamable").item(0).getTextContent();
|
||||
// String streamable = doc.getElementsByTagName("streamable").item(0).getTextContent();
|
||||
int listeners = Integer.parseInt(doc.getElementsByTagName("listeners").item(0).getTextContent());
|
||||
int playCount = Integer.parseInt(doc.getElementsByTagName("playcount").item(0).getTextContent());
|
||||
int userPlayCount = Integer.parseInt(doc.getElementsByTagName("userplaycount").item(0).getTextContent());
|
||||
@ -87,7 +85,7 @@ public class Parser {
|
||||
|
||||
// System.out.println(userPlayCount);
|
||||
|
||||
Track track = new Track(name, url, mbid, listeners, playCount, userPlayCount, null);
|
||||
Track track = new Track(name, url, mbid, artistObj, listeners, playCount, userPlayCount, null);
|
||||
return track;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user