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.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);
} }
} }

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 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;

View File

@ -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) {

View File

@ -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 {
@ -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();

View File

@ -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);
}
} }

View File

@ -61,4 +61,13 @@ public class Getter {
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;
}
} }