wiki for tracks working

This commit is contained in:
aj 2018-03-29 14:29:04 -07:00
parent bf7f7dcf2d
commit 8d731f284d
3 changed files with 62 additions and 35 deletions

View File

@ -44,15 +44,16 @@ public class TrackView extends JFrame {
buttons2.setLayout(new FlowLayout()); buttons2.setLayout(new FlowLayout());
buttons.add(open); buttons.add(open);
if (track.getWiki() != null)
buttons.add(viewWiki);
if (track.getMbid() != null) if (track.getMbid() != null)
buttons.add(musicBrainz); buttons.add(musicBrainz);
buttons2.add(viewArtist); buttons2.add(viewArtist);
if (track.getAlbum() != null) if (track.getAlbum() != null)
buttons2.add(viewAlbum); buttons2.add(viewAlbum);
if (track.getArtist() != null) if (track.getWiki() != null)
buttons2.add(genius); buttons2.add(viewWiki);
// if (track.getArtist() != null)
buttons.add(genius);
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);

View File

@ -6,6 +6,7 @@ import org.w3c.dom.Document;
import sarsoo.fmframework.gui.TrackView; import sarsoo.fmframework.gui.TrackView;
import sarsoo.fmframework.net.Network; import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.net.TestCall;
import sarsoo.fmframework.parser.Parser; import sarsoo.fmframework.parser.Parser;
public class Track extends FMObj{ public class Track extends FMObj{
@ -29,6 +30,7 @@ public class Track extends FMObj{
public static Track getTrack(String name, String artist, String username) { public static Track getTrack(String name, String artist, String username) {
String url = Network.getTrackInfoUrl(name, artist, username); String url = Network.getTrackInfoUrl(name, artist, username);
TestCall.test(url);
Document response = Network.getResponse(url); Document response = Network.getResponse(url);
Track track = Parser.parseTrack(response); Track track = Parser.parseTrack(response);
return track; return track;

View File

@ -50,24 +50,36 @@ public class Parser {
Wiki wiki = null; Wiki wiki = null;
NodeList wikiNodeList = doc.getElementsByTagName("wiki"); NodeList wikiNodeList = doc.getElementsByTagName("wiki");
if (wikiNodeList.item(0) != null) { if (wikiNodeList.getLength() != 0) {
String date = wikiNodeList.item(0).getFirstChild().getTextContent(); Node wikiNode = wikiNodeList.item(0);
NodeList wikiContents = wikiNode.getChildNodes();
Node summaryNode = wikiNodeList.item(0).getFirstChild().getNextSibling(); String date = null;
while (!(summaryNode instanceof Element) && summaryNode != null) { // String summary = null;
summaryNode = summaryNode.getNextSibling(); 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());
date = 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());
content = node.getTextContent();
} }
String summary = summaryNode.getTextContent();
// System.out.println(summary);
Node contentNode = summaryNode.getNextSibling();
while (!(contentNode instanceof Element) && contentNode != null) {
contentNode = contentNode.getNextSibling();
} }
String content = contentNode.getTextContent();
// System.out.println(content);
wiki = new Wiki(date, summary, content); if (date != null && content != null)
// System.out.println("wiki init");
wiki = new Wiki(date, null, content);
} }
Album album = new Album(name, url, mbid, artistObj, listeners, playCount, userPlayCount, wiki); Album album = new Album(name, url, mbid, artistObj, listeners, playCount, userPlayCount, wiki);
@ -198,27 +210,39 @@ public class Parser {
Wiki wiki = null; Wiki wiki = null;
NodeList wikiNodeList = doc.getElementsByTagName("wiki"); NodeList wikiNodeList = doc.getElementsByTagName("wiki");
if (wikiNodeList.item(0) != null) { if (wikiNodeList.getLength() != 0) {
String date = wikiNodeList.item(0).getFirstChild().getTextContent(); Node wikiNode = wikiNodeList.item(0);
NodeList wikiContents = wikiNode.getChildNodes();
Node summaryNode = wikiNodeList.item(0).getFirstChild().getNextSibling(); String date = null;
while (!(summaryNode instanceof Element) && summaryNode != null) { // String summary = null;
summaryNode = summaryNode.getNextSibling(); 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());
date = node.getTextContent();
} }
String summary = summaryNode.getTextContent(); // if (node.getNodeName().equals("summary")) {
// System.out.println(summary); // System.out.println(node.getNodeName() + node.getTextContent());
// summary = node.getTextContent();
Node contentNode = summaryNode.getNextSibling(); // }
while (!(contentNode instanceof Element) && contentNode != null) { if (node.getNodeName().equals("content")) {
contentNode = contentNode.getNextSibling(); System.out.println(node.getNodeName() + node.getTextContent());
content = node.getTextContent();
} }
String content = contentNode.getTextContent();
// System.out.println(content);
wiki = new Wiki(date, summary, content);
} }
Track track = new Track(name, url, mbid, artistObj, listeners, playCount, userPlayCount, null); if (date != null && content != null)
// System.out.println("wiki init");
wiki = new Wiki(date, null, content);
}
Track track = new Track(name, url, mbid, artistObj, listeners, playCount, userPlayCount, wiki);
return track; return track;
} else { } else {
return null; return null;