Added tag list pulling
This commit is contained in:
parent
f6d8f5f401
commit
379e3a014c
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
|||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
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;
|
||||||
|
|
||||||
public class RefListsView extends JFrame {
|
public class RefListsView extends JFrame {
|
||||||
@ -86,5 +87,23 @@ public class RefListsView extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(viewEmoTrio);
|
add(viewEmoTrio);
|
||||||
|
|
||||||
|
JButton viewRockTag = new JButton("Rock Tag");
|
||||||
|
viewRockTag.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
|
FMObjList list = Getter.getTag(Reference.getUserName(), "rock");
|
||||||
|
list.view();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(viewRockTag);
|
||||||
|
|
||||||
|
JButton viewRapTag = new JButton("Rap Tag");
|
||||||
|
viewRapTag.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
|
FMObjList list = Getter.getTag(Reference.getUserName(), "rap");
|
||||||
|
list.view();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(viewRapTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
fmframework/src/sarsoo/fmframework/gui/TagMenuView.java
Normal file
5
fmframework/src/sarsoo/fmframework/gui/TagMenuView.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package sarsoo.fmframework.gui;
|
||||||
|
|
||||||
|
public class TagMenuView {
|
||||||
|
|
||||||
|
}
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import sarsoo.fmframework.net.Network;
|
import sarsoo.fmframework.net.Network;
|
||||||
|
import sarsoo.fmframework.net.TestCall;
|
||||||
import sarsoo.fmframework.net.URLBuilder;
|
import sarsoo.fmframework.net.URLBuilder;
|
||||||
//import sarsoo.fmframework.net.TestCall;
|
//import sarsoo.fmframework.net.TestCall;
|
||||||
import sarsoo.fmframework.parser.Parser;
|
import sarsoo.fmframework.parser.Parser;
|
||||||
@ -26,7 +27,7 @@ public class Artist extends FMObj {
|
|||||||
|
|
||||||
public static Artist getArtist(String name, String username) {
|
public static Artist getArtist(String name, String username) {
|
||||||
String url = URLBuilder.getArtistInfoUrl(name, username);
|
String url = URLBuilder.getArtistInfoUrl(name, username);
|
||||||
// TestCall.test(url);
|
// TestCall.test(url);
|
||||||
Document response = Network.getResponse(url);
|
Document response = Network.getResponse(url);
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
Artist artist = Parser.parseArtist(response);
|
Artist artist = Parser.parseArtist(response);
|
||||||
|
@ -111,13 +111,13 @@ public class URLBuilder {
|
|||||||
return urlString;
|
return urlString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUserPersonalTags(String username, String tag, FMObjType taggingType) {
|
public static String getUserPersonalTags(String username, String tag) {
|
||||||
String urlString;
|
String urlString;
|
||||||
try {
|
try {
|
||||||
urlString = String.format("http://ws.audioscrobbler.com/2.0/?method=user.getpersonaltags&user=%s&tag=%s&taggingtype=%s&api_key=%s",
|
urlString = String.format("http://ws.audioscrobbler.com/2.0/?method=user.getpersonaltags&user=%s&tag=%s&taggingtype=artist&api_key=%s",
|
||||||
URLEncoder.encode(username, "UTF-8"),
|
URLEncoder.encode(username, "UTF-8"),
|
||||||
URLEncoder.encode(tag, "UTF-8"),
|
URLEncoder.encode(tag, "UTF-8"),
|
||||||
URLEncoder.encode(taggingType.toString(), "UTF-8"),
|
// URLEncoder.encode(taggingType.toString().toLowerCase(), "UTF-8"),
|
||||||
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||||
return urlString;
|
return urlString;
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
@ -20,6 +20,8 @@ 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.music.Wiki;
|
import sarsoo.fmframework.music.Wiki;
|
||||||
|
import sarsoo.fmframework.net.URLBuilder;
|
||||||
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
import sarsoo.fmframework.util.Reference;
|
import sarsoo.fmframework.util.Reference;
|
||||||
|
|
||||||
public class Parser {
|
public class Parser {
|
||||||
@ -54,7 +56,7 @@ public class Parser {
|
|||||||
NodeList wikiContents = wikiNode.getChildNodes();
|
NodeList wikiContents = wikiNode.getChildNodes();
|
||||||
|
|
||||||
String date = null;
|
String date = null;
|
||||||
// String summary = null;
|
// String summary = null;
|
||||||
String content = null;
|
String content = null;
|
||||||
|
|
||||||
int counter;
|
int counter;
|
||||||
@ -63,21 +65,21 @@ public class Parser {
|
|||||||
node = wikiContents.item(counter);
|
node = wikiContents.item(counter);
|
||||||
|
|
||||||
if (node.getNodeName().equals("published")) {
|
if (node.getNodeName().equals("published")) {
|
||||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||||
date = node.getTextContent();
|
date = node.getTextContent();
|
||||||
}
|
}
|
||||||
// if (node.getNodeName().equals("summary")) {
|
// if (node.getNodeName().equals("summary")) {
|
||||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||||
// summary = node.getTextContent();
|
// summary = node.getTextContent();
|
||||||
// }
|
// }
|
||||||
if (node.getNodeName().equals("content")) {
|
if (node.getNodeName().equals("content")) {
|
||||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||||
content = node.getTextContent();
|
content = node.getTextContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (date != null && content != null)
|
if (date != null && content != null)
|
||||||
// System.out.println("wiki init");
|
// System.out.println("wiki init");
|
||||||
wiki = new Wiki(date, null, content);
|
wiki = new Wiki(date, null, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,21 +127,21 @@ public class Parser {
|
|||||||
node = wikiContents.item(counter);
|
node = wikiContents.item(counter);
|
||||||
|
|
||||||
if (node.getNodeName().equals("published")) {
|
if (node.getNodeName().equals("published")) {
|
||||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||||
date = node.getTextContent();
|
date = node.getTextContent();
|
||||||
}
|
}
|
||||||
if (node.getNodeName().equals("summary")) {
|
if (node.getNodeName().equals("summary")) {
|
||||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||||
summary = node.getTextContent();
|
summary = node.getTextContent();
|
||||||
}
|
}
|
||||||
if (node.getNodeName().equals("content")) {
|
if (node.getNodeName().equals("content")) {
|
||||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||||
content = node.getTextContent();
|
content = node.getTextContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (date != null && content != null)
|
if (date != null && content != null)
|
||||||
// System.out.println("wiki init");
|
// System.out.println("wiki init");
|
||||||
wiki = new Wiki(date, summary, content);
|
wiki = new Wiki(date, summary, content);
|
||||||
// if (wikiNodeList.item(0) != null) {
|
// if (wikiNodeList.item(0) != null) {
|
||||||
// String date = wikiNodeList.item(0).getFirstChild().getTextContent();
|
// String date = wikiNodeList.item(0).getFirstChild().getTextContent();
|
||||||
@ -214,7 +216,7 @@ public class Parser {
|
|||||||
NodeList wikiContents = wikiNode.getChildNodes();
|
NodeList wikiContents = wikiNode.getChildNodes();
|
||||||
|
|
||||||
String date = null;
|
String date = null;
|
||||||
// String summary = null;
|
// String summary = null;
|
||||||
String content = null;
|
String content = null;
|
||||||
|
|
||||||
int counter;
|
int counter;
|
||||||
@ -223,21 +225,21 @@ public class Parser {
|
|||||||
node = wikiContents.item(counter);
|
node = wikiContents.item(counter);
|
||||||
|
|
||||||
if (node.getNodeName().equals("published")) {
|
if (node.getNodeName().equals("published")) {
|
||||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||||
date = node.getTextContent();
|
date = node.getTextContent();
|
||||||
}
|
}
|
||||||
// if (node.getNodeName().equals("summary")) {
|
// if (node.getNodeName().equals("summary")) {
|
||||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||||
// summary = node.getTextContent();
|
// summary = node.getTextContent();
|
||||||
// }
|
// }
|
||||||
if (node.getNodeName().equals("content")) {
|
if (node.getNodeName().equals("content")) {
|
||||||
// System.out.println(node.getNodeName() + node.getTextContent());
|
// System.out.println(node.getNodeName() + node.getTextContent());
|
||||||
content = node.getTextContent();
|
content = node.getTextContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (date != null && content != null)
|
if (date != null && content != null)
|
||||||
// System.out.println("wiki init");
|
// System.out.println("wiki init");
|
||||||
wiki = new Wiki(date, null, content);
|
wiki = new Wiki(date, null, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,6 +273,37 @@ public class Parser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FMObjList parseTagList(Document doc) {
|
||||||
|
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||||
|
NodeList objList = doc.getElementsByTagName("artist");
|
||||||
|
|
||||||
|
// Node obj = objList.item(0);
|
||||||
|
FMObjList list = new FMObjList();
|
||||||
|
// String name = obj.getFirstChild().getTextContent();
|
||||||
|
// System.out.println(name);
|
||||||
|
//
|
||||||
|
// Artist artist = Artist.getArtist(name, Reference.getUserName());
|
||||||
|
//
|
||||||
|
// System.out.println(artist);
|
||||||
|
|
||||||
|
int counter;
|
||||||
|
for (counter = 0; counter < objList.getLength(); counter++) {
|
||||||
|
Node obj = objList.item(counter);
|
||||||
|
|
||||||
|
String name = obj.getFirstChild().getTextContent();
|
||||||
|
// System.out.println(name + ".");
|
||||||
|
// System.out.println(obj.getTextContent());
|
||||||
|
Artist artist = Artist.getArtist(name, Reference.getUserName());
|
||||||
|
|
||||||
|
System.out.println(artist);
|
||||||
|
list.add(artist);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException {
|
public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException {
|
||||||
TransformerFactory tf = TransformerFactory.newInstance();
|
TransformerFactory tf = TransformerFactory.newInstance();
|
||||||
Transformer transformer = tf.newTransformer();
|
Transformer transformer = tf.newTransformer();
|
||||||
|
@ -15,41 +15,61 @@ import sarsoo.fmframework.net.TestCall;
|
|||||||
import sarsoo.fmframework.net.URLBuilder;
|
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.Reference;
|
||||||
|
|
||||||
class NetworkTest {
|
class NetworkTest {
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// void testCall() {
|
||||||
|
// //TestCall.test("Pink Floyd", "The Wall", "sarsoo");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// void test() {
|
||||||
|
// String url = URLBuilder.getAlbumInfoUrl("The Wall", "Pink Floyd", "Sarsoo");
|
||||||
|
// Document response = Network.getResponse(url);
|
||||||
|
// Album album = Parser.parseAlbum(response);
|
||||||
|
// //System.out.println(album);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// void testArtist() {
|
||||||
|
// String url = URLBuilder.getArtistInfoUrl("Pink Floyd", "sarsoo");
|
||||||
|
// Document response = Network.getResponse(url);
|
||||||
|
// Artist artist = Parser.parseArtist(response);
|
||||||
|
// //System.out.println(album);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// void testTrack() {
|
||||||
|
// String url = URLBuilder.getTrackInfoUrl("Business", "Eminem", "sarsoo");
|
||||||
|
// Document response = Network.getResponse(url);
|
||||||
|
// Track track = Parser.parseTrack(response);
|
||||||
|
// //System.out.println(album);
|
||||||
|
// }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCall() {
|
void testTag() {
|
||||||
//TestCall.test("Pink Floyd", "The Wall", "sarsoo");
|
Reference.setUserName("sarsoo");
|
||||||
}
|
String url = URLBuilder.getUserPersonalTags("sarsoo", "rock");
|
||||||
|
|
||||||
@Test
|
|
||||||
void test() {
|
|
||||||
String url = URLBuilder.getAlbumInfoUrl("The Wall", "Pink Floyd", "Sarsoo");
|
|
||||||
Document response = Network.getResponse(url);
|
Document response = Network.getResponse(url);
|
||||||
Album album = Parser.parseAlbum(response);
|
FMObjList list = Parser.parseTagList(response);
|
||||||
//System.out.println(album);
|
|
||||||
|
list.view();
|
||||||
|
// FMObjList list = Parser.parseTagList(response);
|
||||||
|
|
||||||
|
// int counter;
|
||||||
|
// for(counter = 0; counter < list.size(); counter++) {
|
||||||
|
// System.out.println(list.get(counter));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// System.out.println(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
void testArtist() {
|
// void getArtistXml() {
|
||||||
String url = URLBuilder.getArtistInfoUrl("Pink Floyd", "sarsoo");
|
// //String url = Network.getAlbumInfoUrl("The Wall", "Pink Floyd", "Sarsoo");
|
||||||
Document response = Network.getResponse(url);
|
// //TestCall.test(url);
|
||||||
Artist artist = Parser.parseArtist(response);
|
// }
|
||||||
//System.out.println(album);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testTrack() {
|
|
||||||
String url = URLBuilder.getTrackInfoUrl("Business", "Eminem", "sarsoo");
|
|
||||||
Document response = Network.getResponse(url);
|
|
||||||
Track track = Parser.parseTrack(response);
|
|
||||||
//System.out.println(album);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getArtistXml() {
|
|
||||||
//String url = Network.getAlbumInfoUrl("The Wall", "Pink Floyd", "Sarsoo");
|
|
||||||
//TestCall.test(url);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,10 @@ public class Getter {
|
|||||||
public static Track getLastTrack() {
|
public static Track getLastTrack() {
|
||||||
|
|
||||||
String url = URLBuilder.getLastTrackUrl(Reference.getUserName());
|
String url = URLBuilder.getLastTrackUrl(Reference.getUserName());
|
||||||
// TestCall.test(url);
|
// TestCall.test(url);
|
||||||
Document doc = Network.getResponse(url);
|
Document doc = Network.getResponse(url);
|
||||||
|
|
||||||
// System.out.println(doc.getDocumentElement().getAttribute("status"));
|
// System.out.println(doc.getDocumentElement().getAttribute("status"));
|
||||||
if (doc != null) {
|
if (doc != null) {
|
||||||
// System.out.println(doc.getDocumentElement().getAttribute("status"));
|
// System.out.println(doc.getDocumentElement().getAttribute("status"));
|
||||||
Parser.stripSpace(doc.getDocumentElement());
|
Parser.stripSpace(doc.getDocumentElement());
|
||||||
@ -55,10 +55,19 @@ public class Getter {
|
|||||||
Document doc = Network.getResponse(url);
|
Document doc = Network.getResponse(url);
|
||||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||||
String scrobbles = doc.getElementsByTagName("playcount").item(0).getTextContent();
|
String scrobbles = doc.getElementsByTagName("playcount").item(0).getTextContent();
|
||||||
if(scrobbles != null)
|
if (scrobbles != null)
|
||||||
return Integer.parseInt(scrobbles);
|
return Integer.parseInt(scrobbles);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FMObjList getTag(String username, String tag) {
|
||||||
|
String url = URLBuilder.getUserPersonalTags(username, tag);
|
||||||
|
Document doc = Network.getResponse(url);
|
||||||
|
if (doc != null) {
|
||||||
|
return Parser.parseTagList(doc);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user