Added tag list pulling

This commit is contained in:
aj 2018-04-05 22:05:55 -07:00
parent f6d8f5f401
commit 379e3a014c
7 changed files with 149 additions and 62 deletions

View File

@ -8,6 +8,7 @@ import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Getter;
import sarsoo.fmframework.util.Reference;
public class RefListsView extends JFrame {
@ -86,5 +87,23 @@ public class RefListsView extends JFrame {
}
});
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);
}
}

View File

@ -0,0 +1,5 @@
package sarsoo.fmframework.gui;
public class TagMenuView {
}

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import org.w3c.dom.Document;
import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.net.TestCall;
import sarsoo.fmframework.net.URLBuilder;
//import sarsoo.fmframework.net.TestCall;
import sarsoo.fmframework.parser.Parser;
@ -26,7 +27,7 @@ public class Artist extends FMObj {
public static Artist getArtist(String name, String username) {
String url = URLBuilder.getArtistInfoUrl(name, username);
// TestCall.test(url);
// TestCall.test(url);
Document response = Network.getResponse(url);
if (response != null) {
Artist artist = Parser.parseArtist(response);

View File

@ -111,13 +111,13 @@ public class URLBuilder {
return urlString;
}
public static String getUserPersonalTags(String username, String tag, FMObjType taggingType) {
public static String getUserPersonalTags(String username, String tag) {
String urlString;
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(tag, "UTF-8"),
URLEncoder.encode(taggingType.toString(), "UTF-8"),
// URLEncoder.encode(taggingType.toString().toLowerCase(), "UTF-8"),
URLEncoder.encode(Key.getKey(), "UTF-8"));
return urlString;
} catch (UnsupportedEncodingException e) {

View File

@ -20,6 +20,8 @@ import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.music.Wiki;
import sarsoo.fmframework.net.URLBuilder;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Reference;
public class Parser {
@ -54,30 +56,30 @@ public class Parser {
NodeList wikiContents = wikiNode.getChildNodes();
String date = null;
// String summary = null;
// String summary = null;
String content = null;
int counter;
Node node;
for (counter = 0; counter < wikiContents.getLength(); counter++) {
node = wikiContents.item(counter);
if (node.getNodeName().equals("published")) {
// System.out.println(node.getNodeName() + node.getTextContent());
// System.out.println(node.getNodeName() + node.getTextContent());
date = node.getTextContent();
}
// if (node.getNodeName().equals("summary")) {
// System.out.println(node.getNodeName() + node.getTextContent());
// summary = node.getTextContent();
// }
// if (node.getNodeName().equals("summary")) {
// System.out.println(node.getNodeName() + node.getTextContent());
// summary = node.getTextContent();
// }
if (node.getNodeName().equals("content")) {
// System.out.println(node.getNodeName() + node.getTextContent());
// System.out.println(node.getNodeName() + node.getTextContent());
content = node.getTextContent();
}
}
if (date != null && content != null)
// System.out.println("wiki init");
// System.out.println("wiki init");
wiki = new Wiki(date, null, content);
}
@ -123,23 +125,23 @@ public class Parser {
Node node;
for (counter = 0; counter < wikiContents.getLength(); counter++) {
node = wikiContents.item(counter);
if (node.getNodeName().equals("published")) {
// System.out.println(node.getNodeName() + node.getTextContent());
// System.out.println(node.getNodeName() + node.getTextContent());
date = node.getTextContent();
}
if (node.getNodeName().equals("summary")) {
// System.out.println(node.getNodeName() + node.getTextContent());
// System.out.println(node.getNodeName() + node.getTextContent());
summary = node.getTextContent();
}
if (node.getNodeName().equals("content")) {
// System.out.println(node.getNodeName() + node.getTextContent());
// System.out.println(node.getNodeName() + node.getTextContent());
content = node.getTextContent();
}
}
if (date != null && content != null)
// System.out.println("wiki init");
// System.out.println("wiki init");
wiki = new Wiki(date, summary, content);
// if (wikiNodeList.item(0) != null) {
// String date = wikiNodeList.item(0).getFirstChild().getTextContent();
@ -214,30 +216,30 @@ public class Parser {
NodeList wikiContents = wikiNode.getChildNodes();
String date = null;
// String summary = null;
// String summary = null;
String content = null;
int counter;
Node node;
for (counter = 0; counter < wikiContents.getLength(); counter++) {
node = wikiContents.item(counter);
if (node.getNodeName().equals("published")) {
// System.out.println(node.getNodeName() + node.getTextContent());
// System.out.println(node.getNodeName() + node.getTextContent());
date = node.getTextContent();
}
// if (node.getNodeName().equals("summary")) {
// System.out.println(node.getNodeName() + node.getTextContent());
// summary = node.getTextContent();
// }
// if (node.getNodeName().equals("summary")) {
// System.out.println(node.getNodeName() + node.getTextContent());
// summary = node.getTextContent();
// }
if (node.getNodeName().equals("content")) {
// System.out.println(node.getNodeName() + node.getTextContent());
// System.out.println(node.getNodeName() + node.getTextContent());
content = node.getTextContent();
}
}
if (date != null && content != null)
// System.out.println("wiki init");
// System.out.println("wiki init");
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 {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();

View File

@ -15,41 +15,61 @@ import sarsoo.fmframework.net.TestCall;
import sarsoo.fmframework.net.URLBuilder;
import sarsoo.fmframework.parser.AlbumParser;
import sarsoo.fmframework.parser.Parser;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Reference;
class NetworkTest {
@Test
void testCall() {
//TestCall.test("Pink Floyd", "The Wall", "sarsoo");
}
//
// @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
void test() {
String url = URLBuilder.getAlbumInfoUrl("The Wall", "Pink Floyd", "Sarsoo");
void testTag() {
Reference.setUserName("sarsoo");
String url = URLBuilder.getUserPersonalTags("sarsoo", "rock");
Document response = Network.getResponse(url);
Album album = Parser.parseAlbum(response);
//System.out.println(album);
FMObjList list = Parser.parseTagList(response);
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
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
void getArtistXml() {
//String url = Network.getAlbumInfoUrl("The Wall", "Pink Floyd", "Sarsoo");
//TestCall.test(url);
}
// @Test
// void getArtistXml() {
// //String url = Network.getAlbumInfoUrl("The Wall", "Pink Floyd", "Sarsoo");
// //TestCall.test(url);
// }
}

View File

@ -35,10 +35,10 @@ public class Getter {
public static Track getLastTrack() {
String url = URLBuilder.getLastTrackUrl(Reference.getUserName());
// TestCall.test(url);
// TestCall.test(url);
Document doc = Network.getResponse(url);
// System.out.println(doc.getDocumentElement().getAttribute("status"));
// System.out.println(doc.getDocumentElement().getAttribute("status"));
if (doc != null) {
// System.out.println(doc.getDocumentElement().getAttribute("status"));
Parser.stripSpace(doc.getDocumentElement());
@ -49,16 +49,25 @@ public class Getter {
return null;
}
public static int getScrobbles(String username) {
String url = URLBuilder.getUserInfoUrl(username);
Document doc = Network.getResponse(url);
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
String scrobbles = doc.getElementsByTagName("playcount").item(0).getTextContent();
if(scrobbles != null)
if (scrobbles != null)
return Integer.parseInt(scrobbles);
}
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;
}
}